I've got a problem with the sf::SoundStream class where the OnGetData is not called often enough and the "externalChunks_" buffer is filled much faster than its emptied. Thus I get delayed and stuttering audio.
What am I doing wrong?
class SoundChannel : public sf::SoundStream
{
public:
SoundChannel() : internalChunks_(25) // Keep data for 25 frames = 1 sec
{
Initialize(2, 48000);
}
~SoundChannel()
{
Stop();
}
void Push(const AudioChunkPtr& pAudioChunk) // Called once per frame, push in audio data for one frame
{
externalChunks_.push(pAudioChunk); // pushes ALOT more than is popped
if(GetStatus() != Playing)
Play();
}
private:
bool OnGetData(sf::SoundStream::Chunk& data) // Should be called much more often
{
AudioChunkPtr pChunk;
externalChunks_.pop(pChunk); // doesn't empty fast enough
internalChunks_.push_back(pChunk); // Keep memory allocated while the audio is played
data.Samples = reinterpret_cast<sf::Int16*>(pChunk->GetDataPtr());
data.NbSamples = 3840; // Each "AudioChunk" has enough audio data for one frame, 7680 bytes per frame in 25 fps, 1 sample = 2 bytes
return true;
}
boost::circular_buffer<AudioChunkPtr> internalChunks_;
tbb::concurrent_bounded_queue<AudioChunkPtr> externalChunks_;
};
EDIT:
If i change the samplerate to 24000 i get rid of the stuttering... however it sounds very wierd and is delayed.
Iprobably should mention im using SFML 1.6