Log in

View Full Version : Mixaudio() negative clip values


MaroonMike
16th May 2008, 20:18
What do negative clip factors in MixAudio() represent?

I do not understand negative volume??? Plz help. :confused:

IanB
16th May 2008, 22:44
It's all in the arithmetic.double track1_factor = args[2].AsFloat(0.5);
double track2_factor = args[3].AsFloat(1.0 - track1_factor);
...
for (unsigned i = 0; i < unsigned(count)*channels; ++i) {
samples[i] = (samples[i] * t1factor) + (clip_samples[i] * t2factor);
}Note! The default track2_factor is 1.0-track1_factor, so if track1_factor=-0.5 then track2_factor=1.0-(-0.5)=1.5 which may cause saturation. When using negative values specify both volumes levels explicitly.

Negative volumes just cause a 180 degree phase inversion. So to generate a (Left-Right) difference audio channel...
MixAudio(GetLeftChannel(), GetRightChannel(), 0.5, -0.5)

MaroonMike
17th May 2008, 03:01
Ahh....got it. Thanks for the quick reply!

:thanks:

Comatose
17th May 2008, 06:37
Wait, what? Since you said inversion, I assumed you meant it creates the inverse sound to the clip, kinda like Invert()ing colors... but then you said difference. What? D:
Can you please explain it in layman's terms?

Leak
17th May 2008, 10:13
Wait, what? Since you said inversion, I assumed you meant it creates the inverse sound to the clip, kinda like Invert()ing colors... but then you said difference. What? D:
Can you please explain it in layman's terms?
16 bit samples are integer values between -32768 and +32767. The factor is applied simply by multiplying it with all sample values.

So if you have a factor of -1 the waveform is simply mirrored along the time axis, since the sign of each sample value is inverted.

I.e.
+32767
^
|--
| |
+--+--+-> t
| | |
| --
v
-32768
becomes
+32767
^
| --
| | |
+--+--+-> t
| |
|--
v
-32768

np: Aesop Rock - Garbage (Float)

tebasuna51
17th May 2008, 13:55
Example:
We have an ac3 3/1 (Left,Right,Center,Surround) file and want a stereo Dolby ProLogic downmix.
The (simplified) mathematical formula is:

l' = 0.4xL + 0.3xC + 0.3xS
r' = 0.4xR + 0.3xC - 0.3xS

Then the DPL decoder send the common signal in l',r' to Center channel and the common, but inverted (phase 180º), signal to Surround channel.

The AviSynth implementation can be:

a = NicAc3Source("G:\Test\3-1_file.ac3")
l = GetChannel(a, 1)
r = GetChannel(a, 2)
c = GetChannel(a, 3)
s = GetChannel(a, 4)
newl = MixAudio(l, c, 0.4, 0.3)
newl = MixAudio(newl, s, 1, 0.3)
newr = MixAudio(r, c, 0.4, 0.3)
newr = MixAudio(newr, s, 1, -0.3)
MergeChannels(newl, newr)