annotate src/Scripts/Profiles_test.py @ 49:0cd20c748308

- AIMCopy v5 for just smooth NAP features - Reporting of all modules and versions
author tomwalters
date Sun, 11 Jul 2010 03:46:06 +0000
parents c5f5e9569863
children
rev   line source
tomwalters@22 1 #!/usr/bin/env python
tomwalters@22 2 # encoding: utf-8
tomwalters@22 3 #
tomwalters@22 4 # AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@22 5 # http://www.acousticscale.org/AIMC
tomwalters@22 6 #
tomwalters@45 7 # Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@45 8 # you may not use this file except in compliance with the License.
tomwalters@45 9 # You may obtain a copy of the License at
tomwalters@22 10 #
tomwalters@45 11 # http://www.apache.org/licenses/LICENSE-2.0
tomwalters@22 12 #
tomwalters@45 13 # Unless required by applicable law or agreed to in writing, software
tomwalters@45 14 # distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@45 15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@45 16 # See the License for the specific language governing permissions and
tomwalters@45 17 # limitations under the License.
tomwalters@22 18 """
tomwalters@22 19 Profiles_test.py
tomwalters@22 20
tomwalters@22 21 Created by Thomas Walters on 2010-02-22.
tomwalters@22 22 Copyright 2010 Thomas Walters <tom@acousticscale.org>
tomwalters@22 23 Test the AIM-C model from filterbank to SSI profiles
tomwalters@22 24 """
tomwalters@22 25
tomwalters@22 26 import aimc
tomwalters@22 27 from scipy.io import wavfile
tomwalters@22 28 from scipy import io
tomwalters@22 29 import scipy
tomwalters@22 30 import pylab
tomwalters@22 31 from itertools import izip, chain, repeat
tomwalters@22 32
tomwalters@22 33 def grouper(n, iterable, padvalue=None):
tomwalters@22 34 "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
tomwalters@22 35 return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
tomwalters@22 36
tomwalters@22 37 def main():
tomwalters@22 38 wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/"
tomwalters@22 39 features_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/work08-jess-original-rec_rubber/features/"
tomwalters@22 40
tomwalters@22 41 file_name = "aa/aa161.1p119.4s100.0t+000itd"
tomwalters@22 42
tomwalters@22 43 wave_suffix = ".wav"
tomwalters@22 44 features_suffix = ".mat"
tomwalters@22 45
tomwalters@22 46 frame_period_ms = 10;
tomwalters@22 47
tomwalters@22 48 wave_filename = wave_path + file_name + wave_suffix
tomwalters@22 49 features_filename = features_path + file_name + features_suffix
tomwalters@22 50
tomwalters@22 51 (sample_rate, input_wave) = wavfile.read(wave_filename)
tomwalters@22 52 wave_length = input_wave.size
tomwalters@22 53 buffer_length = int(frame_period_ms * sample_rate / 1000)
tomwalters@22 54
tomwalters@22 55 #pylab.plot(input_wave)
tomwalters@22 56 #pylab.show()
tomwalters@22 57
tomwalters@22 58 input_sig = aimc.SignalBank()
tomwalters@22 59 input_sig.Initialize(1, buffer_length, sample_rate)
tomwalters@22 60 parameters = aimc.Parameters()
tomwalters@22 61 parameters.Load("src/Scripts/profile_features.cfg")
tomwalters@22 62 mod_gt = aimc.ModuleGammatone(parameters)
tomwalters@22 63 mod_hl = aimc.ModuleHCL(parameters)
tomwalters@22 64 mod_profile = aimc.ModuleSlice(parameters)
tomwalters@22 65 mod_scaler = aimc.ModuleScaler(parameters)
tomwalters@22 66 mod_gt.AddTarget(mod_hl)
tomwalters@22 67 mod_hl.AddTarget(mod_profile)
tomwalters@22 68 mod_profile.AddTarget(mod_scaler)
tomwalters@22 69 mod_gt.Initialize(input_sig)
tomwalters@22 70
tomwalters@22 71 correct_count = 0;
tomwalters@22 72 incorrect_count = 0;
tomwalters@22 73
tomwalters@22 74 scaled_wave = []
tomwalters@22 75 for sample in input_wave:
tomwalters@22 76 scaled_wave.append(float(sample / float(pow(2,15) - 1)))
tomwalters@22 77 i = 0
tomwalters@22 78
tomwalters@22 79 wave_chunks = grouper(buffer_length, scaled_wave, 0)
tomwalters@22 80
tomwalters@22 81 out_frames = []
tomwalters@22 82 for chunk in wave_chunks:
tomwalters@22 83 i = 0
tomwalters@22 84 for sample in chunk:
tomwalters@22 85 input_sig.set_sample(0, i, float(sample))
tomwalters@22 86 i += 1
tomwalters@22 87 mod_gt.Process(input_sig)
tomwalters@22 88 out_sig = mod_scaler.GetOutputBank()
tomwalters@22 89
tomwalters@22 90 channel_count = out_sig.channel_count()
tomwalters@22 91 out_buffer_length = out_sig.buffer_length()
tomwalters@22 92 cfs = scipy.zeros((channel_count))
tomwalters@22 93 out = scipy.zeros((channel_count, out_buffer_length))
tomwalters@22 94
tomwalters@22 95 for ch in range(0, channel_count):
tomwalters@22 96 for i in range(0, out_buffer_length):
tomwalters@22 97 out[ch, i] = out_sig.sample(ch, i)
tomwalters@22 98 out_frames.append(out)
tomwalters@22 99
tomwalters@22 100 outmat = dict(profile_out=out_frames)
tomwalters@22 101 io.savemat("src/Scripts/profile_out.mat", outmat)
tomwalters@22 102
tomwalters@22 103 pass
tomwalters@22 104
tomwalters@22 105
tomwalters@22 106 if __name__ == '__main__':
tomwalters@22 107 main()