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.addDSP(0, dsp);
    thisSoundEventChannels.getDSP(0, out dsp);
    dsp.setMeteringEnabled(true, true);
    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.

  • You must to post comments
Best Answer

Here is an example of one way to get the fft data from a dsp:

What you should be doing is creating a (FMOD.DSP_TYPE.FFT) DSP, then attaching it to the channelGroup you want to monitor. You only need to do this the first time, the DSP is now part of the event and each time you call DSP::getParameterData you will receive the latest information. Then it is just a matter of what to do with the information.

We have some relatively new docs that might help with understanding:

  • Francois

    Oh thank you so much, it seems to be exactly what I needed !

    I swear I did quite a lot of research but didn’t find any of the two links you gave haha

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.