Howdy,
I'm trying to build a stereo tone generator module. It sort of works,
but I'm getting hellacious garbage noise in the left channel.
Here's a greatly simplified version of my code (the function
definition is the same, but I've condensed my main):
def tone6(limit = 2770, length = 17960, granularity = 10, phones = 2,
envelope = 10, attack = None):
switch_amplitude = 1
cur_level = 0
out = []
for l in range(0,length):
if abs(cur_level) >= limit:
if switch_amplitude == 1:
switch_amplitude = -1
elif switch_amplitude == -1:
switch_amplitude = 1
cur_level += switch_amplitude * granularity
out.append([cur_level,cur_level])
print "sa", switch_amplitude
return Numeric.array(out)
pygame.init()
pygame.mixer.init(11025, 16, 1)
channels = []
channels.append(pygame.mixer.Channel(0))
if not channels[0].get_sound():
channels[0].play(pygame.sndarray.make_sound(tone6()))
The array out in the function tone6 outputs values:
array([[ 10, 10],
[ 20, 20],
[ 30, 30],
[ 40, 40],
[ 50, 50],
[ 60, 60],
[ 70, 70],
[ 80, 80],
[ 90, 90],
[100, 100],
...snip...
[350, 350],
[360, 360],
[370, 370],
[380, 380],
[390, 390],
[400, 400],
[410, 410],
[420, 420],
[430, 430]])
Not sure what I'm doing wrong here. Wrong scale of numbers? Wrong
array format? I'm quite stuck at the moment. Someone please educate me.
Thanks a bunch,
--
Andrew Ulysses Baker
"failrate"