only open microphone when actually needed. fixes #1165
This commit is contained in:
parent
9ee2017443
commit
aaa97c9242
|
@ -106,6 +106,8 @@ u32 micExtBufferWritePos;
|
||||||
u32 micWavLength;
|
u32 micWavLength;
|
||||||
s16* micWavBuffer;
|
s16* micWavBuffer;
|
||||||
|
|
||||||
|
void micCallback(void* data, Uint8* stream, int len);
|
||||||
|
|
||||||
|
|
||||||
void audioCallback(void* data, Uint8* stream, int len)
|
void audioCallback(void* data, Uint8* stream, int len)
|
||||||
{
|
{
|
||||||
|
@ -143,6 +145,40 @@ void audioCallback(void* data, Uint8* stream, int len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void micOpen()
|
||||||
|
{
|
||||||
|
if (Config::MicInputType != 1)
|
||||||
|
{
|
||||||
|
micDevice = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_AudioSpec whatIwant, whatIget;
|
||||||
|
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
|
||||||
|
whatIwant.freq = 44100;
|
||||||
|
whatIwant.format = AUDIO_S16LSB;
|
||||||
|
whatIwant.channels = 1;
|
||||||
|
whatIwant.samples = 1024;
|
||||||
|
whatIwant.callback = micCallback;
|
||||||
|
micDevice = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0);
|
||||||
|
if (!micDevice)
|
||||||
|
{
|
||||||
|
printf("Mic init failed: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_PauseAudioDevice(micDevice, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void micClose()
|
||||||
|
{
|
||||||
|
if (micDevice)
|
||||||
|
SDL_CloseAudioDevice(micDevice);
|
||||||
|
|
||||||
|
micDevice = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void micLoadWav(const char* name)
|
void micLoadWav(const char* name)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec format;
|
SDL_AudioSpec format;
|
||||||
|
@ -623,7 +659,7 @@ void EmuThread::emuRun()
|
||||||
// checkme
|
// checkme
|
||||||
emit windowEmuStart();
|
emit windowEmuStart();
|
||||||
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0);
|
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0);
|
||||||
if (micDevice) SDL_PauseAudioDevice(micDevice, 0);
|
micOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuPause()
|
void EmuThread::emuPause()
|
||||||
|
@ -636,7 +672,7 @@ void EmuThread::emuPause()
|
||||||
while (EmuStatus != 2);
|
while (EmuStatus != 2);
|
||||||
|
|
||||||
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1);
|
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1);
|
||||||
if (micDevice) SDL_PauseAudioDevice(micDevice, 1);
|
micClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuUnpause()
|
void EmuThread::emuUnpause()
|
||||||
|
@ -649,7 +685,7 @@ void EmuThread::emuUnpause()
|
||||||
EmuRunning = PrevEmuStatus;
|
EmuRunning = PrevEmuStatus;
|
||||||
|
|
||||||
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0);
|
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0);
|
||||||
if (micDevice) SDL_PauseAudioDevice(micDevice, 0);
|
micOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuStop()
|
void EmuThread::emuStop()
|
||||||
|
@ -658,7 +694,7 @@ void EmuThread::emuStop()
|
||||||
EmuPause = 0;
|
EmuPause = 0;
|
||||||
|
|
||||||
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1);
|
if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1);
|
||||||
if (micDevice) SDL_PauseAudioDevice(micDevice, 1);
|
micClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuFrameStep()
|
void EmuThread::emuFrameStep()
|
||||||
|
@ -2393,6 +2429,8 @@ void MainWindow::onOpenAudioSettings()
|
||||||
|
|
||||||
void MainWindow::onAudioSettingsFinished(int res)
|
void MainWindow::onAudioSettingsFinished(int res)
|
||||||
{
|
{
|
||||||
|
micClose();
|
||||||
|
|
||||||
if (Config::MicInputType == 3)
|
if (Config::MicInputType == 3)
|
||||||
{
|
{
|
||||||
micLoadWav(Config::MicWavPath);
|
micLoadWav(Config::MicWavPath);
|
||||||
|
@ -2408,6 +2446,8 @@ void MainWindow::onAudioSettingsFinished(int res)
|
||||||
else
|
else
|
||||||
Frontend::Mic_SetExternalBuffer(NULL, 0);
|
Frontend::Mic_SetExternalBuffer(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
micOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onOpenWifiSettings()
|
void MainWindow::onOpenWifiSettings()
|
||||||
|
@ -2751,21 +2791,7 @@ int main(int argc, char** argv)
|
||||||
SDL_PauseAudioDevice(audioDevice, 1);
|
SDL_PauseAudioDevice(audioDevice, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&whatIwant, 0, sizeof(SDL_AudioSpec));
|
micDevice = 0;
|
||||||
whatIwant.freq = 44100;
|
|
||||||
whatIwant.format = AUDIO_S16LSB;
|
|
||||||
whatIwant.channels = 1;
|
|
||||||
whatIwant.samples = 1024;
|
|
||||||
whatIwant.callback = micCallback;
|
|
||||||
micDevice = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0);
|
|
||||||
if (!micDevice)
|
|
||||||
{
|
|
||||||
printf("Mic init failed: %s\n", SDL_GetError());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SDL_PauseAudioDevice(micDevice, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
memset(micExtBuffer, 0, sizeof(micExtBuffer));
|
memset(micExtBuffer, 0, sizeof(micExtBuffer));
|
||||||
|
@ -2836,7 +2862,7 @@ int main(int argc, char** argv)
|
||||||
Frontend::DeInit_ROM();
|
Frontend::DeInit_ROM();
|
||||||
|
|
||||||
if (audioDevice) SDL_CloseAudioDevice(audioDevice);
|
if (audioDevice) SDL_CloseAudioDevice(audioDevice);
|
||||||
if (micDevice) SDL_CloseAudioDevice(micDevice);
|
micClose();
|
||||||
|
|
||||||
SDL_DestroyCond(audioSync);
|
SDL_DestroyCond(audioSync);
|
||||||
SDL_DestroyMutex(audioSyncLock);
|
SDL_DestroyMutex(audioSyncLock);
|
||||||
|
|
Loading…
Reference in New Issue