Our game is a rhythm game that can be played with any music file on the player’s computer, and I’d like to know when the volume/amplitude of a song’s waveform is below a certain level. I would like to be able to ask, for example: What is the apparent volume of the track currently being played, at its current playback position?
When a portion of a song is silent (or, at least, below some threshold) I want the game to behave differently. What’s the best way to do this with FMOD? Should I calculate it via the data from getWaveData? Or is there some function that returns amplitude/volume?
Thanks for your help!
- Ryan Clark asked 5 years ago
You can create DSP to measure amplitude RMS (you will have to create one by yourself since FMODEx doesn’t provide one) and connect it to FMOD::Channel DSP head. Other option is to preprocess wave data (basically with the same algorithm you would use in the DSP, only offline) and create LUT so you can select two samples from LUT based on the sound playback position and interpolate them.
- lromaniuk answered 5 years ago
You can create FMOD::Sound with FMOD_CREATESAMPLE falg. This way the sound buffer should contain uncompressed PCM data. Next as you’ve said you have to use FMOD::Sound::Lock to get to the internal sound buffer. To get numer of bytes you have to lock on you can use FMOD::Sound::GetLength providing FMOD_TIMEUNIT_RAWBYTES flag. Then you can use FMOD::Sound::getFormat() to obtain information nedded to interpret raw bytes as a valid sample data.
- lromaniuk answered 4 years ago
Thanks for the help, lromaniuk! If I were to do this by pre-processing the wave data, I assume I’d use Sound::lock and Sound::unlock ? Is there any source code out there for taking the various kinds of raw audio data that Sound::lock returns and converting it into a usable waveform?
- Ryan Clark answered 5 years ago
Please login first to submit.