Active Topics

 


Reply
Thread Tools
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#1
I got the following code from here and the latest for Python 3.1.2 says the same thing.

Should the following

Code:
Note that operations such as mul() or max() make no distinction between mono and stereo fragments, i.e. all samples are treated equal. If this is a problem the stereo fragment should be split into two mono fragments first and recombined later. Here is an example of how to do that:

def mul_stereo(sample, width, lfactor, rfactor):
    lsample = audioop.tomono(sample, width, 1, 0)
    rsample = audioop.tomono(sample, width, 0, 1)
    lsample = audioop.mul(sample, width, lfactor)
    rsample = audioop.mul(sample, width, rfactor)
    lsample = audioop.tostereo(lsample, width, 1, 0)
    rsample = audioop.tostereo(rsample, width, 0, 1)
    return audioop.add(lsample, rsample, width)
actually be

Code:
Note that operations such as mul() or max() make no distinction between mono and stereo fragments, i.e. all samples are treated equal. If this is a problem the stereo fragment should be split into two mono fragments first and recombined later. Here is an example of how to do that:

def mul_stereo(sample, width, lfactor, rfactor):
    lsample = audioop.tomono(sample, width, 1, 0)
    rsample = audioop.tomono(sample, width, 0, 1)
    lsample = audioop.mul(lsample, width, lfactor)
    rsample = audioop.mul(rsample, width, rfactor)
    lsample = audioop.tostereo(lsample, width, 1, 0)
    rsample = audioop.tostereo(rsample, width, 0, 1)
    return audioop.add(lsample, rsample, width)
If not, please explain because I just ain't gettin' it. And thanks in advance for the extra eyeballs.
__________________
N9: Go white or go home
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#2
After only a cursory look, I'd say it makes very little sense to do as in the first snippet since lsample and rsample are bound to new values and thus discarding the result from the previous operation.

So, the second one makes the most sense, to me at least.
 

The Following User Says Thank You to Joorin For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 14:21.