# HG changeset patch # User Neil Muller # Date 1282908152 -7200 # Node ID f87a3485d927c9a58497425ee75edca0d6bb2ef5 # Parent cc478e3a951e4490603cddf6267bff6520563c46 Add tool for making beeps diff -r cc478e3a951e -r f87a3485d927 tools/gen_sound.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/gen_sound.py Fri Aug 27 13:22:32 2010 +0200 @@ -0,0 +1,33 @@ +# Generate 'perfect' sine wave sounds + +# Design notes: produces ~= 0.5s raw CDDA audio - 44100 Hz, 16 bit signed values +# Input is freq in Hz - 440 for A, etc. - must be an integer +# Output is written the file beep.pcm +# Convert to ogg with oggenc -r + +import sys +import math +import struct + + +CDDA_RATE = 44100 +MAX = 105*256 # Max value for sine wave + +def gen_sine(freq): + filename = 'beep%s.pcm' % freq + # We need to generate freq cycles and sample that CDDA_RATE times + samples_per_cycle = CDDA_RATE / freq + data = [] + for x in range(samples_per_cycle): + rad = float(x) / samples_per_cycle * 2 * math.pi + y = MAX * math.sin(rad) + data.append(struct.pack('