mardi 27 janvier 2015

Generating tremolo sine wave

I'm trying to create a tremolo by oscillating between two 430Hz and 450Hz, storing the 16-bit sample in the list wav. However, the audible frequency seems to increase range of oscillation across the entire clip. Does anyone know why?



# wavtools.py

defaults = {
'nchannels': 1,
'sampwidth': 2,
'framerate': 44100,
'comptype' : 'NONE',
'compname' : None,
}

def sinegen(f, a):
"""
generator for a sin wav
f: the frequency of the sin wave
a: the amplitude of the sin wave
"""
(i, n) = (0, defaults['framerate'] / f)
while True:
yield a * math.sin(2 * math.pi * i / n)
i += 1



# tremolo.py

maxamp = 2**15 - 1
foscillator = wavtools.sinegen(1, 10)
nframes = 6 * wavtools.defaults['framerate']

wav = []
for t in range(nframes):
f = (440 + next(foscillator)) / wavtools.defaults['framerate']
w = 2 * math.pi * f
x = w * t
y = maxamp * math.sin(x)
wav.append(y)

Aucun commentaire:

Enregistrer un commentaire