mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 22:23:31 +00:00
Avoid calling Pa_IsStreamStopped() on each audio frame
This commit is contained in:
@@ -8,7 +8,8 @@ PortAudioRenderer::PortAudioRenderer()
|
|||||||
: m_Stream(nullptr),
|
: m_Stream(nullptr),
|
||||||
m_ChannelCount(0),
|
m_ChannelCount(0),
|
||||||
m_WriteIndex(0),
|
m_WriteIndex(0),
|
||||||
m_ReadIndex(0)
|
m_ReadIndex(0),
|
||||||
|
m_Started(false)
|
||||||
{
|
{
|
||||||
PaError error = Pa_Initialize();
|
PaError error = Pa_Initialize();
|
||||||
if (error != paNoError) {
|
if (error != paNoError) {
|
||||||
@@ -95,7 +96,7 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
|
|||||||
m_WriteIndex = (m_WriteIndex + 1) % CIRCULAR_BUFFER_SIZE;
|
m_WriteIndex = (m_WriteIndex + 1) % CIRCULAR_BUFFER_SIZE;
|
||||||
|
|
||||||
// Start the stream after we've written the first sample to it
|
// 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);
|
PaError error = Pa_StartStream(m_Stream);
|
||||||
if (error != paNoError) {
|
if (error != paNoError) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
@@ -103,6 +104,8 @@ void PortAudioRenderer::submitAudio(short* audioBuffer, int audioSize)
|
|||||||
Pa_GetErrorText(error));
|
Pa_GetErrorText(error));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ private:
|
|||||||
int m_ChannelCount;
|
int m_ChannelCount;
|
||||||
int m_WriteIndex;
|
int m_WriteIndex;
|
||||||
int m_ReadIndex;
|
int m_ReadIndex;
|
||||||
|
bool m_Started;
|
||||||
short m_AudioBuffer[CIRCULAR_BUFFER_SIZE * CIRCULAR_BUFFER_STRIDE];
|
short m_AudioBuffer[CIRCULAR_BUFFER_SIZE * CIRCULAR_BUFFER_STRIDE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user