Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Mixing Mono Samples with Stereo Samples (Read 7207 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Mixing Mono Samples with Stereo Samples

Hello,

I've got two streams of audio sample that are stored in arrays, one mono and one stereo. I'd like to mix the mono into the stereo stream and output as stereo. Any known examples to accomplish?

Thanks in advance.........Mick

Mixing Mono Samples with Stereo Samples

Reply #1
How about converting the mono to stereo (two identical tracks) and then mixing normally?

Mixing Mono Samples with Stereo Samples

Reply #2
Is this anything like M-S Stereo System?  That's Main & Sides or Mid & Sides or Middle & Sides or the earlier Mitte-Seite.
Kevin Graf :: aka Speedskater

Mixing Mono Samples with Stereo Samples

Reply #3
How about converting the mono to stereo (two identical tracks) and then mixing normally?

Yes that's reasonable. I could convert the mono easily, so then what is the mixing normally part? Is it fairly straight-forward?

Mixing Mono Samples with Stereo Samples

Reply #4
It’s one of the simplest operations that can be performed upon audio streams, so yes. Mixing two PCM streams (assuming the same sampling rate, bit-depth, and sign) is done simply by generating a new stream, each of whose samples is the mean of the corresponding two samples from the respective source files, i.e. output(sampleNumber)=(stream1(sampleNumber)+stream2(sampleNumber))/2.

Mixing Mono Samples with Stereo Samples

Reply #5
It’s one of the simplest operations that can be performed upon audio streams, so yes. Mixing two PCM streams (assuming the same sampling rate, bit-depth, and sign) is done simply by generating a new stream, each of whose samples is the mean of the corresponding two samples from the respective source files, i.e. output(sampleNumber)=(stream1(sampleNumber)+stream2(sampleNumber))/2.


Ok, but what you describe here is creating a mono stream from stereo, correct? What I need is to mix two stereo streams.

Mixing Mono Samples with Stereo Samples

Reply #6
Don't the stereo streams just contain alternating left and right channel values?

Mixing Mono Samples with Stereo Samples

Reply #7
Ok, but what you describe here is creating a mono stream from stereo, correct? What I need is to mix two stereo streams.

I was referring to your mixing one stream from two, those being your actual stereo stream and the doubled-up stereo version of your mono stream.

pdq has a good point, but the same ‘algorithm’ should work just as well for arrays consisting of alternating left and right samples.

Mixing Mono Samples with Stereo Samples

Reply #8
Ok, but what you describe here is creating a mono stream from stereo, correct? What I need is to mix two stereo streams.

I was referring to your mixing one stream from two, those being your actual stereo stream and the doubled-up stereo version of your mono stream.

pdq has a good point, but the same ‘algorithm’ should work just as well for arrays consisting of alternating left and right samples.

Ok, so is the algo for mixing two stereo arrays into one new one easy enough? Is it similar in complexity to creating a mono from stereo?

Mixing Mono Samples with Stereo Samples

Reply #9
To create mono from stereo you would take pairs of values (left and right), average them, and output a single value. You will need to make sure that the new stream is interpreted as mono or else the sample rate will effectively be halved.

Mixing Mono Samples with Stereo Samples

Reply #10
Could I ask which is your background? I don't want to assume too much (or to little).

Like they said, when having the same sample rate and the same bit depth, Mixing equals to the sum of the values. Doing a division is not a requirement but it might be needed depending on the goal.*

Likewise, changing the number of channels of a signal is also quite straightforward:

Mono to "N" is just using the same stream for the other channels
"N" to mono is mixing the streams into a single one.

Since this can cause changes in the volume, a "channel matrix" is applied.
Channel matrix is just doing a multiplication before doing the addition, in order to change the amplitude of the signal in that channel. In 5.1 to stereo matrixes, generally the different channels reduce their volume in different amounts before being mixed together. (In a matrix, one source channel can go to more than one destination channel, like when converting stereo to 5.1).


Depending on your background you could take a look at http://www.dspguide.com/ . It talks about digital signal processing, and might be helpful for you in the future. (Obviously, if you have just started, most of that will be clueless math and strange words).



* Concretely, if you sum the same signal twice, its peak will double and that could cause clipping. Said that, if one mixes 32 streams, it is not wise to have a division by 32 (this would lower the peak of one stream by 30dB. Think that the mute of some car radios is only 20dBs).

Mixing Mono Samples with Stereo Samples

Reply #11
Mick,

Typically, a stereo mixer (hardware or software) will have (at least) two controls for each input.

There is a level control, so if you are mixing A+B you can mix 30% of A with 70% of B, etc.  The total does not have to add to 100%, because there is also a master level control, and if you are using floating-point there are essentially no limits.  (You'd normally check/adjust the levels to prevent clipping before rendering to an integer format.) 

For mono sources there is also a panning control  (AKA "pan pot").    The pan control determines "where" the sound is located, left-to right, by adjusting how much of this mono signal gets mixed-into the left channel, and how much gets mixed into the right channel.      If you pan to the center (equal amounts in both channels), the level is normally reduced by 3dB, because otherwise the single-track mono volume level is doubled, since it's duplicated in both channels.*

By default, you wouldn't use a pan-pot with stereo inputs, since the left-input normally goes to the left-output, and the right- input goes to the right-output.  But, most mixers do allow you to pan the left & right stereo channels indpendently.  So, you could move both channels to the left, or both to the right, or move them both to the middle, or criss-cross them, etc.

You will notice that pan controls can take care of stereo-to-mono, or mono-to-stereo (of course you don't have true stereo if you have the same  sound in both channels).


*  Not all pan pots follow this rule (there are different "pan laws"), and it's usually not that important, since you always have a level control to adjust the mono signal before mixing & panning.  It does become important if you are moving the sound around during the track...  i.e.  If a speaker/singer starts-out on the left and moves across the "stage" to the right during the track/song.  In that case, you don't want the voice to get louder in the "center".

Mixing Mono Samples with Stereo Samples

Reply #12
Ok thanks for the input. I am a .NET developer and I've got an algorithm that converts stereo stream into mono(for simplicity sake) and evaluates those samples with algo logic. It then creates a new stream(in this case) mono and now I've got to mix the two back together into a new stereo stream.

Mixing Mono Samples with Stereo Samples

Reply #13
Quote
I am a .NET developer and I've got an algorithm that converts stereo stream into mono(for simplicity sake) and evaluates those samples with algo logic. It then creates a new stream(in this case) mono and now I've got to mix the two back together into a new stereo stream.
Good.  That's pretty-much how most audio editing software works.  Each channel from each file/source would be loaded into an array.  Then everything gets mixed/processed and the result goes into new "output" or "result" arrays.  (Some applications might use 2-dimensional or multi-dimensional arrays for stereo/multi-channel data.)

I assume real-time audio processing basically works the same way except with smaller arrays used as circular buffers.