tomwalters@5: #!/usr/bin/env python
tomwalters@5: # encoding: utf-8
tomwalters@5: #
tomwalters@5: # AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@5: # http://www.acousticscale.org/AIMC
tomwalters@5: #
tomwalters@5: # This program is free software: you can redistribute it and/or modify
tomwalters@5: # it under the terms of the GNU General Public License as published by
tomwalters@5: # the Free Software Foundation, either version 3 of the License, or
tomwalters@5: # (at your option) any later version.
tomwalters@5: #
tomwalters@5: # This program is distributed in the hope that it will be useful,
tomwalters@5: # but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@5: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@5: # GNU General Public License for more details.
tomwalters@5: #
tomwalters@5: # You should have received a copy of the GNU General Public License
tomwalters@5: # along with this program. If not, see .
tomwalters@5: """
tomwalters@5: ModuleGammatone_test.py
tomwalters@5:
tomwalters@5: Created by Thomas Walters on 2010-02-15.
tomwalters@5: Copyright 2010 Thomas Walters
tomwalters@5: Test for the Slaney IIR gammatone.
tomwalters@5: """
tomwalters@5:
tomwalters@5: import aimc
tomwalters@5: from scipy import io
tomwalters@16: import wave
tomwalters@16: import scipy
tomwalters@5:
tomwalters@5: def main():
tomwalters@5: data_file = "src/Modules/BMM/testdata/gammatone.mat"
tomwalters@5: data = io.loadmat(data_file)
tomwalters@5:
tomwalters@5: # The margin of error allowed between the returned values from AIM-C and
tomwalters@5: # the stored MATLAB values.
tomwalters@5: epsilon = 0.000001;
tomwalters@5:
tomwalters@5: input_wave = data["input_wave"]
tomwalters@5: sample_rate = data["sample_rate"]
tomwalters@5: centre_frequencies = data["centre_frequencies"]
tomwalters@5: expected_output = data["expected_output"]
tomwalters@5:
tomwalters@16: (channel_count, frame_count) = expected_output.shape
tomwalters@16: buffer_length = 20000;
tomwalters@5:
tomwalters@5: input_sig = aimc.SignalBank()
tomwalters@16: input_sig.Initialize(1, buffer_length, 48000)
tomwalters@5: parameters = aimc.Parameters()
tomwalters@16: parameters.Load("src/Modules/BMM/testdata/gammatone.cfg")
tomwalters@5: mod_gt = aimc.ModuleGammatone(parameters)
tomwalters@5: mod_gt.Initialize(input_sig)
tomwalters@5:
tomwalters@5: correct_count = 0;
tomwalters@5: incorrect_count = 0;
tomwalters@16:
tomwalters@16: out = scipy.zeros((channel_count, buffer_length))
tomwalters@16:
tomwalters@16: cfs = scipy.zeros((channel_count))
tomwalters@16:
tomwalters@16: for i in range(0, buffer_length):
tomwalters@16: input_sig.set_sample(0, i, input_wave[i][0])
tomwalters@16: mod_gt.Process(input_sig)
tomwalters@16: out_sig = mod_gt.GetOutputBank()
tomwalters@16: for ch in range(0, out_sig.channel_count()):
tomwalters@16: cfs[ch] = out_sig.centre_frequency(ch);
tomwalters@16: for i in range(0, buffer_length):
tomwalters@16: out[ch, i] = out_sig.sample(ch, i)
tomwalters@16:
tomwalters@16: outmat = dict(filterbank_out=out, centre_frequencies_out=cfs)
tomwalters@16: io.savemat("src/Modules/BMM/testdata/out_v2.mat", outmat)
tomwalters@5:
tomwalters@5: pass
tomwalters@5:
tomwalters@5:
tomwalters@5: if __name__ == '__main__':
tomwalters@5: main()