-
Notifications
You must be signed in to change notification settings - Fork 14
/
makehsdata.py
110 lines (86 loc) · 4.5 KB
/
makehsdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python
# makehs.py (hsdata.py generator)
# Bryan Smart 5/15/2012
# This script is a quick and dirty hack to convert the library of
# HRTF impulse responses from individual WAV files in to a Python
# script so that they can be quickly loaded w/o taking the
# performance hit from accessing lots of small files.
import glob
import time
import pyo
class HeadSpaceHelper:
def __init__(self):
self.KEMARDATA = "data/"
self.elev = ["-40", "-30", "-20", "-10", "0", "10", "20", "30", "40", "50", "60", "70", "80", "90"]
# This is really the "least worst" way of doing it... load all filenames into a matrix
self.elevData_l = [ glob.glob(self.KEMARDATA+"elev-40/left/*.wav"),
glob.glob(self.KEMARDATA+"elev-30/left/*.wav"),
glob.glob(self.KEMARDATA+"elev-20/left/*.wav"),
glob.glob(self.KEMARDATA+"elev-10/left/*.wav"),
glob.glob(self.KEMARDATA+"elev0/left/*.wav"),
glob.glob(self.KEMARDATA+"elev10/left/*.wav"),
glob.glob(self.KEMARDATA+"elev20/left/*.wav"),
glob.glob(self.KEMARDATA+"elev30/left/*.wav"),
glob.glob(self.KEMARDATA+"elev40/left/*.wav"),
glob.glob(self.KEMARDATA+"elev50/left/*.wav"),
glob.glob(self.KEMARDATA+"elev60/left/*.wav"),
glob.glob(self.KEMARDATA+"elev70/left/*.wav"),
glob.glob(self.KEMARDATA+"elev80/left/*.wav"),
glob.glob(self.KEMARDATA+"elev90/left/*.wav") ]
self.elevData_r = [ glob.glob(self.KEMARDATA+"elev-40/right/*.wav"),
glob.glob(self.KEMARDATA+"elev-30/right/*.wav"),
glob.glob(self.KEMARDATA+"elev-20/right/*.wav"),
glob.glob(self.KEMARDATA+"elev-10/right/*.wav"),
glob.glob(self.KEMARDATA+"elev0/right/*.wav"),
glob.glob(self.KEMARDATA+"elev10/right/*.wav"),
glob.glob(self.KEMARDATA+"elev20/right/*.wav"),
glob.glob(self.KEMARDATA+"elev30/right/*.wav"),
glob.glob(self.KEMARDATA+"elev40/right/*.wav"),
glob.glob(self.KEMARDATA+"elev50/right/*.wav"),
glob.glob(self.KEMARDATA+"elev60/right/*.wav"),
glob.glob(self.KEMARDATA+"elev70/right/*.wav"),
glob.glob(self.KEMARDATA+"elev80/right/*.wav"),
glob.glob(self.KEMARDATA+"elev90/right/*.wav") ]
### Init lists of SndTable objects ###
self.elevData_l_tables = []
self.elevData_r_tables = []
# As good as GLOB is, it doesn't sort the data...
for items in self.elevData_l:
self.elevData_l_tables.append([])
items.sort()
for item in items:
self.elevData_l_tables[-1].append(pyo.SndTable(item))
for items in self.elevData_r:
self.elevData_r_tables.append([])
items.sort()
for item in items:
self.elevData_r_tables[-1].append(pyo.SndTable(item))
# Startup
s = pyo.Server().boot()
s.start()
print "Loading tables..."
h = HeadSpaceHelper()
print "Writing hsdata.py..."
f = open("hsdata.py", "w")
f.write("# HRTF impulse responses for HeadSpace, an HRTF effect for Pyo.\n")
f.write("# This file was automatically generated on " + time.asctime() + "\n\n")
f.write("from pyo import *\n\n")
f.write("class ImpulseResponseTables:\n\n")
f.write("\tdef getTables(self):\n")
f.write("\t\tIR_TABLE_LEFT = []\n\n")
for elevation in h.elevData_l_tables:
f.write ("\t\tIR_TABLE_LEFT.append([])\n\n")
for azimuth in elevation:
f.write("\t\tIR_TABLE_LEFT[len(IR_TABLE_LEFT)-1].append(DataTable(128, init=")
f.write(str(azimuth[0].getTable()))
f.write("))\n\n")
f.write("\t\tIR_TABLE_RIGHT = []\n\n")
for elevation in h.elevData_r_tables:
f.write ("\t\tIR_TABLE_RIGHT.append([])\n\n")
for azimuth in elevation:
f.write("\t\tIR_TABLE_RIGHT[len(IR_TABLE_RIGHT)-1].append(DataTable(128, init=")
f.write(str(azimuth[0].getTable()))
f.write("))\n\n")
f.write("\t\treturn IR_TABLE_LEFT, IR_TABLE_RIGHT\n\n")
f.close()
print "Done."