Made Sound.cpp more accurate

This commit is contained in:
Clownacy 2019-08-13 20:45:50 +01:00
parent 8f5370ea81
commit add4e69374
3 changed files with 29 additions and 13 deletions

View file

@ -1066,6 +1066,21 @@ addr = 0x41FE70
name = "PlaySoundObject" name = "PlaySoundObject"
addr = 0x420640 addr = 0x420640
[[func]]
name = "ChangeSoundFrequency"
addr = 0x420720
size = 0x34
[[func]]
name = "ChangeSoundVolume"
addr = 0x420760
size = 0x35
[[func]]
name = "ChangeSoundPan"
addr = 0x4207A0
size = 0x36
[[func]] [[func]]
name = "TransferStage" name = "TransferStage"
addr = 0x420BE0 addr = 0x420BE0

View file

@ -221,7 +221,7 @@ void AudioCallback(void *userdata, Uint8 *stream, int len)
} }
//Sound things //Sound things
SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO]; SOUNDBUFFER* lpSECONDARYBUFFER[SE_MAX];
BOOL InitDirectSound() BOOL InitDirectSound()
{ {
@ -250,6 +250,9 @@ BOOL InitDirectSound()
//Unpause audio device //Unpause audio device
SDL_PauseAudioDevice(audioDevice, 0); SDL_PauseAudioDevice(audioDevice, 0);
for (unsigned int i = 0; i < SE_MAX; ++i)
lpSECONDARYBUFFER[i] = NULL;
//Start organya //Start organya
StartOrganya(); StartOrganya();
return TRUE; return TRUE;
@ -257,14 +260,15 @@ BOOL InitDirectSound()
void EndDirectSound() void EndDirectSound()
{ {
//Quit sub-system EndOrganya();
for (unsigned int i = 0; i < SE_MAX; ++i)
lpSECONDARYBUFFER[i]->Release();
SDL_QuitSubSystem(SDL_INIT_AUDIO); SDL_QuitSubSystem(SDL_INIT_AUDIO);
//Close audio device
SDL_CloseAudioDevice(audioDevice); SDL_CloseAudioDevice(audioDevice);
//End organya
EndOrganya();
} }
//Sound effects playing //Sound effects playing
@ -293,20 +297,17 @@ void PlaySoundObject(int no, int mode)
void ChangeSoundFrequency(int no, unsigned long rate) void ChangeSoundFrequency(int no, unsigned long rate)
{ {
if (lpSECONDARYBUFFER[no]) lpSECONDARYBUFFER[no]->SetFrequency((rate * 10) + 100);
lpSECONDARYBUFFER[no]->SetFrequency(10 * rate + 100);
} }
void ChangeSoundVolume(int no, long volume) void ChangeSoundVolume(int no, long volume)
{ {
if (lpSECONDARYBUFFER[no]) lpSECONDARYBUFFER[no]->SetVolume((volume - 300) * 8);
lpSECONDARYBUFFER[no]->SetVolume(8 * volume - 2400);
} }
void ChangeSoundPan(int no, long pan) void ChangeSoundPan(int no, long pan)
{ {
if (lpSECONDARYBUFFER[no]) lpSECONDARYBUFFER[no]->SetPan((pan - 256) * 10);
lpSECONDARYBUFFER[no]->SetPan(10 * (pan - 256));
} }
int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no) int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no)

View file

@ -90,8 +90,8 @@ enum MUSIC_IDS
mus_White = 0x29 mus_White = 0x29
}; };
#define SOUND_NO 0x100 #define SE_MAX 160 // According to the Organya source code release, this is the real name for this constant
extern SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO]; extern SOUNDBUFFER* lpSECONDARYBUFFER[SE_MAX];
BOOL InitDirectSound(); BOOL InitDirectSound();
void EndDirectSound(); void EndDirectSound();