projects
/
naja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
343dbba
)
Make gen_sound work under python3
author
Neil
<neil@dip.sun.ac.za>
Fri, 16 May 2014 09:25:15 +0000
(11:25 +0200)
committer
Neil
<neil@dip.sun.ac.za>
Fri, 16 May 2014 09:32:31 +0000
(11:32 +0200)
tools/gen_sound.py
patch
|
blob
|
history
diff --git
a/tools/gen_sound.py
b/tools/gen_sound.py
index 6e524e850f05fa1660126dbd161f2ace1bb62b4d..db37d8267325d187ed9ffdfce8ec5c861e8be35a 100644
(file)
--- a/
tools/gen_sound.py
+++ b/
tools/gen_sound.py
@@
-17,26
+17,26
@@
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
- per_cycle = OUTPUT_RATE / freq
+ 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)
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')
+ output = open(filename, 'w
b
')
# 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)):
# 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.write(
b
''.join(data))
output.close()
output.close()
- print
'Wrote output to %s' % filename
+ print
('Wrote output to %s' % filename)
def usage():
def usage():
- print
'Unexpected input'
- 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
('Unexpected input')
+ 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)
@@
-52,19
+52,19
@@
if __name__ == "__main__":
volume = int(sys.argv[3])
else:
volume = DEFAULT_VOL
volume = int(sys.argv[3])
else:
volume = DEFAULT_VOL
- except Exception
,
exc:
+ except Exception
as
exc:
usage()
usage()
- print
'Error was', exc
+ print
('Error was: %s' % exc)
sys.exit(1)
if volume > 128 or volume < 0:
usage()
sys.exit(1)
if volume > 128 or volume < 0:
usage()
- print
'Invalid volume: %s' % volume
+ print
('Invalid volume: %s' % volume)
sys.exit(1)
if freq > 2000 or freq < 100:
usage()
sys.exit(1)
if freq > 2000 or freq < 100:
usage()
- print
'Invalid freq: %s' % volume
+ print
('Invalid freq: %s' % volume)
sys.exit(1)
gen_sine(freq, secs, volume)
sys.exit(1)
gen_sine(freq, secs, volume)