I have an audio file and I want a float variable to be synced with it. The float variable will then be used to create a graphical indication of the audio file being played.
What I would like to happen:
Every other beat in the audio file (first beat, third beat, fifth beat, and so on), the variable should be 0.0f. The other beats (second beat, forth beat, sixth beat, and so on), the variable should be 1.0f.
On top of that, I would like the variable, over time, between the beats, to "slide" between 0.0 and 1.0, and my first thought is to use the sin-function in the C++ standard library.
The information I have about the audio file:
- The tempo / BPM of the file
- The length of the file (in seconds)
- How many beats in total the audio file consist of
- The position of the file, while it's being played back. I know where in the song, in seconds, I'm currently at. For example, if the song has played for 3 and a half seconds, I get 3.5f from the function I'm using
Besides this, I also have a deltatime and a lifetime, which tells how long (in seconds) the application has been executed.
Since the sin-function takes a float (or double) as parameter, what I need help with is the calculation, which can then be passed as the parameter to the function, which will then be used to generate a sine wave synced with the audio file.