-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, 'wb')
- # 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(b''.join(data))
- output.close()
- print ('Wrote output to %s' % filename)
+def encode(filename, data):
+ print "Writing %s" % filename
+ p = Popen(('oggenc', '-o', filename, '--raw', '--raw-chan=1',
+ '--quiet', '-'),
+ stdin=PIPE, cwd='data/sounds')
+ for blob in data:
+ p.stdin.write(blob)
+ p.stdin.close()
+ assert p.wait() == 0