Sine wave?
Anton Vredegoor
anton at vredegoor.doge.nl
Mon Dec 23 07:03:55 EST 2002
On Mon, 23 Dec 2002 00:09:52 -0500, Andrew Henshaw
<andrew.henshaw at gtri.gatech.edu> wrote:
>The original poster might also be interested in the following version (based
>upon Bengt's code) that uses the Numeric module for speed and code economy.
Yes, but the OP should not look at such code before having done it "by
hand" first!
Regards,
Anton.
Now for the adventurous ...
There are lots of interesting things one can do with numeric (and it's
successor numarray) when it comes to sound and vision. However, it
gets complex fast.
One example (probably fragile code):
from numarray import *
from FFT2 import *
import wave
def test():
n = 88200
m = n / 44100.0
freqs = [110,220,440,880,1760]
y = [0.0 for i in range((n+2)/2)]
for f in freqs:
y[int(f*m)] = 1.0
vol = (m*22050.0/sum(y))* 30000.0
y = (inverse_real_fft(y) * vol).astype(Int16)
ww = wave.open('sound.wav','w')
ww.setparams((1,2,44100,0,'NONE','RIFF'))
ww.writeframes(y.tostring())
ww.close()
if __name__=='__main__':
test()
More information about the Python-list
mailing list