SFML community forums
Help => Audio => Topic started by: shadowmouse on December 22, 2015, 09:29:16 pm
-
I have a function that allows a user input maths function (such as y = 2 *sin x) to be evaluated for whatever value of x. Is it possible to play this wave via SFML? The only way I've seen it done is via a callback that would pass the time value to the evaluation function, and then the result would be passed back to the library (done using PortAudio). As far as I know, you can't do that with SFML, so is there some other way to do it?
-
What exactly are you trying to do? Do you want to modulate a sound's amplitude over time based on the graph? Or do you want to directly use the graph results for your samples?
I'm in the process of writing a tutorial for simple audio processing with SFML, although that might take a bit till it's done.
-
Either, as long as they produce the result of playing back an entered sound wave. My original plan was to change the amplitude over time based on the graph function, but I had also thought of precalculating the amplitudes and storing them in an array then playing it at a set rate.
-
You can play a wave created from a maths function by sampling the function and storing them in a sf::SoundBuffer.
-
That is a very good point. Thank you.
-
If you'd like to modify the amplitude, you could just play a static/constant sinus wave and update it's volume while updating the graph.
-
Volume controls the amplitude, and pitch controls the frequency. So you could even change the whole sine without touching the sampled data.