Fix a possible hang in the audio mixer
It was likely a race condition between the game thread writing to 'organya_timer', and the audio thread reading it. ...I really need to rethink the API for this Organya-synchronisation thing.
This commit is contained in:
parent
e599d02fb1
commit
788697dc5d
4 changed files with 16 additions and 7 deletions
|
@ -22,3 +22,5 @@ void AudioBackend_RewindSound(AudioBackend_Sound *sound);
|
|||
void AudioBackend_SetSoundFrequency(AudioBackend_Sound *sound, unsigned int frequency);
|
||||
void AudioBackend_SetSoundVolume(AudioBackend_Sound *sound, long volume);
|
||||
void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan);
|
||||
|
||||
void AudioBackend_SetOrganyaTimer(unsigned short timer);
|
||||
|
|
|
@ -44,6 +44,8 @@ static SDL_AudioDeviceID device_id;
|
|||
|
||||
static unsigned long output_frequency;
|
||||
|
||||
static unsigned short organya_timer;
|
||||
|
||||
static double MillibelToScale(long volume)
|
||||
{
|
||||
// Volume is in hundredths of decibels, from 0 to -10000
|
||||
|
@ -351,3 +353,12 @@ void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan)
|
|||
|
||||
SDL_UnlockAudioDevice(device_id);
|
||||
}
|
||||
|
||||
void AudioBackend_SetOrganyaTimer(unsigned short timer)
|
||||
{
|
||||
SDL_LockAudioDevice(device_id);
|
||||
|
||||
organya_timer = timer;
|
||||
|
||||
SDL_UnlockAudioDevice(device_id);
|
||||
}
|
||||
|
|
|
@ -95,8 +95,6 @@ typedef struct OrgData
|
|||
BOOL InitMusicData(const char *path);
|
||||
} ORGDATA;
|
||||
|
||||
unsigned short organya_timer;
|
||||
|
||||
AudioBackend_Sound *lpORGANBUFFER[8][8][2] = {NULL};
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
@ -827,7 +825,7 @@ void PlayOrganyaMusic(void)
|
|||
if (!audio_backend_initialised)
|
||||
return;
|
||||
|
||||
organya_timer = org_data.info.wait;
|
||||
AudioBackend_SetOrganyaTimer(org_data.info.wait);
|
||||
}
|
||||
|
||||
BOOL ChangeOrganyaVolume(signed int volume)
|
||||
|
@ -847,7 +845,7 @@ void StopOrganyaMusic(void)
|
|||
if (!audio_backend_initialised)
|
||||
return;
|
||||
|
||||
organya_timer = 0;
|
||||
AudioBackend_SetOrganyaTimer(0);
|
||||
|
||||
// Stop notes
|
||||
for (int i = 0; i < MAXMELODY; i++)
|
||||
|
@ -870,7 +868,7 @@ void EndOrganya(void)
|
|||
if (!audio_backend_initialised)
|
||||
return;
|
||||
|
||||
organya_timer = 0;
|
||||
AudioBackend_SetOrganyaTimer(0);
|
||||
|
||||
// Release everything related to org
|
||||
org_data.ReleaseNote();
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#define MAXMELODY 8
|
||||
#define MAXDRAM 8
|
||||
|
||||
extern unsigned short organya_timer;
|
||||
|
||||
extern BOOL g_mute[MAXTRACK]; // Used by the debug Mute menu
|
||||
|
||||
BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
|
||||
|
|
Loading…
Add table
Reference in a new issue