[Silver Rock]
The signal scaling is just beyond my understandings,
and I can´t find
any explanation on the web about it. What is the role of that in the
programm? Anyway, I will write here what it does to the audio signal
that I don´t understand. By catching code lines in functions it looks
like this:
''''
mono signal, a list, say a 200Hz sinusoid with 2 seconds):
signal=[math.sin(2*math.pi*200*(x/44100.0)) for x in range(88200)]
'''
tmp = list( signal )
min_tmp = min(tmp)
max_tmp = max(tmp)
scalar = (2**16 - 1.0) / (1.0 * (max_tmp - min_tmp)) * volume #for 16
bit, it could be 8 or 32
tmp = map( lambda x: int(scalar*(x-min_tmp)), tmp)
signal = tmp
if samp_width != 1:
signal = map( lambda x: x - 2**(samp_width*8 - 1), signal )
The code determines the max and min sample values of the signal. It
then scales and translates the signal to completely cover the interval
between the minimum and maximum sample values (i.e. -1 to +1 in a
normalized range). The translation part introduces the DC offset which
you perceive as a shift of the previous 0 value (the 'x axis'). A DC
offset is not what you usually want in your audio signals.
I'm not overly impressed with this snippet. If you're meaning to learn
DSP off the net,
dspguide.com for example is a much better starting
point. And there's better Python out there, too.
Cheers, Tim