Search code examples
c++audiowavwaveform

Mute one channel of audio


I am dealing with audio data in the form of floats.

I would like to know if there is a way to mute a channel (the left or the right one) with a simply command, like just setting each second float to 0 or so. :-)

Thank you.


Solution

  • It's going to depend (completely) on the form in which your data is encoded.

    If (and pretty much, only if) it's encoded as raw samples interleaved by channels, then yes, you can probably mute a channel by replacing its samples with zeros.

    There are, however, lots of alternatives to that format. Just for one example, you could send L+R as one set of samples, and L-R as the other set of samples. In a case like this, you'd need to decode the channels from the data (L+R + L-R => L, L + R - L - R => R), zero the samples for one channel, then combine the result back to the same format.

    Of course, a lot of formats are substantially more complex than even that. Compression like MP3 is considerably more complex with regard to encoding a single channel and allows you to encode the channels separately or as something like a sum and difference (which will usually save some space).