Sound, how is it done?
Im working on an interactive piece using an alternate form of the doppler effect and I would appreciate some help in making it play sound. Thank you
import wave
class SoundFile:
def __init__(self, signal,lab=''):
self.file = wave.open('./test' + lab + '.wav', 'wb')
self.signal = signal
self.sr = 44100
def write(self):
self.file.setparams((1, 2, self.sr, 44100*4, 'NONE', 'noncompressed'))
self.file.writeframes(self.signal)
self.file.close()
mypi = float(pi)
from math import sin
var('x')
@interact
def sinsound(f = slider(16,16000,1,5120)):
v = 340.29
html('$y = f*(((v)+ tan(x))/((v)+sin(x))))$')
y = f*((v+tan(x))/(v+sin(x)))
hz1 = y
s2 = [sin(hz1*x*mypi*2) for x in srange(0,4,1/44100.0)]
s2m = max(s2)
s2f = [16384*x/s2m for x in s2]
s2str = ''.join(wave.struct.pack('h',x) for x in s2f)
lab="%1.2f"%float(f)
f = SoundFile(s2str,lab=lab)
f.write()
pnum = 1500+int(500/f)
show(list_plot(s2[0:pnum],plotjoined=True))
html('<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>')
Hi. It is not clear at all what your code shoud do !! The variable **y** seems to be a function of **x** but is used as a float number. The parameter **f** has the same name as the **SoundFile** object... Anyway, as such because you use the function **sin** from **math** I get an error because you can not evaluate it on a symbolic variable.
You may also find the discussion [here](https://groups.google.com/forum/?fromgroups=#!topic/sage-devel/3-Y1RUFkq14) interesting, as well as [this ticket](http://trac.sagemath.org/sage_trac/ticket/7668).