The channels of the FFT’s spectrum data are simply arranged in order. If you want to get the FFT of the right channel instead of the left, instead of:
fftData.getSpectrum(0, ref mFFTSpectrum);
You can do:
fftData.getSpectrum(1, ref mFFTSpectrum);
Alternatively, if you want to retrieve the spectrum data for all channels, you can use the other getSpectrum
overload which passes the data for all channels out by reference:
// create and initialize buffer for all channels
float[][] allFFTData = new float[fftData.numchannels][];
for (int i = 0; i < fftData.numchannels; ++i)
{
allFFTData[i] = new float[fftData.length];
}
// pass buffer to function by reference to get spectrum data for all channels
fftData.getSpectrum(ref allFFTData);
Note that summing the FFT data from all channels isn’t the same as an FFT of the sum of all channels, as the former will only give you the total signal power, which may be all you need for your purposes.
If not, the simplest way to sum the channels before the FFT would be to use DSP::setChannelFormat
to set the DSP to mono, which will force a downmix before the FFT occurs. This will affect the rest of the signal chain though, so you may wish to create a split in the signal and place your FFT DSP in parallel with a ChannelGroup instead of inserting it into the ChannelGroup. To do this, instead of adding the DSP to the ChannelGroup, you’ll need to manually connect it to another DSP like so:
// add FFT DSP parallel to signal
// get head DSP of channel group
FMOD.DSP cgHead;
channelGroup.getDSP(FMOD.CHANNELCONTROL_DSP_INDEX.HEAD, out cgHead);
// creates a loop in signal - potentially bad, but we mute the FFT DSP's output so it's fine
mFFT.addInput(cgHead);
cgHead.addInput(mFFT);
mFFT.setWetDryMix(1, 0, 0);
// set pre-processing downmix to mono for FFT DSP
mFFT.setChannelFormat(FMOD.CHANNELMASK.MONO, 1, FMOD.SPEAKERMODE.MAX);
// set FFT DSP as active
mFFT.setActive(true);
Additionally, if you wanted to avoid any spatialization affecting your FFT, you could place your FFT DSP (either in sequence or in parallel) before the spatializer in your DSP chain.