pause audio/mic devices when they're not needed.
fixes potential pop when starting emulator (due to playing uninitialized audio buffer).
This commit is contained in:
parent
dbfb67fe8f
commit
64ab8302cb
|
@ -115,6 +115,8 @@ u32 KeyInputMask;
|
||||||
bool LidCommand, LidStatus;
|
bool LidCommand, LidStatus;
|
||||||
SDL_Joystick* Joystick;
|
SDL_Joystick* Joystick;
|
||||||
|
|
||||||
|
SDL_AudioDeviceID AudioDevice, MicDevice;
|
||||||
|
|
||||||
u32 MicBufferLength = 2048;
|
u32 MicBufferLength = 2048;
|
||||||
s16 MicBuffer[2048];
|
s16 MicBuffer[2048];
|
||||||
u32 MicBufferReadPos, MicBufferWritePos;
|
u32 MicBufferReadPos, MicBufferWritePos;
|
||||||
|
@ -1035,6 +1037,9 @@ void Run()
|
||||||
EmuRunning = 1;
|
EmuRunning = 1;
|
||||||
RunningSomething = true;
|
RunningSomething = true;
|
||||||
|
|
||||||
|
SDL_PauseAudioDevice(AudioDevice, 0);
|
||||||
|
SDL_PauseAudioDevice(MicDevice, 0);
|
||||||
|
|
||||||
uiMenuItemEnable(MenuItem_SaveState);
|
uiMenuItemEnable(MenuItem_SaveState);
|
||||||
uiMenuItemEnable(MenuItem_LoadState);
|
uiMenuItemEnable(MenuItem_LoadState);
|
||||||
|
|
||||||
|
@ -1080,6 +1085,9 @@ void Stop(bool internal)
|
||||||
|
|
||||||
memset(ScreenBuffer, 0, 256*384*4);
|
memset(ScreenBuffer, 0, 256*384*4);
|
||||||
uiAreaQueueRedrawAll(MainDrawArea);
|
uiAreaQueueRedrawAll(MainDrawArea);
|
||||||
|
|
||||||
|
SDL_PauseAudioDevice(AudioDevice, 1);
|
||||||
|
SDL_PauseAudioDevice(MicDevice, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupSRAMPath()
|
void SetupSRAMPath()
|
||||||
|
@ -1410,12 +1418,18 @@ void OnPause(uiMenuItem* item, uiWindow* window, void* blarg)
|
||||||
// enable pause
|
// enable pause
|
||||||
EmuRunning = 2;
|
EmuRunning = 2;
|
||||||
uiMenuItemSetChecked(MenuItem_Pause, 1);
|
uiMenuItemSetChecked(MenuItem_Pause, 1);
|
||||||
|
|
||||||
|
SDL_PauseAudioDevice(AudioDevice, 1);
|
||||||
|
SDL_PauseAudioDevice(MicDevice, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// disable pause
|
// disable pause
|
||||||
EmuRunning = 1;
|
EmuRunning = 1;
|
||||||
uiMenuItemSetChecked(MenuItem_Pause, 0);
|
uiMenuItemSetChecked(MenuItem_Pause, 0);
|
||||||
|
|
||||||
|
SDL_PauseAudioDevice(AudioDevice, 0);
|
||||||
|
SDL_PauseAudioDevice(MicDevice, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1969,14 +1983,14 @@ int main(int argc, char** argv)
|
||||||
whatIwant.channels = 2;
|
whatIwant.channels = 2;
|
||||||
whatIwant.samples = 1024;
|
whatIwant.samples = 1024;
|
||||||
whatIwant.callback = AudioCallback;
|
whatIwant.callback = AudioCallback;
|
||||||
SDL_AudioDeviceID audio = SDL_OpenAudioDevice(NULL, 0, &whatIwant, &whatIget, 0);
|
AudioDevice = SDL_OpenAudioDevice(NULL, 0, &whatIwant, &whatIget, 0);
|
||||||
if (!audio)
|
if (!AudioDevice)
|
||||||
{
|
{
|
||||||
printf("Audio init failed: %s\n", SDL_GetError());
|
printf("Audio init failed: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_PauseAudioDevice(audio, 0);
|
SDL_PauseAudioDevice(AudioDevice, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
|
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
|
||||||
|
@ -1985,15 +1999,15 @@ int main(int argc, char** argv)
|
||||||
whatIwant.channels = 1;
|
whatIwant.channels = 1;
|
||||||
whatIwant.samples = 1024;
|
whatIwant.samples = 1024;
|
||||||
whatIwant.callback = MicCallback;
|
whatIwant.callback = MicCallback;
|
||||||
SDL_AudioDeviceID mic = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0);
|
MicDevice = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0);
|
||||||
if (!mic)
|
if (!MicDevice)
|
||||||
{
|
{
|
||||||
printf("Mic init failed: %s\n", SDL_GetError());
|
printf("Mic init failed: %s\n", SDL_GetError());
|
||||||
MicBufferLength = 0;
|
MicBufferLength = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_PauseAudioDevice(mic, 0);
|
SDL_PauseAudioDevice(MicDevice, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(MicBuffer, 0, sizeof(MicBuffer));
|
memset(MicBuffer, 0, sizeof(MicBuffer));
|
||||||
|
@ -2038,8 +2052,8 @@ int main(int argc, char** argv)
|
||||||
SDL_WaitThread(EmuThread, NULL);
|
SDL_WaitThread(EmuThread, NULL);
|
||||||
|
|
||||||
if (Joystick) SDL_JoystickClose(Joystick);
|
if (Joystick) SDL_JoystickClose(Joystick);
|
||||||
if (audio) SDL_CloseAudioDevice(audio);
|
if (AudioDevice) SDL_CloseAudioDevice(AudioDevice);
|
||||||
if (mic) SDL_CloseAudioDevice(mic);
|
if (MicDevice) SDL_CloseAudioDevice(MicDevice);
|
||||||
|
|
||||||
if (MicWavBuffer) delete[] MicWavBuffer;
|
if (MicWavBuffer) delete[] MicWavBuffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue