projects
/
naja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
885d6dc
)
pep8 cleanups
author
Neil
<neil@dip.sun.ac.za>
Thu, 15 May 2014 19:43:45 +0000
(21:43 +0200)
committer
Neil
<neil@dip.sun.ac.za>
Thu, 15 May 2014 20:10:12 +0000
(22:10 +0200)
tools/gen_sound.py
patch
|
blob
|
history
diff --git
a/tools/gen_sound.py
b/tools/gen_sound.py
index be544283d657687a460063feb78d22945ada0817..6e524e850f05fa1660126dbd161f2ace1bb62b4d 100644
(file)
--- a/
tools/gen_sound.py
+++ b/
tools/gen_sound.py
@@
-1,5
+1,5
@@
# Generate imperfect sine waves
# Generate imperfect sine waves
-#
+#
# Design notes. Produces ~= (user requested) s of raw audio
# We're aiming for an 8-bit'ish effect, so we're going with
# 8125 Hz, 8 bit sampling, but faking it out to
# Design notes. Produces ~= (user requested) s of raw audio
# We're aiming for an 8-bit'ish effect, so we're going with
# 8125 Hz, 8 bit sampling, but faking it out to
@@
-13,6
+13,7
@@
import struct
OUTPUT_RATE = 8125
DEFAULT_VOL = 95
OUTPUT_RATE = 8125
DEFAULT_VOL = 95
+
def gen_sine(freq, secs, volume):
filename = 'beep%s.pcm' % freq
# We generate freq cycles and sample that OUTPUT_RATE times
def gen_sine(freq, secs, volume):
filename = 'beep%s.pcm' % freq
# We generate freq cycles and sample that OUTPUT_RATE times
@@
-36,24
+37,25
@@
def usage():
print 'Usage gen_sound <freq> [<length>] [<volume>]'
print ' where <freq> is the frequency in Hz (int)'
print ' [<length>] is the time in seconds (float) - default 0.25'
print 'Usage gen_sound <freq> [<length>] [<volume>]'
print ' where <freq> is the frequency in Hz (int)'
print ' [<length>] is the time in seconds (float) - default 0.25'
- print ' and [<volume>] is the volume (integer between 0 and 127) - default %s' % DEFAULT_VOL
+ print (' and [<volume>] is the volume (integer between 0 and 127)'
+ ' - default %s' % DEFAULT_VOL)
if __name__ == "__main__":
try:
if __name__ == "__main__":
try:
- freq = int(sys.argv[1])
- if len(sys.argv) > 2:
- secs = float(sys.argv[2])
- else:
- secs = 0.25
- if len(sys.argv) > 3:
- volume = int(sys.argv[3])
- else:
- volume = DEFAULT_VOL
+
freq = int(sys.argv[1])
+
if len(sys.argv) > 2:
+
secs = float(sys.argv[2])
+
else:
+
secs = 0.25
+
if len(sys.argv) > 3:
+
volume = int(sys.argv[3])
+
else:
+
volume = DEFAULT_VOL
except Exception, exc:
except Exception, exc:
- usage()
- print 'Error was', exc
- sys.exit(1)
+
usage()
+
print 'Error was', exc
+
sys.exit(1)
if volume > 128 or volume < 0:
usage()
if volume > 128 or volume < 0:
usage()
@@
-65,6
+67,4
@@
if __name__ == "__main__":
print 'Invalid freq: %s' % volume
sys.exit(1)
print 'Invalid freq: %s' % volume
sys.exit(1)
-
gen_sine(freq, secs, volume)
gen_sine(freq, secs, volume)
-