Hi everyone !
I am using Fmod in Unity for a game project about sound visualization. I started to dwelve into DSP in order to retrieve data from the audio signal but I had absolutely zero experience with it. I kind of got the basic concept of it, but I have to admit I have a hard time understanding how to implement it and what internal logic is going on.
Here I am simply trying to retrieve the total volume output of a sound heard by the player, and also the dominant frequency. I managed to get the first thing working with the code below, but I am stuck with the second one : I always get the value 360, no matter what. To be honnest I don’t really understand exactly what my code is doing and for example I tried removing the “addDSP” line and if I do I get 120 as a return value.
Eventually I would like to use fft in order to get the volume of all the channels for samples of frequency, but I don’t know how this is to be integrated. I managed to grab some bits of info here and there, but I couldn’t get it to work for my personal problems.
Here is the code I have so far :
void GetDSPMeteringInfo()
{
soundEvent.getChannelGroup(out thisSoundEventChannels);
thisSoundEventChannels.setPitch(pitch);
thisSoundEventChannels.addDSP(0, dsp);
thisSoundEventChannels.getDSP(0, out dsp);
dsp.setMeteringEnabled(true, true);
dsp.setActive(true);
dsp.setBypass(false);
dsp.getParameterFloat(FMOD.DSP_FFT.DOMINANT_FREQ.GetHashCode(), out averagePitchOutput);
dsp.getMeteringInfo(System.IntPtr.Zero, out dspOutput);
volumeOutput = 0; //reset the saved sound volume at the beginning of the frame (so that it doesn't keep increasing)
for (int i = 0; i < dspOutput.numchannels; i++)
{
volumeOutput = volumeOutput + dspOutput.peaklevel[i]; //add the rms level of each channel of the output of the channel group to the total channel group volume
}
/*
for (int channel = 0; channel < fftParam.numchannels; channel++) //for each channel (audio outputs = 2 with regular headphones for example)
{
for (int bin = 0; bin < fftParam.length; bin++) //for each sample in this channel. 256 samples made
{
samplesValues[channel] = fftParam.spectrum[channel][bin];
}
}
*/
//Not really dwelved into it yet ; the goal is eventually to get the volume of each frequency sample
}
I am sorry for asking such a vague question. I am really stuck right now but I think my problem comes from the fact that I am lost about how DSPs are to be implemented.
Thank you so much for your time.