Adjustable processing interval in SoundStream #1517

Resurrection of previous PR with updated documentation. Added setter to
adjust processing interval in SoundStream for low-latency streams.
This commit is contained in:
scotth 2020-05-28 21:06:18 +09:30 committed by Lukas Dürrenberger
parent 0337568846
commit 95c98093e9
2 changed files with 24 additions and 3 deletions

View File

@ -251,6 +251,20 @@ protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual Int64 onLoop(); virtual Int64 onLoop();
////////////////////////////////////////////////////////////
/// \brief Set the processing interval
///
/// The processing interval controls the period at which the
/// audio buffers are filled by calls to onGetData. A smaller
/// interval may be useful for low-latency streams. Note that
/// the given period is only a hint and the actual period may
/// vary. The default processing interval is 10 ms.
///
/// \param interval Processing interval
///
////////////////////////////////////////////////////////////
void setProcessingInterval(Time interval);
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -315,8 +329,9 @@ private:
unsigned int m_sampleRate; //!< Frequency (samples / second) unsigned int m_sampleRate; //!< Frequency (samples / second)
Uint32 m_format; //!< Format of the internal sound buffers Uint32 m_format; //!< Format of the internal sound buffers
bool m_loop; //!< Loop flag (true to loop, false to play once) bool m_loop; //!< Loop flag (true to loop, false to play once)
Uint64 m_samplesProcessed; //!< Number of buffers processed since beginning of the stream Uint64 m_samplesProcessed; //!< Number of samples processed since beginning of the stream
Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation. Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation.
Time m_processingInterval; //!< Interval for checking and filling the internal sound buffers.
}; };
} // namespace sf } // namespace sf

View File

@ -51,7 +51,8 @@ m_sampleRate (0),
m_format (0), m_format (0),
m_loop (false), m_loop (false),
m_samplesProcessed(0), m_samplesProcessed(0),
m_bufferSeeks () m_bufferSeeks (),
m_processingInterval(milliseconds(10))
{ {
} }
@ -264,6 +265,11 @@ Int64 SoundStream::onLoop()
return 0; return 0;
} }
////////////////////////////////////////////////////////////
void SoundStream::setProcessingInterval(Time interval)
{
m_processingInterval = interval;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundStream::streamData() void SoundStream::streamData()
@ -384,7 +390,7 @@ void SoundStream::streamData()
// Leave some time for the other threads if the stream is still playing // Leave some time for the other threads if the stream is still playing
if (SoundSource::getStatus() != Stopped) if (SoundSource::getStatus() != Stopped)
sleep(milliseconds(10)); sleep(m_processingInterval);
} }
// Stop the playback // Stop the playback