Play vector from float as sound

is there any way i can play a vector from float as sound?
Is there a way that I can just pass a saved vector to a soundstream that it will play it?

Thanks for the help :slight_smile:

Hey @Skulla , oF has an ofSoundBuffer class that might work well, though I’ve never used it. There is a soundBufferExample that might be helpful, along with previous posts in the forum.

Hey @TimChi, thank you for your answer. I had already looked at that, but I can’t figure it out. In the examples only FIles are uploaded and then played. I try to play a saved vector of floats.

the ofSoundBuffer is esentially a float vector with some extra metadata.
take a look at examples/sound/audioOutputExample It is esentially doing what you are asking for, with some extra visualization stuff. You want to look at void ofApp::audioOut(ofSoundBuffer& buffer) which is the audio thread callback. In the example you can see that numbers are put inside buffer, which is what eventually goes out to the sound device.
Take a look at the ofSoundBuffer documentation as it has a lot of super useful functions for dealing with sound data.
Let me know if this cleared your doubt


Have a look at this soundBufferExample. It calculates samples from sin functions and stores them in an ofSoundBuffer; they are not loaded from a file. Maybe I don’t understand fully what you’re trying to do. But you should be able to adapt this example to “play” a std::vector in an ofSoundStream.

Edit: And I’ll 2nd roy’s suggestion for the audioOutputExample. Both of these examples use the audioOut() function with an ofSoundBuffer argument to calculate the audio samples.

1 Like