Avoid calling Pa_IsStreamStopped() on each audio frame

This commit is contained in:
Cameron Gutman 2018-09-29 16:52:40 -07:00
parent 76387aacad
commit 1ad072236d
2 changed files with 6 additions and 2 deletions

View file

@ -8,7 +8,8 @@ PortAudioRenderer::PortAudioRenderer()
: m_Stream(nullptr),
m_ChannelCount(0),
m_WriteIndex(0),
m_ReadIndex(0)
m_ReadIndex(0),
m_Started(false)
{
PaError error = Pa_Initialize();
if (error != paNoError) {
@ -95,7 +96,7 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
m_WriteIndex = (m_WriteIndex + 1) % CIRCULAR_BUFFER_SIZE;
// Start the stream after we've written the first sample to it
if (Pa_IsStreamStopped(m_Stream) == 1) {
if (!m_Started) {
PaError error = Pa_StartStream(m_Stream);
if (error != paNoError) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@ -103,6 +104,8 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
Pa_GetErrorText(error));
return;
}
m_Started = true;
}
}

View file

@ -36,6 +36,7 @@ private:
int m_ChannelCount;
int m_WriteIndex;
int m_ReadIndex;
bool m_Started;
short m_AudioBuffer[CIRCULAR_BUFFER_SIZE * CIRCULAR_BUFFER_STRIDE];
};