tomwalters@22
|
1 #!/usr/bin/env python
|
tomwalters@22
|
2 # encoding: utf-8
|
tomwalters@22
|
3 #
|
tomwalters@22
|
4 # AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@22
|
5 # http://www.acousticscale.org/AIMC
|
tomwalters@22
|
6 #
|
tomwalters@22
|
7 # This program is free software: you can redistribute it and/or modify
|
tomwalters@22
|
8 # it under the terms of the GNU General Public License as published by
|
tomwalters@22
|
9 # the Free Software Foundation, either version 3 of the License, or
|
tomwalters@22
|
10 # (at your option) any later version.
|
tomwalters@22
|
11 #
|
tomwalters@22
|
12 # This program is distributed in the hope that it will be useful,
|
tomwalters@22
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
tomwalters@22
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
tomwalters@22
|
15 # GNU General Public License for more details.
|
tomwalters@22
|
16 #
|
tomwalters@22
|
17 # You should have received a copy of the GNU General Public License
|
tomwalters@22
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
tomwalters@22
|
19 """
|
tomwalters@22
|
20 Profiles_test.py
|
tomwalters@22
|
21
|
tomwalters@22
|
22 Created by Thomas Walters on 2010-02-22.
|
tomwalters@22
|
23 Copyright 2010 Thomas Walters <tom@acousticscale.org>
|
tomwalters@22
|
24 Test the AIM-C model from filterbank to SSI profiles
|
tomwalters@22
|
25 """
|
tomwalters@22
|
26
|
tomwalters@22
|
27 import aimc
|
tomwalters@22
|
28 from scipy.io import wavfile
|
tomwalters@22
|
29 from scipy import io
|
tomwalters@22
|
30 import scipy
|
tomwalters@22
|
31 import pylab
|
tomwalters@22
|
32 from itertools import izip, chain, repeat
|
tomwalters@22
|
33
|
tomwalters@22
|
34 def grouper(n, iterable, padvalue=None):
|
tomwalters@22
|
35 "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
|
tomwalters@22
|
36 return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
|
tomwalters@22
|
37
|
tomwalters@22
|
38 def main():
|
tomwalters@22
|
39 wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/"
|
tomwalters@22
|
40 features_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/work08-jess-original-rec_rubber/features/"
|
tomwalters@22
|
41
|
tomwalters@22
|
42 file_name = "aa/aa161.1p119.4s100.0t+000itd"
|
tomwalters@22
|
43
|
tomwalters@22
|
44 wave_suffix = ".wav"
|
tomwalters@22
|
45 features_suffix = ".mat"
|
tomwalters@22
|
46
|
tomwalters@22
|
47 frame_period_ms = 10;
|
tomwalters@22
|
48
|
tomwalters@22
|
49 wave_filename = wave_path + file_name + wave_suffix
|
tomwalters@22
|
50 features_filename = features_path + file_name + features_suffix
|
tomwalters@22
|
51
|
tomwalters@22
|
52 (sample_rate, input_wave) = wavfile.read(wave_filename)
|
tomwalters@22
|
53 wave_length = input_wave.size
|
tomwalters@22
|
54 buffer_length = int(frame_period_ms * sample_rate / 1000)
|
tomwalters@22
|
55
|
tomwalters@22
|
56 #pylab.plot(input_wave)
|
tomwalters@22
|
57 #pylab.show()
|
tomwalters@22
|
58
|
tomwalters@22
|
59 input_sig = aimc.SignalBank()
|
tomwalters@22
|
60 input_sig.Initialize(1, buffer_length, sample_rate)
|
tomwalters@22
|
61 parameters = aimc.Parameters()
|
tomwalters@22
|
62 parameters.Load("src/Scripts/profile_features.cfg")
|
tomwalters@22
|
63 mod_gt = aimc.ModuleGammatone(parameters)
|
tomwalters@22
|
64 mod_hl = aimc.ModuleHCL(parameters)
|
tomwalters@22
|
65 mod_profile = aimc.ModuleSlice(parameters)
|
tomwalters@22
|
66 mod_scaler = aimc.ModuleScaler(parameters)
|
tomwalters@22
|
67 mod_gt.AddTarget(mod_hl)
|
tomwalters@22
|
68 mod_hl.AddTarget(mod_profile)
|
tomwalters@22
|
69 mod_profile.AddTarget(mod_scaler)
|
tomwalters@22
|
70 mod_gt.Initialize(input_sig)
|
tomwalters@22
|
71
|
tomwalters@22
|
72 correct_count = 0;
|
tomwalters@22
|
73 incorrect_count = 0;
|
tomwalters@22
|
74
|
tomwalters@22
|
75 scaled_wave = []
|
tomwalters@22
|
76 for sample in input_wave:
|
tomwalters@22
|
77 scaled_wave.append(float(sample / float(pow(2,15) - 1)))
|
tomwalters@22
|
78 i = 0
|
tomwalters@22
|
79
|
tomwalters@22
|
80 wave_chunks = grouper(buffer_length, scaled_wave, 0)
|
tomwalters@22
|
81
|
tomwalters@22
|
82 out_frames = []
|
tomwalters@22
|
83 for chunk in wave_chunks:
|
tomwalters@22
|
84 i = 0
|
tomwalters@22
|
85 for sample in chunk:
|
tomwalters@22
|
86 input_sig.set_sample(0, i, float(sample))
|
tomwalters@22
|
87 i += 1
|
tomwalters@22
|
88 mod_gt.Process(input_sig)
|
tomwalters@22
|
89 out_sig = mod_scaler.GetOutputBank()
|
tomwalters@22
|
90
|
tomwalters@22
|
91 channel_count = out_sig.channel_count()
|
tomwalters@22
|
92 out_buffer_length = out_sig.buffer_length()
|
tomwalters@22
|
93 cfs = scipy.zeros((channel_count))
|
tomwalters@22
|
94 out = scipy.zeros((channel_count, out_buffer_length))
|
tomwalters@22
|
95
|
tomwalters@22
|
96 for ch in range(0, channel_count):
|
tomwalters@22
|
97 for i in range(0, out_buffer_length):
|
tomwalters@22
|
98 out[ch, i] = out_sig.sample(ch, i)
|
tomwalters@22
|
99 out_frames.append(out)
|
tomwalters@22
|
100
|
tomwalters@22
|
101 outmat = dict(profile_out=out_frames)
|
tomwalters@22
|
102 io.savemat("src/Scripts/profile_out.mat", outmat)
|
tomwalters@22
|
103
|
tomwalters@22
|
104 pass
|
tomwalters@22
|
105
|
tomwalters@22
|
106
|
tomwalters@22
|
107 if __name__ == '__main__':
|
tomwalters@22
|
108 main()
|