Re: [linux-audio-dev] scaling audio signal

From: Tim Goetze <tim@email-addr-hidden>
Date: Sat Mar 03 2007 - 23:37:26 EET

[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
Received on Sun Mar 4 00:15:03 2007

This archive was generated by hypermail 2.1.8 : Sun Mar 04 2007 - 00:15:03 EET