dicklyon@615
|
1 % Copyright 2013, Google, Inc.
|
dicklyon@615
|
2 % Author: Richard F. Lyon
|
dicklyon@615
|
3 %
|
dicklyon@615
|
4 % This Matlab file is part of an implementation of Lyon's cochlear model:
|
dicklyon@615
|
5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression"
|
dicklyon@615
|
6 % to supplement Lyon's upcoming book "Human and Machine Hearing"
|
dicklyon@615
|
7 %
|
dicklyon@615
|
8 % Licensed under the Apache License, Version 2.0 (the "License");
|
dicklyon@615
|
9 % you may not use this file except in compliance with the License.
|
dicklyon@615
|
10 % You may obtain a copy of the License at
|
dicklyon@615
|
11 %
|
dicklyon@615
|
12 % http://www.apache.org/licenses/LICENSE-2.0
|
dicklyon@615
|
13 %
|
dicklyon@615
|
14 % Unless required by applicable law or agreed to in writing, software
|
dicklyon@615
|
15 % distributed under the License is distributed on an "AS IS" BASIS,
|
dicklyon@615
|
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
dicklyon@615
|
17 % See the License for the specific language governing permissions and
|
dicklyon@615
|
18 % limitations under the License.
|
dicklyon@615
|
19
|
dicklyon@615
|
20 %% Test/demo hacking for CARFAC_SAI Matlab stuff:
|
dicklyon@615
|
21
|
dicklyon@615
|
22 clear variables
|
dicklyon@615
|
23
|
dicklyon@615
|
24 system('mkdir frames');
|
dicklyon@615
|
25
|
dicklyon@615
|
26 %%
|
dicklyon@615
|
27
|
dicklyon@615
|
28 dB_list = -40; % -60:20:0
|
dicklyon@615
|
29
|
dicklyon@615
|
30 wav_fn = 'plan.wav';
|
dicklyon@665
|
31 wav_fn = 'Stiletto44.wav';
|
dicklyon@665
|
32 wav_fn = 'You Can Call Me Al.wav';
|
dicklyon@615
|
33
|
dicklyon@615
|
34 if ~exist(['./', wav_fn], 'file')
|
dicklyon@615
|
35 error('wav file not found')
|
dicklyon@615
|
36 end
|
dicklyon@615
|
37
|
dicklyon@615
|
38 wav_fn
|
dicklyon@615
|
39 [file_signal, fs] = wavread(wav_fn);
|
dicklyon@615
|
40
|
dicklyon@665
|
41 % if fs == 44100
|
dicklyon@665
|
42 % file_signal = (file_signal(1:2:end-1, :) + file_signal(2:2:end, :)) / 2;
|
dicklyon@665
|
43 % fs = fs / 2;
|
dicklyon@665
|
44 % end
|
dicklyon@665
|
45 %
|
dicklyon@665
|
46 % if fs ~= 22050
|
dicklyon@665
|
47 % error('unexpected sample rate')
|
dicklyon@665
|
48 % end
|
dicklyon@615
|
49
|
dicklyon@615
|
50 file_signal = file_signal(:, 1); % mono
|
dicklyon@615
|
51 file_signal = [file_signal; zeros(fs, 1)]; % pad with a second of silence
|
dicklyon@615
|
52
|
dicklyon@615
|
53
|
dicklyon@615
|
54 % make a long test signal by repeating at different levels:
|
dicklyon@615
|
55 test_signal = [];
|
dicklyon@615
|
56 for dB = dB_list
|
dicklyon@615
|
57 test_signal = [test_signal; file_signal * 10^(dB/20)];
|
dicklyon@615
|
58 end
|
dicklyon@615
|
59
|
dicklyon@615
|
60 %%
|
dicklyon@665
|
61 CF_struct = CARFAC_Design(1, fs); % default design
|
dicklyon@615
|
62
|
dicklyon@615
|
63 CF_struct = CARFAC_Init(CF_struct);
|
dicklyon@615
|
64
|
dicklyon@615
|
65 [frame_rate, num_frames] = SAI_RunLayered(CF_struct, test_signal);
|
dicklyon@615
|
66
|
dicklyon@615
|
67 %%
|
dicklyon@615
|
68 png_name_pattern = 'frames/frame%05d.png';
|
dicklyon@615
|
69 MakeMovieFromPngsAndWav(round(frame_rate), png_name_pattern, ...
|
dicklyon@615
|
70 wav_fn, ['CARFAC_SAI_movie_', wav_fn(1:end-4), '.mpg'])
|
dicklyon@615
|
71
|
dicklyon@615
|
72 %%
|
dicklyon@615
|
73 system('rm -r frames');
|
dicklyon@615
|
74
|
dicklyon@665
|
75
|