SFML community forums

Help => Audio => Topic started by: Ectance on May 06, 2014, 03:06:51 pm

Title: sf::SoundStream onGetData()
Post by: Ectance on May 06, 2014, 03:06:51 pm
Hello again~!

Can I ask when exactly is onGetData() called ? When the previous chunk of samples has finished being played or a bit sooner ?
Is it possible if onGetData() takes lets say 2-3ms to return true , cracks or gaps in the sound to be produced ?
Thanks.
Title: Re: sf::SoundStream onGetData()
Post by: eXpl0it3r on May 06, 2014, 03:18:00 pm
onGetData gets called in fillAndPushBuffer (https://github.com/SFML/SFML/blob/master/src/SFML/Audio/SoundStream.cpp#L311), which get's called by fillQueue, which gets called by streamData, which gets called by in the initialization list for the second thread.

I'm not sure whether it's possible to make assumption about the timing. You'd really just have to test it.
What are you trying to do?
Title: Re: sf::SoundStream onGetData()
Post by: Laurent on May 06, 2014, 03:28:51 pm
sf::SoundStream is triple-buffered, which means that when you fill a chunk, two others are still playing.

Computing the delay is simple, if you know how many samples you put into each. Divide by the sample rate, multiply by two.
Title: Re: sf::SoundStream onGetData()
Post by: Ectance on May 08, 2014, 12:28:40 pm
The delay is not an issue . Even 250-300ms are fine in my case , I'm coding a standalone synthesizer/wave generator by the way .
When it's generating sounds in real-time ( instead writing them to a file )  , every time a chunk is popped from a queue and passed to the internal AL queue, I get "missing" part of a waveform.Not cutted or anything just audiable flat line for 1-2ms so I asked the question to understand if the problem is in my code or the speed of which the internal queue is filling.

And the pipeline :

Create chunk of N samples -> write a sine/whatever wave -> push in queue -> pop from queue -> pass to .data


( main thread ; SoundStream thread )
Title: Re: sf::SoundStream onGetData()
Post by: Laurent on May 08, 2014, 02:50:48 pm
You should experiment with a simpler use case, to make sure sf::SoundStream is behaving as expected. For example, you couldgenerate a sine wave directly in onGetData (no other thread involved).