mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
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:
parent
0337568846
commit
95c98093e9
@ -251,6 +251,20 @@ protected:
|
||||
////////////////////////////////////////////////////////////
|
||||
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:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -315,8 +329,9 @@ private:
|
||||
unsigned int m_sampleRate; //!< Frequency (samples / second)
|
||||
Uint32 m_format; //!< Format of the internal sound buffers
|
||||
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.
|
||||
Time m_processingInterval; //!< Interval for checking and filling the internal sound buffers.
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -51,7 +51,8 @@ m_sampleRate (0),
|
||||
m_format (0),
|
||||
m_loop (false),
|
||||
m_samplesProcessed(0),
|
||||
m_bufferSeeks ()
|
||||
m_bufferSeeks (),
|
||||
m_processingInterval(milliseconds(10))
|
||||
{
|
||||
|
||||
}
|
||||
@ -264,6 +265,11 @@ Int64 SoundStream::onLoop()
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::setProcessingInterval(Time interval)
|
||||
{
|
||||
m_processingInterval = interval;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::streamData()
|
||||
@ -384,7 +390,7 @@ void SoundStream::streamData()
|
||||
|
||||
// Leave some time for the other threads if the stream is still playing
|
||||
if (SoundSource::getStatus() != Stopped)
|
||||
sleep(milliseconds(10));
|
||||
sleep(m_processingInterval);
|
||||
}
|
||||
|
||||
// Stop the playback
|
||||
|
Loading…
Reference in New Issue
Block a user