comparison src/Scripts/Multi-slice_test.py @ 32:9122efd2b227

-New AIMCopy main for the SSI features (temporary hack till I get a working module load system) -LocalMax strobe criterion. This is faster and better than the parabola version, which still seems buggy. -Noise generator module. Adds noise to a signal. Uses boost for the random number generator. -New options for the SSI -Slice now respects all its flags (oops!). -MATLAB functions for visualisation -Scripts for generating data to view in MATLAB -Script to download and build HTK - useful for running experiments
author tomwalters
date Thu, 25 Feb 2010 22:02:00 +0000
parents
children c5f5e9569863
comparison
equal deleted inserted replaced
31:fa06bfacf004 32:9122efd2b227
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # AIM-C: A C++ implementation of the Auditory Image Model
5 # http://www.acousticscale.org/AIMC
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 """
20 Profiles_test.py
21
22 Created by Thomas Walters on 2010-02-22.
23 Copyright 2010 Thomas Walters <tom@acousticscale.org>
24 Test the AIM-C model from filterbank to SSI profiles
25 """
26
27 import aimc
28 from scipy.io import wavfile
29 from scipy import io
30 import scipy
31 import pylab
32 from itertools import izip, chain, repeat
33
34 def grouper(n, iterable, padvalue=None):
35 "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
36 return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
37
38 def BankToArray(out_bank):
39 channel_count = out_bank.channel_count()
40 out_buffer_length = out_bank.buffer_length()
41 out = scipy.zeros((channel_count, out_buffer_length))
42 for ch in range(0, channel_count):
43 for i in range(0, out_buffer_length):
44 out[ch, i] = out_bank.sample(ch, i)
45 return out
46
47 def StrobesToList(bank):
48 channel_count = bank.channel_count()
49 strobes = []
50 for ch in range(0, channel_count):
51 s = []
52 for i in range(0, bank.strobe_count(ch)):
53 s.append(bank.strobe(ch, i))
54 strobes.append(s)
55
56 def main():
57 wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/"
58 #features_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/work08-jess-original-rec_rubber/features/"
59
60 file_name = "ii/ii172.5p112.5s100.0t+000itd"
61
62 wave_suffix = ".wav"
63 features_suffix = ".mat"
64
65 frame_period_ms = 10;
66
67 wave_filename = wave_path + file_name + wave_suffix
68 #features_filename = features_path + file_name + features_suffix
69
70 (sample_rate, input_wave) = wavfile.read(wave_filename)
71 wave_length = input_wave.size
72 buffer_length = int(frame_period_ms * sample_rate / 1000)
73
74 #pylab.plot(input_wave)
75 #pylab.show()
76
77 input_sig = aimc.SignalBank()
78 input_sig.Initialize(1, buffer_length, sample_rate)
79 parameters = aimc.Parameters()
80 parameters.SetFloat("sai.frame_period_ms", 10.0)
81 parameters.SetInt("input.buffersize", 480)
82
83 mod_gt = aimc.ModuleGammatone(parameters)
84 mod_hl = aimc.ModuleHCL(parameters)
85 mod_strobes = aimc.ModuleLocalMax(parameters)
86 mod_sai = aimc.ModuleSAI(parameters)
87 parameters.SetBool("ssi.pitch_cutoff", True)
88 parameters.SetBool("ssi.weight_by_cutoff", False)
89 parameters.SetBool("ssi.weight_by_scaling", True)
90 parameters.SetBool("ssi.log_cycles_axis", True)
91 mod_ssi = aimc.ModuleSSI(parameters)
92
93 parameters.SetFloat("nap.lowpass_cutoff", 100.0)
94 mod_nap_smooth = aimc.ModuleHCL(parameters)
95 mod_scaler = aimc.ModuleScaler(parameters)
96
97 parameters.SetBool("slice.all", False)
98 parameters.SetInt("slice.lower_index", 77)
99 parameters.SetInt("slice.upper_index", 150)
100 slice_1 = aimc.ModuleSlice(parameters)
101
102 parameters.SetInt("slice.lower_index", 210)
103 parameters.SetInt("slice.upper_index", 240)
104 slice_2 = aimc.ModuleSlice(parameters)
105
106 parameters.SetInt("slice.lower_index", 280)
107 parameters.SetInt("slice.upper_index", 304)
108 slice_3 = aimc.ModuleSlice(parameters)
109
110 parameters.SetInt("slice.lower_index", 328)
111 parameters.SetInt("slice.upper_index", 352)
112 slice_4 = aimc.ModuleSlice(parameters)
113
114 parameters.SetBool("slice.all", True)
115 slice_5 = aimc.ModuleSlice(parameters)
116
117 nap_profile = aimc.ModuleSlice(parameters)
118
119 features_1 = aimc.ModuleGaussians(parameters)
120 features_2 = aimc.ModuleGaussians(parameters)
121 features_3 = aimc.ModuleGaussians(parameters)
122 features_4 = aimc.ModuleGaussians(parameters)
123 features_5 = aimc.ModuleGaussians(parameters)
124
125 mod_gt.AddTarget(mod_hl)
126 mod_gt.AddTarget(mod_nap_smooth)
127 mod_nap_smooth.AddTarget(nap_profile)
128 nap_profile.AddTarget(mod_scaler)
129 mod_hl.AddTarget(mod_strobes)
130 mod_strobes.AddTarget(mod_sai)
131 mod_sai.AddTarget(mod_ssi)
132 mod_ssi.AddTarget(slice_1)
133 mod_ssi.AddTarget(slice_2)
134 mod_ssi.AddTarget(slice_3)
135 mod_ssi.AddTarget(slice_4)
136 mod_ssi.AddTarget(slice_5)
137
138 slice_1.AddTarget(features_1)
139 slice_2.AddTarget(features_2)
140 slice_3.AddTarget(features_3)
141 slice_4.AddTarget(features_4)
142 slice_5.AddTarget(features_5)
143
144 mod_gt.Initialize(input_sig)
145
146 correct_count = 0;
147 incorrect_count = 0;
148
149 scaled_wave = []
150 for sample in input_wave:
151 scaled_wave.append(float(sample / float(pow(2,15) - 1)))
152 i = 0
153
154 wave_chunks = grouper(buffer_length, scaled_wave, 0)
155
156 out_bmm = []
157 out_nap = []
158 out_smooth_nap_profile = []
159 out_strobes = []
160 out_sais = []
161 out_ssis = []
162 out_slice_1 = []
163 out_slice_2 = []
164 out_slice_3 = []
165 out_slice_4 = []
166 out_slice_5 = []
167 out_feat_1 = []
168 out_feat_2 = []
169 out_feat_3 = []
170 out_feat_4 = []
171 out_feat_5 = []
172 for chunk in wave_chunks:
173 i = 0
174 for sample in chunk:
175 input_sig.set_sample(0, i, float(sample))
176 i += 1
177 mod_gt.Process(input_sig)
178
179 #out_bmm.append(BankToArray(mod_gt.GetOutputBank()))
180 #out_nap.append(BankToArray(mod_hl.GetOutputBank()))
181 out_smooth_nap_profile.append(BankToArray(mod_scaler.GetOutputBank()))
182 #out_strobes.append(BankToArray(mod_strobes.GetOutputBank()))
183 #out_sais.append(BankToArray(mod_sai.GetOutputBank()))
184 out_ssis.append(BankToArray(mod_ssi.GetOutputBank()))
185 out_slice_1.append(BankToArray(slice_1.GetOutputBank()))
186 out_slice_2.append(BankToArray(slice_2.GetOutputBank()))
187 out_slice_3.append(BankToArray(slice_3.GetOutputBank()))
188 out_slice_4.append(BankToArray(slice_4.GetOutputBank()))
189 out_slice_5.append(BankToArray(slice_5.GetOutputBank()))
190 out_feat_1.append(BankToArray(features_1.GetOutputBank()))
191 out_feat_2.append(BankToArray(features_2.GetOutputBank()))
192 out_feat_3.append(BankToArray(features_3.GetOutputBank()))
193 out_feat_4.append(BankToArray(features_4.GetOutputBank()))
194 out_feat_5.append(BankToArray(features_5.GetOutputBank()))
195
196 out_bank = mod_gt.GetOutputBank()
197 channel_count = out_bank.channel_count()
198 cfs = scipy.zeros((channel_count))
199 for ch in range(0, channel_count):
200 cfs[ch] = out_bank.centre_frequency(ch)
201 outmat = dict(bmm=out_bmm, nap=out_nap, sais=out_sais,
202 ssis=out_ssis, slice1=out_slice_1, slice2=out_slice_2,
203 slice3=out_slice_3, slice4=out_slice_4, slice5=out_slice_5,
204 feat1=out_feat_1, feat2=out_feat_2, feat3=out_feat_3,
205 feat4=out_feat_4, feat5=out_feat_5,
206 nap_smooth=out_smooth_nap_profile, centre_freqs=cfs)
207 io.savemat("src/Scripts/profile_out.mat", outmat, oned_as='column')
208
209 pass
210
211
212 if __name__ == '__main__':
213 main()