# Multi Channel Microphone Recording

**URL:** <https://qa.fmod.com/t/multi-channel-microphone-recording/18519>\
**Category:** Unity\
**Created:** [March 15, 2022, 9:30pm UTC](https://qa.fmod.com/t/multi-channel-microphone-recording/18519 "2022-03-15T21:30:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martindevans1](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/martindevans1/32/3052_2.png) [@martindevans1](https://qa.fmod.com/u/martindevans1)\
**Post date:** [March 15, 2022, 9:30pm UTC](https://qa.fmod.com/t/multi-channel-microphone-recording/18519/1 "2022-03-15T21:30:25Z")

</div>

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:

```nohighlight
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?

```nohighlight
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);
}

```

---

<div class="post-metadata">

**Author:** ![martindevans1](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/martindevans1/32/3052_2.png) [@martindevans1](https://qa.fmod.com/u/martindevans1)\
**Post date:** [March 22, 2022, 3:58pm UTC](https://qa.fmod.com/t/multi-channel-microphone-recording/18519/2 "2022-03-22T15:58:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richard\_simms](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/richard_simms/32/261_2.png) [@richard\_simms](https://qa.fmod.com/u/richard_simms)\
**Post date:** [March 24, 2022, 1:07pm UTC](https://qa.fmod.com/t/multi-channel-microphone-recording/18519/3 "2022-03-24T13:07:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![martindevans1](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/martindevans1/32/3052_2.png) [@martindevans1](https://qa.fmod.com/u/martindevans1)\
**Post date:** [March 27, 2022, 7:29pm UTC](https://qa.fmod.com/t/multi-channel-microphone-recording/18519/4 "2022-03-27T19:29:17Z")

</div>

This seems to have fixed it. Thanks!
