comparison src/Modules/BMM/ModuleGammatone_test.py @ 5:3c782dec2fc0

- Ported over HTK file output - Added some more meat to the Slaney IIR gammatone implementation - Ported over the AIM-MAT sf2003 parabola strobe algorithm - Finished making the SAI implementation compile - Ported over the strobe list class (now uses STL deques internally)
author tomwalters
date Thu, 18 Feb 2010 16:55:40 +0000
parents
children 2a5354042241
comparison
equal deleted inserted replaced
4:eb0449575bb9 5:3c782dec2fc0
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 ModuleGammatone_test.py
21
22 Created by Thomas Walters on 2010-02-15.
23 Copyright 2010 Thomas Walters <tom@acousticscale.org>
24 Test for the Slaney IIR gammatone.
25 """
26
27 import aimc
28 from scipy import io
29
30 def main():
31 data_file = "src/Modules/BMM/testdata/gammatone.mat"
32 data = io.loadmat(data_file)
33
34 # The margin of error allowed between the returned values from AIM-C and
35 # the stored MATLAB values.
36 epsilon = 0.000001;
37
38 input_wave = data["input_wave"]
39 sample_rate = data["sample_rate"]
40 centre_frequencies = data["centre_frequencies"]
41 expected_output = data["expected_output"]
42
43 (channel_count, buffer_length, frame_count) = expected_output.shape
44
45 input_sig = aimc.SignalBank()
46 input_sig.Initialize(1, buffer_length, 44100)
47 parameters = aimc.Parameters()
48 mod_gt = aimc.ModuleGammatone(parameters)
49 mod_gt.Initialize(input_sig)
50
51 correct_count = 0;
52 incorrect_count = 0;
53 for p in range(0, profile_count):
54 profile = given_profiles[p]
55 features = matlab_features[p]
56 for i in range(0, channel_count):
57 profile_sig.set_sample(i, 0, profile[i])
58 mod_gauss.Process(profile_sig)
59 out_sig = mod_gauss.GetOutputBank()
60 error = False;
61 for j in range(0, out_sig.channel_count()):
62 if (abs(out_sig.sample(j, 0) - features[j]) > epsilon):
63 error = True;
64 incorrect_count += 1;
65 else:
66 correct_count += 1;
67 if error:
68 print("Mismatch at profile %d" % (p))
69 print("AIM-C values: %f %f %f %f" % (out_sig.sample(0, 0), out_sig.sample(1, 0), out_sig.sample(2, 0), out_sig.sample(3, 0)))
70 print("MATLAB values: %f %f %f %f" % (features[0], features[1], features[2], features[3]))
71 print("")
72 percent_correct = 100 * correct_count / (correct_count + incorrect_count)
73 print("Total correct: %f percent" % (percent_correct))
74 if percent_correct == 100:
75 print("=== TEST PASSED ===")
76 else:
77 print("=== TEST FAILED! ===")
78
79 pass
80
81
82 if __name__ == '__main__':
83 main()