comparison src/Scripts/Strobes_test.py @ 32:9122efd2b227

-New AIMCopy main for the SSI features (temporary hack till I get a working module load system) -LocalMax strobe criterion. This is faster and better than the parabola version, which still seems buggy. -Noise generator module. Adds noise to a signal. Uses boost for the random number generator. -New options for the SSI -Slice now respects all its flags (oops!). -MATLAB functions for visualisation -Scripts for generating data to view in MATLAB -Script to download and build HTK - useful for running experiments
author tomwalters
date Thu, 25 Feb 2010 22:02:00 +0000
parents
children c5f5e9569863
comparison
equal deleted inserted replaced
31:fa06bfacf004 32:9122efd2b227
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # AIM-C: A C++ implementation of the Auditory Image Model
5 # http://www.acousticscale.org/AIMC
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 """
20 Profiles_test.py
21
22 Created by Thomas Walters on 2010-02-22.
23 Copyright 2010 Thomas Walters <tom@acousticscale.org>
24 Test the AIM-C model from filterbank to SSI profiles
25 """
26
27 import aimc
28 from scipy.io import wavfile
29 from scipy import io
30 import scipy
31 import pylab
32 import numpy
33 from itertools import izip, chain, repeat
34
35 def grouper(n, iterable, padvalue=None):
36 "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
37 return izip(*[chain(iterable, repeat(padvalue, n-1))]*n)
38
39 def BankToArray(out_bank):
40 channel_count = out_bank.channel_count()
41 out_buffer_length = out_bank.buffer_length()
42 out = scipy.zeros((channel_count,out_buffer_length))
43 for ch in range(0, channel_count):
44 for i in range(0, out_buffer_length):
45 out[ch, i] = out_bank.sample(ch, i)
46 return out
47
48 def StrobesToList(bank):
49 channel_count = bank.channel_count()
50 out = scipy.zeros((channel_count,), dtype=numpy.object)
51 for ch in range(0, channel_count):
52 s = []
53 for i in range(0, bank.strobe_count(ch)):
54 s.append(bank.strobe(ch, i))
55 out[ch] = s
56 return out
57
58 def main():
59 wave_path = "/Users/Tom/Documents/Work/PhD/HTK-AIM/Sounds/"
60
61 file_name = "ii/ii172.5p112.5s100.0t+000itd"
62
63 wave_suffix = ".wav"
64
65 frame_period_ms = 10;
66
67 wave_filename = wave_path + file_name + wave_suffix
68
69 (sample_rate, input_wave) = wavfile.read(wave_filename)
70 wave_length = input_wave.size
71 buffer_length = int(frame_period_ms * sample_rate / 1000)
72
73
74 input_sig = aimc.SignalBank()
75 input_sig.Initialize(1, buffer_length, sample_rate)
76 parameters = aimc.Parameters()
77 parameters.SetInt("input.buffersize", 480)
78
79 mod_gt = aimc.ModuleGammatone(parameters)
80 mod_hl = aimc.ModuleHCL(parameters)
81 mod_strobes = aimc.ModuleLocalMax(parameters)
82
83 mod_gt.AddTarget(mod_hl)
84 mod_hl.AddTarget(mod_strobes)
85
86 mod_gt.Initialize(input_sig)
87
88 correct_count = 0;
89 incorrect_count = 0;
90
91 scaled_wave = []
92 for sample in input_wave:
93 scaled_wave.append(float(sample / float(pow(2,15) - 1)))
94 i = 0
95
96 wave_chunks = grouper(buffer_length, scaled_wave, 0)
97
98 out_nap = []
99 out_strobes = []
100
101 for chunk in wave_chunks:
102 i = 0
103 for sample in chunk:
104 input_sig.set_sample(0, i, float(sample))
105 i += 1
106 mod_gt.Process(input_sig)
107 out_nap.append(BankToArray(mod_hl.GetOutputBank()))
108 out_strobes.append(StrobesToList(mod_strobes.GetOutputBank()))
109
110 outmat = dict(nap=out_nap, strobes=out_strobes)
111 io.savemat("src/Scripts/strobes_out.mat", outmat, oned_as='column')
112
113 pass
114
115
116 if __name__ == '__main__':
117 main()