I'm trying to visualize an FFT using the sf::Music class. However my visualization happens 2 or so seconds before what gets played which is what I expected.
I'ts pretty easy to do this just by using an sf::SoundBuffer on it's own but then there is a 3-4 second delay loading the file and easily 100mb+ memory usage.
Having read
this thread I can't understand why I cannot simply do this:
class FFT: public sf::Music
{
public:
app()
{
loadFromFile("music.ogg");
play();
}
void input()
{
standard event stuff...
}
virtual bool onGetData(sf::SoundStream::Chunk& data)
{
bool result = sf::Music::onGetData(data);
chunkQ.push(data);
if (chunkQ.size() > bufferCount)
{
chunkQ.pop();
}
chunkData = chunkQ.front();
return result;
}
void render()
{
rendering vertex array....
}
void update()
{
crazy FFT shit going on here....
}
void run()
{
typical run loop....
}
private:
sf::SoundStream::Chunk chunkData;
std::queue<sf::SoundStream::Chunk> chunkQ;
window, vertex array, other stuff not important
};