IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Mixing Mono Samples with Stereo Samples, Audio DSP using C#
AltAudio
post Apr 19 2012, 06:18
Post #1





Group: Members
Posts: 5
Joined: 19-April 12
Member No.: 98974



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
Go to the top of the page
+Quote Post
pdq
post Apr 19 2012, 12:49
Post #2





Group: Members
Posts: 3391
Joined: 1-September 05
From: SE Pennsylvania
Member No.: 24233



How about converting the mono to stereo (two identical tracks) and then mixing normally?
Go to the top of the page
+Quote Post
Speedskater
post Apr 19 2012, 13:40
Post #3





Group: Members
Posts: 138
Joined: 12-December 07
From: Cleveland, OH
Member No.: 49500



Is this anything like M-S Stereo System? That's Main & Sides or Mid & Sides or Middle & Sides or the earlier Mitte-Seite.


--------------------
Kevin
Go to the top of the page
+Quote Post
AltAudio
post Apr 19 2012, 15:32
Post #4





Group: Members
Posts: 5
Joined: 19-April 12
Member No.: 98974



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?
Go to the top of the page
+Quote Post
db1989
post Apr 19 2012, 16:08
Post #5





Group: Super Moderator
Posts: 5275
Joined: 23-June 06
Member No.: 32180



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.

This post has been edited by db1989: Apr 19 2012, 16:20
Go to the top of the page
+Quote Post
AltAudio
post Apr 19 2012, 16:41
Post #6





Group: Members
Posts: 5
Joined: 19-April 12
Member No.: 98974



QUOTE (db1989 @ Apr 19 2012, 10:08) *
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.
Go to the top of the page
+Quote Post
pdq
post Apr 19 2012, 17:25
Post #7





Group: Members
Posts: 3391
Joined: 1-September 05
From: SE Pennsylvania
Member No.: 24233



Don't the stereo streams just contain alternating left and right channel values?
Go to the top of the page
+Quote Post
db1989
post Apr 19 2012, 17:35
Post #8





Group: Super Moderator
Posts: 5275
Joined: 23-June 06
Member No.: 32180



QUOTE (AltAudio @ Apr 19 2012, 16:41) *
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.
Go to the top of the page
+Quote Post
AltAudio
post Apr 19 2012, 18:11
Post #9





Group: Members
Posts: 5
Joined: 19-April 12
Member No.: 98974



QUOTE (db1989 @ Apr 19 2012, 11:35) *
QUOTE (AltAudio @ Apr 19 2012, 16:41) *
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?
Go to the top of the page
+Quote Post
pdq
post Apr 19 2012, 18:27
Post #10





Group: Members
Posts: 3391
Joined: 1-September 05
From: SE Pennsylvania
Member No.: 24233



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.
Go to the top of the page
+Quote Post
[JAZ]
post Apr 19 2012, 19:26
Post #11





Group: Members
Posts: 1772
Joined: 24-June 02
From: Catalunya(Spain)
Member No.: 2383



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).

This post has been edited by [JAZ]: Apr 19 2012, 19:28
Go to the top of the page
+Quote Post
DVDdoug
post Apr 19 2012, 19:43
Post #12





Group: Members
Posts: 2565
Joined: 24-August 07
From: Silicon Valley
Member No.: 46454



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".
Go to the top of the page
+Quote Post
AltAudio
post Apr 19 2012, 22:00
Post #13





Group: Members
Posts: 5
Joined: 19-April 12
Member No.: 98974



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.
Go to the top of the page
+Quote Post
DVDdoug
post Apr 20 2012, 00:34
Post #14





Group: Members
Posts: 2565
Joined: 24-August 07
From: Silicon Valley
Member No.: 46454



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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd August 2014 - 19:12