-def gen_sine(freq, secs, volume):
- filename = 'beep%s.pcm' % freq
- # We generate freq cycles and sample that OUTPUT_RATE times
- per_cycle = OUTPUT_RATE / freq
- data = []
- for x in range(per_cycle):
- rad = float(x) / per_cycle * 2 * math.pi
- y = 256 * int(volume * math.sin(rad))
- data.extend([struct.pack('<i', y)] * 4)
- output = open(filename, 'w')
- # This is correct because OUTPUT_RATE = CDDA rate / 4 and we repeat
- # the samples 4 times, so this works out to CDDA rate
- for x in range(int(freq * secs)):
- output.write(''.join(data))
- output.close()
- print 'Wrote output to %s' % filename