tomwalters@294
|
1 #!/usr/bin/env python
|
tomwalters@294
|
2 # encoding: utf-8
|
tomwalters@294
|
3 #
|
tomwalters@294
|
4 # AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@294
|
5 # http://www.acousticscale.org/AIMC
|
tomwalters@294
|
6 #
|
tomwalters@318
|
7 # Licensed under the Apache License, Version 2.0 (the "License");
|
tomwalters@318
|
8 # you may not use this file except in compliance with the License.
|
tomwalters@318
|
9 # You may obtain a copy of the License at
|
tomwalters@294
|
10 #
|
tomwalters@318
|
11 # http://www.apache.org/licenses/LICENSE-2.0
|
tomwalters@294
|
12 #
|
tomwalters@318
|
13 # Unless required by applicable law or agreed to in writing, software
|
tomwalters@318
|
14 # distributed under the License is distributed on an "AS IS" BASIS,
|
tomwalters@318
|
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tomwalters@318
|
16 # See the License for the specific language governing permissions and
|
tomwalters@318
|
17 # limitations under the License.
|
tomwalters@294
|
18 """
|
tomwalters@294
|
19 Profiles_test.py
|
tomwalters@294
|
20
|
tomwalters@294
|
21 Created by Thomas Walters on 2010-02-22.
|
tomwalters@294
|
22 Copyright 2010 Thomas Walters <tom@acousticscale.org>
|
tomwalters@294
|
23 Test the AIM-C model from filterbank to SSI profiles
|
tomwalters@294
|
24 """
|
tomwalters@294
|
25
|
tomwalters@294
|
26 import aimc
|
tomwalters@294
|
27 from scipy.io import wavfile
|
tomwalters@294
|
28 from scipy import io
|
tomwalters@294
|
29 import scipy
|
tomwalters@294
|
30 import pylab
|
tomwalters@294
|
31 from itertools import izip, chain, repeat
|
tomwalters@294
|
32
|
tomwalters@294
|
33 def grouper(n, iterable, padvalue=None):
|
tomwalters@294
|
34 "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
|
tomwalters@294
|
35 return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
|
tomwalters@294
|
36
|
tomwalters@294
|
37 def main():
|
tomwalters@294
|
38 wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/"
|
tomwalters@294
|
39 features_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/work08-jess-original-rec_rubber/features/"
|
tomwalters@294
|
40
|
tomwalters@294
|
41 file_name = "aa/aa161.1p119.4s100.0t+000itd"
|
tomwalters@294
|
42
|
tomwalters@294
|
43 wave_suffix = ".wav"
|
tomwalters@294
|
44 features_suffix = ".mat"
|
tomwalters@294
|
45
|
tomwalters@294
|
46 frame_period_ms = 10;
|
tomwalters@294
|
47
|
tomwalters@294
|
48 wave_filename = wave_path + file_name + wave_suffix
|
tomwalters@294
|
49 features_filename = features_path + file_name + features_suffix
|
tomwalters@294
|
50
|
tomwalters@294
|
51 (sample_rate, input_wave) = wavfile.read(wave_filename)
|
tomwalters@294
|
52 wave_length = input_wave.size
|
tomwalters@294
|
53 buffer_length = int(frame_period_ms * sample_rate / 1000)
|
tomwalters@294
|
54
|
tomwalters@294
|
55 #pylab.plot(input_wave)
|
tomwalters@294
|
56 #pylab.show()
|
tomwalters@294
|
57
|
tomwalters@294
|
58 input_sig = aimc.SignalBank()
|
tomwalters@294
|
59 input_sig.Initialize(1, buffer_length, sample_rate)
|
tomwalters@294
|
60 parameters = aimc.Parameters()
|
tomwalters@294
|
61 parameters.Load("src/Scripts/profile_features.cfg")
|
tomwalters@294
|
62 mod_gt = aimc.ModuleGammatone(parameters)
|
tomwalters@294
|
63 mod_hl = aimc.ModuleHCL(parameters)
|
tomwalters@294
|
64 mod_profile = aimc.ModuleSlice(parameters)
|
tomwalters@294
|
65 mod_scaler = aimc.ModuleScaler(parameters)
|
tomwalters@294
|
66 mod_features = aimc.ModuleGaussians(parameters)
|
tomwalters@294
|
67 mod_gt.AddTarget(mod_hl)
|
tomwalters@294
|
68 mod_hl.AddTarget(mod_profile)
|
tomwalters@294
|
69 mod_profile.AddTarget(mod_scaler)
|
tomwalters@294
|
70 mod_scaler.AddTarget(mod_features)
|
tomwalters@294
|
71 mod_gt.Initialize(input_sig)
|
tomwalters@294
|
72
|
tomwalters@294
|
73 correct_count = 0;
|
tomwalters@294
|
74 incorrect_count = 0;
|
tomwalters@294
|
75
|
tomwalters@294
|
76 scaled_wave = []
|
tomwalters@294
|
77 for sample in input_wave:
|
tomwalters@294
|
78 scaled_wave.append(float(sample / float(pow(2,15) - 1)))
|
tomwalters@294
|
79 i = 0
|
tomwalters@294
|
80
|
tomwalters@294
|
81 wave_chunks = grouper(buffer_length, scaled_wave, 0)
|
tomwalters@294
|
82
|
tomwalters@294
|
83 out_frames = []
|
tomwalters@294
|
84 for chunk in wave_chunks:
|
tomwalters@294
|
85 i = 0
|
tomwalters@294
|
86 for sample in chunk:
|
tomwalters@294
|
87 input_sig.set_sample(0, i, float(sample))
|
tomwalters@294
|
88 i += 1
|
tomwalters@294
|
89 mod_gt.Process(input_sig)
|
tomwalters@294
|
90 out_sig = mod_features.GetOutputBank()
|
tomwalters@294
|
91
|
tomwalters@294
|
92 channel_count = out_sig.channel_count()
|
tomwalters@294
|
93 out_buffer_length = out_sig.buffer_length()
|
tomwalters@294
|
94 cfs = scipy.zeros((channel_count))
|
tomwalters@294
|
95 out = scipy.zeros((channel_count, out_buffer_length))
|
tomwalters@294
|
96
|
tomwalters@294
|
97 for ch in range(0, channel_count):
|
tomwalters@294
|
98 for i in range(0, out_buffer_length):
|
tomwalters@294
|
99 out[ch, i] = out_sig.sample(ch, i)
|
tomwalters@294
|
100 out_frames.append(out)
|
tomwalters@294
|
101
|
tomwalters@294
|
102 outmat = dict(profile_out=out_frames)
|
tomwalters@294
|
103 io.savemat("src/Scripts/features_out.mat", outmat)
|
tomwalters@294
|
104
|
tomwalters@294
|
105 pass
|
tomwalters@294
|
106
|
tomwalters@294
|
107
|
tomwalters@294
|
108 if __name__ == '__main__':
|
tomwalters@294
|
109 main()
|