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

Author Topic: Playing a sound wave  (Read 3198 times)

0 Members and 1 Guest are viewing this topic.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Playing a sound wave
« 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?

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Playing a sound wave
« Reply #1 on: December 22, 2015, 09:53:56 pm »
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.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Playing a sound wave
« Reply #2 on: December 22, 2015, 10:19:26 pm »
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.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Playing a sound wave
« Reply #3 on: December 22, 2015, 10:25:59 pm »
You can play a wave created from a maths function by sampling the function and storing them in a sf::SoundBuffer.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Playing a sound wave
« Reply #4 on: December 22, 2015, 10:46:29 pm »
That is a very good point. Thank you.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Playing a sound wave
« Reply #5 on: December 22, 2015, 10:51:29 pm »
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Playing a sound wave
« Reply #6 on: December 23, 2015, 08:01:44 am »
Volume controls the amplitude, and pitch controls the frequency. So you could even change the whole sine without touching the sampled data.
Laurent Gomila - SFML developer