Briefly explained:
The routine below is the core math that you would use to surround encode
from 5 seperate sound channels/samples to 2 channel stereo.
For more info check http://en.wikipedia.org/wiki/Dolby_Pro_Logic and related articles.
BeSweet and a lot of other tools use similar routines.
http://forum.doom9.org/showthread.php?s=&threadid=27936
Code: Select all
;http://en.wikipedia.org/wiki/Dolby_Pro_Logic
;http://forum.doom9.org/showthread.php?s=&threadid=27936
;surround matrix encoder
;compatible with Dolby Surround/Dolby Pro Logic, Dolby Pro Logic II
;SRS, dts:Neo, Circle Surround, Circle Surround II, Sensaura, and so on.
;convert the sample points to float or doubles (or just float but do math as doubles)
;1.0 is max positive sample point
;-1.0 is max negative sample point
;0.0 is silence (infinity)
;to convert 16bit where max/min sample points are 32767 to -32768
;for positive numbers do l.f=32767/32767
;and for negatives numbers do l.f=-32768/-32768
;To convert back from float to 16bit
;for positives nunbers do left.w=dlt*32767
;and for negatives numbersdo left.w=dlt*-32768
;If you plan to further process the audio,
;it might be wise to store it on disk as float instead.
;32bit float samples with a range of 1.0 to -1.0 is known as normalized float
;(Wave float type 3 stores it same wey if I remember correctly).
;Some software may even support wavs or raw pcm with 64bit/doubles.
;dl is left
;dr is right
;dc is center
;dsl is left surround
;dsr is right surround
;dlt is left total (the result)
;drt is right total (the result)
Define.d dl,dr,dc,dsl,dsr,dlt,drt
;EmSai Surround, (C) EmSai, Roger Hågensen 2006
dl.d=1.0
dr.d=1.0
dc.d=1.0
dsl.d=1.0
dsr.d=1.0
dlt=((-dsl)+(-0.70710678118654757*(dsr*0.5))+dl+(dc*0.5))*0.35044026276028173
drt=((dsr)+(0.70710678118654757*(dsl*0.5))+dr+(dc*0.5))*0.35044026276028173
Debug dlt
Debug drt
Note! The coefficients used are derived from myself,
Dolby nor any of the other surround technology companies has released the exact info needed to replicate their tech.
If you use the above math I'd prefer to be credited somewhere,
other than that consider the code to be free for any use, including commercial.
Also, my math result in a much louder result,
that is, if all the 5 inputs are at maximum (1.0) then the output will also be
the same, so there should be no need to correct the volume before or after, it is part of the routine itself.
Other routines tend to end up with a lower level,
my philosphy is that if all the input it cranked to the max, so should the output be.
PS! one of the channels will seem to be limping if the surround input channels has sound in them, this is intentional. And caused by the phase.
Note! if the input values is above 1.0 then the output might also end up above 1.0
So make sure that the input is in the valid -1.0 to 1.0 range.
For more speed you could use single precision floats rather than doubles,
obviously the precision will be lower, but still good though.
The math will not need to be changed wether you use singles or doubles.