Multi Channel Microphone Recording

I’m currently working on a recording system for the Microphone using FMOD. For my single channel microphone this works well, but a tester with a stereo microphone is getting very choppy audio recording.

At the moment my code to setup the recording looks something like this:

var sys = RuntimeManager.CoreSystem;

sys.getRecordDriverInfo(mic, out _, 0, out _, out var rate, out _, out var channels, out _);

// Create a sound with a one second buffer
CREATESOUNDEXINFO exinfo = default;
exinfo.cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO));
exinfo.numchannels = channels;
exinfo.format = SOUND_FORMAT.PCMFLOAT;
exinfo.defaultfrequency = rate;
exinfo.length = (uint)(deviceSampleRate * sizeof(float));

sys.createSound("recording", MODE.LOOP_NORMAL | MODE.OPENUSER, ref exinfo, out _sound);

I only actually need a mono recording, is it possible to tell FMOD to downmix into a single channel for me? For example by replacing exinfo.numchannels = channels; with exinfo.numchannels = 1?

Alternatively, if that’s not possible does my implementation for mixing down to one channel look reasonable?

private ArraySegment<float> DownmixChannels(ArraySegment<float> data)
    if (_deviceChannels == 1)
        return data;

    var arr = data.Array;
    var channels = _deviceChannels; // This is the same `channels` value from the previous code example
    var factor = 1f / channels;
    var monoSamples = data.Count / channels;
    for (var i = 0; i < monoSamples; i++)
        // Add together all the channels
        var sum = 0f;
        for (var j = 0; j < _deviceChannels; j++)
            sum += arr[i * channels + j];

        // Divide by channel count and save into proper place in buffer
        arr[i] = factor * sum;

    return new ArraySegment<float>(arr, 0, monoSamples);

Any thoughts on this? In particular the first bit about if using exinfo.numchannels = 1 works would be very useful to know!

I have been informed that changing the created sound to a mono channel (via exinfo.numchannels is the correct way to go. Can you confirm if this has helped with the choppy audio recorded?

1 Like

This seems to have fixed it. Thanks!