Mercurial > hg > aimc
comparison trunk/src/Scripts/Features_test.py @ 294:921575ec87a3
- Added scripts directory with a few basic scripts for testing modules and interfacting with matlab
author | tomwalters |
---|---|
date | Mon, 22 Feb 2010 18:17:14 +0000 |
parents | |
children | 30dde71d0230 |
comparison
equal
deleted
inserted
replaced
293:aeac9e2151c6 | 294:921575ec87a3 |
---|---|
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 main(): | |
39 wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/" | |
40 features_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/work08-jess-original-rec_rubber/features/" | |
41 | |
42 file_name = "aa/aa161.1p119.4s100.0t+000itd" | |
43 | |
44 wave_suffix = ".wav" | |
45 features_suffix = ".mat" | |
46 | |
47 frame_period_ms = 10; | |
48 | |
49 wave_filename = wave_path + file_name + wave_suffix | |
50 features_filename = features_path + file_name + features_suffix | |
51 | |
52 (sample_rate, input_wave) = wavfile.read(wave_filename) | |
53 wave_length = input_wave.size | |
54 buffer_length = int(frame_period_ms * sample_rate / 1000) | |
55 | |
56 #pylab.plot(input_wave) | |
57 #pylab.show() | |
58 | |
59 input_sig = aimc.SignalBank() | |
60 input_sig.Initialize(1, buffer_length, sample_rate) | |
61 parameters = aimc.Parameters() | |
62 parameters.Load("src/Scripts/profile_features.cfg") | |
63 mod_gt = aimc.ModuleGammatone(parameters) | |
64 mod_hl = aimc.ModuleHCL(parameters) | |
65 mod_profile = aimc.ModuleSlice(parameters) | |
66 mod_scaler = aimc.ModuleScaler(parameters) | |
67 mod_features = aimc.ModuleGaussians(parameters) | |
68 mod_gt.AddTarget(mod_hl) | |
69 mod_hl.AddTarget(mod_profile) | |
70 mod_profile.AddTarget(mod_scaler) | |
71 mod_scaler.AddTarget(mod_features) | |
72 mod_gt.Initialize(input_sig) | |
73 | |
74 correct_count = 0; | |
75 incorrect_count = 0; | |
76 | |
77 scaled_wave = [] | |
78 for sample in input_wave: | |
79 scaled_wave.append(float(sample / float(pow(2,15) - 1))) | |
80 i = 0 | |
81 | |
82 wave_chunks = grouper(buffer_length, scaled_wave, 0) | |
83 | |
84 out_frames = [] | |
85 for chunk in wave_chunks: | |
86 i = 0 | |
87 for sample in chunk: | |
88 input_sig.set_sample(0, i, float(sample)) | |
89 i += 1 | |
90 mod_gt.Process(input_sig) | |
91 out_sig = mod_features.GetOutputBank() | |
92 | |
93 channel_count = out_sig.channel_count() | |
94 out_buffer_length = out_sig.buffer_length() | |
95 cfs = scipy.zeros((channel_count)) | |
96 out = scipy.zeros((channel_count, out_buffer_length)) | |
97 | |
98 for ch in range(0, channel_count): | |
99 for i in range(0, out_buffer_length): | |
100 out[ch, i] = out_sig.sample(ch, i) | |
101 out_frames.append(out) | |
102 | |
103 outmat = dict(profile_out=out_frames) | |
104 io.savemat("src/Scripts/features_out.mat", outmat) | |
105 | |
106 pass | |
107 | |
108 | |
109 if __name__ == '__main__': | |
110 main() |