Search code examples
c++audiosfml

SFML Audio getSample in realtime using sf::Music


Is there any way to read the current sample that's been playing in sf::Music for further inspection using FFT algorithms and such?

Just like you would do using sf::SoundBuffer with getSamples().


Solution

  • No, not really. But considering you'll want a significant portion of your file (or maybe everything) in memory anyway, just use sf::SoundBuffer and sf::Sound for this.

    To get the sample for the current playback position you'd have to do some calculation like samplesPerSecond * playbackPosition. Just interpolate the time between the last and current calculation.