Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::SoundStream onGetData()  (Read 2694 times)

0 Members and 1 Guest are viewing this topic.

Ectance

  • Newbie
  • *
  • Posts: 8
    • View Profile
sf::SoundStream onGetData()
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: sf::SoundStream onGetData()
« Reply #1 on: May 06, 2014, 03:18:00 pm »
onGetData gets called in fillAndPushBuffer, 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundStream onGetData()
« Reply #2 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.
« Last Edit: May 06, 2014, 03:31:07 pm by Laurent »
Laurent Gomila - SFML developer

Ectance

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::SoundStream onGetData()
« Reply #3 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 )
« Last Edit: May 08, 2014, 12:32:29 pm by Ectance »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundStream onGetData()
« Reply #4 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).
Laurent Gomila - SFML developer