From 1ad072236d6fa1981d6e1b96f148081702283b95 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 29 Sep 2018 16:52:40 -0700 Subject: [PATCH] Avoid calling Pa_IsStreamStopped() on each audio frame --- app/streaming/audio/renderers/portaudiorenderer.cpp | 7 +++++-- app/streaming/audio/renderers/portaudiorenderer.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/streaming/audio/renderers/portaudiorenderer.cpp b/app/streaming/audio/renderers/portaudiorenderer.cpp index de5d6c2f..abc057ce 100644 --- a/app/streaming/audio/renderers/portaudiorenderer.cpp +++ b/app/streaming/audio/renderers/portaudiorenderer.cpp @@ -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; } } diff --git a/app/streaming/audio/renderers/portaudiorenderer.h b/app/streaming/audio/renderers/portaudiorenderer.h index e69bf506..8c203329 100644 --- a/app/streaming/audio/renderers/portaudiorenderer.h +++ b/app/streaming/audio/renderers/portaudiorenderer.h @@ -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]; };