Hi People,
On trying to deal with wave files in python, I came across this article:
http://209.85.165.104/search?q=cache:vMIuboZw0BwJ:scipy.mit.edu/tutorials/w…
the original pdf
http://scipy.mit.edu/tutorials/wave.pdf is not available...
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 )
#and then they pack the code, conv_code is 'B' for 8 bit, 'h' for 16
bit, 'i' for 32 bit:
f.writeframes( struct.pack( conv_code, signal[i] ) )
Ok. This struct thing I don´t fully understand, but I already know it
has to do with C data strings.
But the previous part simply doesn´t make sense, and I can´t find any
reference to this things on the web.
I would really appreciate if anyone could explain me what is happening
and/or point me some writings about that.
One disturbuing thing about using this script is that sometimes it
outputs a wave file with start and end out of center (zero amplitude),
even when the singal list had fadings. It seems that it has to do with
signals that goes beyond the [-1,1] closed interval, but I don´t know
why.
thanks guys,
Claire