annotate trunk/src/Modules/BMM/ModuleGammatone_test.py @ 316:66a23c0545b6

-Added MFCCs back to the feature generation script
author tomwalters
date Thu, 04 Mar 2010 17:38:58 +0000
parents 34993448961f
children 30dde71d0230
rev   line source
tomwalters@277 1 #!/usr/bin/env python
tomwalters@277 2 # encoding: utf-8
tomwalters@277 3 #
tomwalters@277 4 # AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@277 5 # http://www.acousticscale.org/AIMC
tomwalters@277 6 #
tomwalters@277 7 # This program is free software: you can redistribute it and/or modify
tomwalters@277 8 # it under the terms of the GNU General Public License as published by
tomwalters@277 9 # the Free Software Foundation, either version 3 of the License, or
tomwalters@277 10 # (at your option) any later version.
tomwalters@277 11 #
tomwalters@277 12 # This program is distributed in the hope that it will be useful,
tomwalters@277 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@277 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@277 15 # GNU General Public License for more details.
tomwalters@277 16 #
tomwalters@277 17 # You should have received a copy of the GNU General Public License
tomwalters@277 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@277 19 """
tomwalters@277 20 ModuleGammatone_test.py
tomwalters@277 21
tomwalters@277 22 Created by Thomas Walters on 2010-02-15.
tomwalters@277 23 Copyright 2010 Thomas Walters <tom@acousticscale.org>
tomwalters@277 24 Test for the Slaney IIR gammatone.
tomwalters@277 25 """
tomwalters@277 26
tomwalters@277 27 import aimc
tomwalters@277 28 from scipy import io
tomwalters@288 29 import wave
tomwalters@288 30 import scipy
tomwalters@277 31
tomwalters@277 32 def main():
tomwalters@277 33 data_file = "src/Modules/BMM/testdata/gammatone.mat"
tomwalters@277 34 data = io.loadmat(data_file)
tomwalters@277 35
tomwalters@277 36 # The margin of error allowed between the returned values from AIM-C and
tomwalters@277 37 # the stored MATLAB values.
tomwalters@277 38 epsilon = 0.000001;
tomwalters@277 39
tomwalters@277 40 input_wave = data["input_wave"]
tomwalters@277 41 sample_rate = data["sample_rate"]
tomwalters@277 42 centre_frequencies = data["centre_frequencies"]
tomwalters@277 43 expected_output = data["expected_output"]
tomwalters@277 44
tomwalters@288 45 (channel_count, frame_count) = expected_output.shape
tomwalters@288 46 buffer_length = 20000;
tomwalters@277 47
tomwalters@277 48 input_sig = aimc.SignalBank()
tomwalters@288 49 input_sig.Initialize(1, buffer_length, 48000)
tomwalters@277 50 parameters = aimc.Parameters()
tomwalters@288 51 parameters.Load("src/Modules/BMM/testdata/gammatone.cfg")
tomwalters@277 52 mod_gt = aimc.ModuleGammatone(parameters)
tomwalters@277 53 mod_gt.Initialize(input_sig)
tomwalters@277 54
tomwalters@277 55 correct_count = 0;
tomwalters@277 56 incorrect_count = 0;
tomwalters@288 57
tomwalters@288 58 out = scipy.zeros((channel_count, buffer_length))
tomwalters@288 59
tomwalters@288 60 cfs = scipy.zeros((channel_count))
tomwalters@288 61
tomwalters@288 62 for i in range(0, buffer_length):
tomwalters@288 63 input_sig.set_sample(0, i, input_wave[i][0])
tomwalters@288 64 mod_gt.Process(input_sig)
tomwalters@288 65 out_sig = mod_gt.GetOutputBank()
tomwalters@288 66 for ch in range(0, out_sig.channel_count()):
tomwalters@288 67 cfs[ch] = out_sig.centre_frequency(ch);
tomwalters@288 68 for i in range(0, buffer_length):
tomwalters@288 69 out[ch, i] = out_sig.sample(ch, i)
tomwalters@288 70
tomwalters@288 71 outmat = dict(filterbank_out=out, centre_frequencies_out=cfs)
tomwalters@288 72 io.savemat("src/Modules/BMM/testdata/out_v2.mat", outmat)
tomwalters@277 73
tomwalters@277 74 pass
tomwalters@277 75
tomwalters@277 76
tomwalters@277 77 if __name__ == '__main__':
tomwalters@277 78 main()