Mercurial > hg > aimc
diff trunk/src/Scripts/Features_test.py @ 294:921575ec87a3
- Added scripts directory with a few basic scripts for testing modules and interfacting with matlab
author | tomwalters |
---|---|
date | Mon, 22 Feb 2010 18:17:14 +0000 |
parents | |
children | 30dde71d0230 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Scripts/Features_test.py Mon Feb 22 18:17:14 2010 +0000 @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# AIM-C: A C++ implementation of the Auditory Image Model +# http://www.acousticscale.org/AIMC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +""" +Profiles_test.py + +Created by Thomas Walters on 2010-02-22. +Copyright 2010 Thomas Walters <tom@acousticscale.org> +Test the AIM-C model from filterbank to SSI profiles +""" + +import aimc +from scipy.io import wavfile +from scipy import io +import scipy +import pylab +from itertools import izip, chain, repeat + +def grouper(n, iterable, padvalue=None): + "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')" + return izip(*[chain(iterable, repeat(padvalue, n-1))]*n) + +def main(): + wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/" + features_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/work08-jess-original-rec_rubber/features/" + + file_name = "aa/aa161.1p119.4s100.0t+000itd" + + wave_suffix = ".wav" + features_suffix = ".mat" + + frame_period_ms = 10; + + wave_filename = wave_path + file_name + wave_suffix + features_filename = features_path + file_name + features_suffix + + (sample_rate, input_wave) = wavfile.read(wave_filename) + wave_length = input_wave.size + buffer_length = int(frame_period_ms * sample_rate / 1000) + + #pylab.plot(input_wave) + #pylab.show() + + input_sig = aimc.SignalBank() + input_sig.Initialize(1, buffer_length, sample_rate) + parameters = aimc.Parameters() + parameters.Load("src/Scripts/profile_features.cfg") + mod_gt = aimc.ModuleGammatone(parameters) + mod_hl = aimc.ModuleHCL(parameters) + mod_profile = aimc.ModuleSlice(parameters) + mod_scaler = aimc.ModuleScaler(parameters) + mod_features = aimc.ModuleGaussians(parameters) + mod_gt.AddTarget(mod_hl) + mod_hl.AddTarget(mod_profile) + mod_profile.AddTarget(mod_scaler) + mod_scaler.AddTarget(mod_features) + mod_gt.Initialize(input_sig) + + correct_count = 0; + incorrect_count = 0; + + scaled_wave = [] + for sample in input_wave: + scaled_wave.append(float(sample / float(pow(2,15) - 1))) + i = 0 + + wave_chunks = grouper(buffer_length, scaled_wave, 0) + + out_frames = [] + for chunk in wave_chunks: + i = 0 + for sample in chunk: + input_sig.set_sample(0, i, float(sample)) + i += 1 + mod_gt.Process(input_sig) + out_sig = mod_features.GetOutputBank() + + channel_count = out_sig.channel_count() + out_buffer_length = out_sig.buffer_length() + cfs = scipy.zeros((channel_count)) + out = scipy.zeros((channel_count, out_buffer_length)) + + for ch in range(0, channel_count): + for i in range(0, out_buffer_length): + out[ch, i] = out_sig.sample(ch, i) + out_frames.append(out) + + outmat = dict(profile_out=out_frames) + io.savemat("src/Scripts/features_out.mat", outmat) + + pass + + +if __name__ == '__main__': + main()