Synth.cpp
 All Data Structures Namespaces Files Functions Variables Macros
test.py
Go to the documentation of this file.
1 import math
2 import os
3 import sys
4 
5 # Set __ARM = 0 so later it will be possible to disable assembly language.
6 CMD = ("g++ -Wall -g -D__ARM=0 -Iteensy -o foo test.cpp teensy/synth.cpp teensy/tune.cpp teensy/tests.cpp")
7 assert os.system(CMD) == 0, CMD
8 
9 just_tests = False
10 if 'valgrind' in sys.argv[1:]:
11  CMD = "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes ./foo"
12 elif 'tests' in sys.argv[1:]:
13  CMD = "./foo -t"
14  just_tests = True
15 else:
16  CMD = "./foo"
17 assert os.system(CMD) == 0, CMD
18 if just_tests:
19  sys.exit(0)
20 
21 if 'gnuplot' in sys.argv[1:]:
22  os.system("echo \"set term png; set output 'output.png';"
23  " plot 'foo.gp' using 1:2 with lines\" | gnuplot")
24  sys.exit(0)
25 
26 import aifc
27 fname = "quux.aiff"
28 
29 if sys.platform == "darwin":
30  player = "afplay"
31 else:
32  assert sys.platform == "linux2"
33  player = "play" # apt-get install sox
34 
35 def f(x):
36  xhi = (x >> 8) & 0xff
37  xlo = x & 0xff
38  return chr(xhi) + chr(xlo)
39 
40 import foo
41 S = foo.samples
42 
43 try:
44  os.unlink(fname)
45 except:
46  pass
47 
48 q = aifc.open(fname, "wb")
49 q.setnchannels(1)
50 q.setsampwidth(2)
51 q.setframerate(foo.sampfreq)
52 q.setnframes(len(S))
53 
54 q.writeframes("".join(map(f, S)))
55 q.close()
56 
57 os.system(player + " " + fname)
def f
Definition: test.py:35