Fix audio device error with PA renderer (and constify some methods)

This commit is contained in:
Cameron Gutman
2018-09-29 22:19:41 -07:00
parent 6758d6c43e
commit fa52e7c1b7
5 changed files with 40 additions and 16 deletions
@@ -109,7 +109,7 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
}
}
bool PortAudioRenderer::testAudio(int audioConfiguration)
bool PortAudioRenderer::testAudio(int audioConfiguration) const
{
PaStreamParameters params = {};
@@ -120,6 +120,13 @@ bool PortAudioRenderer::testAudio(int audioConfiguration)
return false;
}
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(outputDeviceIndex);
if (deviceInfo == nullptr) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Pa_GetDeviceInfo() failed");
return false;
}
switch (audioConfiguration)
{
case AUDIO_CONFIGURATION_STEREO:
@@ -135,20 +142,37 @@ bool PortAudioRenderer::testAudio(int audioConfiguration)
params.sampleFormat = paInt16;
params.device = outputDeviceIndex;
params.suggestedLatency = deviceInfo->defaultLowOutputLatency;
PaError error = Pa_IsFormatSupported(nullptr, &params, 48000);
if (error == paFormatIsSupported) {
return true;
}
else {
// We used to just use Pa_IsFormatSupported() but there are cases
// where Pa_IsFormatSupported() will fail but when we actually
// call Pa_OpenStream(), it fails with device unavailable.
PaStream* stream;
PaError error = Pa_OpenStream(&stream, nullptr, &params,
48000,
SAMPLES_PER_FRAME,
paNoFlag,
nullptr, nullptr);
if (error != paNoError) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Pa_IsFormatSupported() failed: %s",
"Pa_OpenStream() failed: %s",
Pa_GetErrorText(error));
return false;
}
error = Pa_StartStream(m_Stream);
if (error != paNoError) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Pa_StartStream() failed: %s",
Pa_GetErrorText(error));
}
Pa_CloseStream(stream);
return error == paNoError;
}
int PortAudioRenderer::detectAudioConfiguration()
int PortAudioRenderer::detectAudioConfiguration() const
{
const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
if (deviceInfo == nullptr) {