annotate trunk/src/Modules/BMM/ModuleGammatone_test.py @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents 30dde71d0230
children
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@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@277 10 #
tomwalters@318 11 # http://www.apache.org/licenses/LICENSE-2.0
tomwalters@277 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@277 18 """
tomwalters@277 19 ModuleGammatone_test.py
tomwalters@277 20
tomwalters@277 21 Created by Thomas Walters on 2010-02-15.
tomwalters@277 22 Copyright 2010 Thomas Walters <tom@acousticscale.org>
tomwalters@277 23 Test for the Slaney IIR gammatone.
tomwalters@277 24 """
tomwalters@277 25
tomwalters@277 26 import aimc
tomwalters@277 27 from scipy import io
tomwalters@288 28 import wave
tomwalters@288 29 import scipy
tomwalters@277 30
tomwalters@277 31 def main():
tomwalters@277 32 data_file = "src/Modules/BMM/testdata/gammatone.mat"
tomwalters@277 33 data = io.loadmat(data_file)
tomwalters@277 34
tomwalters@277 35 # The margin of error allowed between the returned values from AIM-C and
tomwalters@277 36 # the stored MATLAB values.
tomwalters@277 37 epsilon = 0.000001;
tomwalters@277 38
tomwalters@277 39 input_wave = data["input_wave"]
tomwalters@277 40 sample_rate = data["sample_rate"]
tomwalters@277 41 centre_frequencies = data["centre_frequencies"]
tomwalters@277 42 expected_output = data["expected_output"]
tomwalters@277 43
tomwalters@288 44 (channel_count, frame_count) = expected_output.shape
tomwalters@288 45 buffer_length = 20000;
tomwalters@277 46
tomwalters@277 47 input_sig = aimc.SignalBank()
tomwalters@288 48 input_sig.Initialize(1, buffer_length, 48000)
tomwalters@277 49 parameters = aimc.Parameters()
tomwalters@288 50 parameters.Load("src/Modules/BMM/testdata/gammatone.cfg")
tomwalters@277 51 mod_gt = aimc.ModuleGammatone(parameters)
tomwalters@277 52 mod_gt.Initialize(input_sig)
tomwalters@277 53
tomwalters@277 54 correct_count = 0;
tomwalters@277 55 incorrect_count = 0;
tomwalters@288 56
tomwalters@288 57 out = scipy.zeros((channel_count, buffer_length))
tomwalters@288 58
tomwalters@288 59 cfs = scipy.zeros((channel_count))
tomwalters@288 60
tomwalters@288 61 for i in range(0, buffer_length):
tomwalters@288 62 input_sig.set_sample(0, i, input_wave[i][0])
tomwalters@288 63 mod_gt.Process(input_sig)
tomwalters@288 64 out_sig = mod_gt.GetOutputBank()
tomwalters@288 65 for ch in range(0, out_sig.channel_count()):
tomwalters@288 66 cfs[ch] = out_sig.centre_frequency(ch);
tomwalters@288 67 for i in range(0, buffer_length):
tomwalters@288 68 out[ch, i] = out_sig.sample(ch, i)
tomwalters@288 69
tomwalters@288 70 outmat = dict(filterbank_out=out, centre_frequencies_out=cfs)
tomwalters@288 71 io.savemat("src/Modules/BMM/testdata/out_v2.mat", outmat)
tomwalters@277 72
tomwalters@277 73 pass
tomwalters@277 74
tomwalters@277 75
tomwalters@277 76 if __name__ == '__main__':
tomwalters@277 77 main()