tomwalters@277: #!/usr/bin/env python tomwalters@277: # encoding: utf-8 tomwalters@277: # tomwalters@277: # AIM-C: A C++ implementation of the Auditory Image Model tomwalters@277: # http://www.acousticscale.org/AIMC tomwalters@277: # tomwalters@318: # Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@318: # you may not use this file except in compliance with the License. tomwalters@318: # You may obtain a copy of the License at tomwalters@277: # tomwalters@318: # http://www.apache.org/licenses/LICENSE-2.0 tomwalters@277: # tomwalters@318: # Unless required by applicable law or agreed to in writing, software tomwalters@318: # distributed under the License is distributed on an "AS IS" BASIS, tomwalters@318: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@318: # See the License for the specific language governing permissions and tomwalters@318: # limitations under the License. tomwalters@277: """ tomwalters@277: ModuleGammatone_test.py tomwalters@277: tomwalters@277: Created by Thomas Walters on 2010-02-15. tomwalters@277: Copyright 2010 Thomas Walters tomwalters@277: Test for the Slaney IIR gammatone. tomwalters@277: """ tomwalters@277: tomwalters@277: import aimc tomwalters@277: from scipy import io tomwalters@288: import wave tomwalters@288: import scipy tomwalters@277: tomwalters@277: def main(): tomwalters@277: data_file = "src/Modules/BMM/testdata/gammatone.mat" tomwalters@277: data = io.loadmat(data_file) tomwalters@277: tomwalters@277: # The margin of error allowed between the returned values from AIM-C and tomwalters@277: # the stored MATLAB values. tomwalters@277: epsilon = 0.000001; tomwalters@277: tomwalters@277: input_wave = data["input_wave"] tomwalters@277: sample_rate = data["sample_rate"] tomwalters@277: centre_frequencies = data["centre_frequencies"] tomwalters@277: expected_output = data["expected_output"] tomwalters@277: tomwalters@288: (channel_count, frame_count) = expected_output.shape tomwalters@288: buffer_length = 20000; tomwalters@277: tomwalters@277: input_sig = aimc.SignalBank() tomwalters@288: input_sig.Initialize(1, buffer_length, 48000) tomwalters@277: parameters = aimc.Parameters() tomwalters@288: parameters.Load("src/Modules/BMM/testdata/gammatone.cfg") tomwalters@277: mod_gt = aimc.ModuleGammatone(parameters) tomwalters@277: mod_gt.Initialize(input_sig) tomwalters@277: tomwalters@277: correct_count = 0; tomwalters@277: incorrect_count = 0; tomwalters@288: tomwalters@288: out = scipy.zeros((channel_count, buffer_length)) tomwalters@288: tomwalters@288: cfs = scipy.zeros((channel_count)) tomwalters@288: tomwalters@288: for i in range(0, buffer_length): tomwalters@288: input_sig.set_sample(0, i, input_wave[i][0]) tomwalters@288: mod_gt.Process(input_sig) tomwalters@288: out_sig = mod_gt.GetOutputBank() tomwalters@288: for ch in range(0, out_sig.channel_count()): tomwalters@288: cfs[ch] = out_sig.centre_frequency(ch); tomwalters@288: for i in range(0, buffer_length): tomwalters@288: out[ch, i] = out_sig.sample(ch, i) tomwalters@288: tomwalters@288: outmat = dict(filterbank_out=out, centre_frequencies_out=cfs) tomwalters@288: io.savemat("src/Modules/BMM/testdata/out_v2.mat", outmat) tomwalters@277: tomwalters@277: pass tomwalters@277: tomwalters@277: tomwalters@277: if __name__ == '__main__': tomwalters@277: main()