Mercurial > hg > aimc
comparison matlab/bmm/carfac/CARFAC_SAI_hacking.m @ 604:ec3a1c74ec54
Add files for making log-lag SAI from CARFAC's NAP output. The file
SAI_RunLayered.m dumps frames to PNG files. The hacking script calls
ffmpeg to assemble them with the soundtrack into a movie.
author | dicklyon@google.com |
---|---|
date | Thu, 09 May 2013 03:48:44 +0000 |
parents | |
children | b3118c9ed67f |
comparison
equal
deleted
inserted
replaced
603:087f3b3c36d3 | 604:ec3a1c74ec54 |
---|---|
1 % Copyright 2013, Google, Inc. | |
2 % Author: Richard F. Lyon | |
3 % | |
4 % This Matlab file is part of an implementation of Lyon's cochlear model: | |
5 % "Cascade of Asymmetric Resonators with Fast-Acting Compression" | |
6 % to supplement Lyon's upcoming book "Human and Machine Hearing" | |
7 % | |
8 % Licensed under the Apache License, Version 2.0 (the "License"); | |
9 % you may not use this file except in compliance with the License. | |
10 % You may obtain a copy of the License at | |
11 % | |
12 % http://www.apache.org/licenses/LICENSE-2.0 | |
13 % | |
14 % Unless required by applicable law or agreed to in writing, software | |
15 % distributed under the License is distributed on an "AS IS" BASIS, | |
16 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
17 % See the License for the specific language governing permissions and | |
18 % limitations under the License. | |
19 | |
20 %% Test/demo hacking for CARFAC_SAI Matlab stuff: | |
21 | |
22 clear variables | |
23 | |
24 system('mkdir frames'); | |
25 | |
26 %% | |
27 | |
28 dB_list = -40; % -60:20:0 | |
29 | |
30 wav_fn = 'plan.wav'; | |
31 | |
32 if ~exist(['./', wav_fn], 'file') | |
33 error('wav file not found') | |
34 end | |
35 | |
36 wav_fn | |
37 [file_signal, fs] = wavread(wav_fn); | |
38 | |
39 if fs == 44100 | |
40 file_signal = (file_signal(1:2:end-1, :) + file_signal(2:2:end, :)) / 2; | |
41 fs = fs / 2; | |
42 end | |
43 | |
44 if fs ~= 22050 | |
45 error('unexpected sample rate') | |
46 end | |
47 | |
48 file_signal = file_signal(:, 1); % mono | |
49 file_signal = [file_signal; zeros(fs, 1)]; % pad with a second of silence | |
50 | |
51 | |
52 % make a long test signal by repeating at different levels: | |
53 test_signal = []; | |
54 for dB = dB_list | |
55 test_signal = [test_signal; file_signal * 10^(dB/20)]; | |
56 end | |
57 | |
58 %% | |
59 CF_struct = CARFAC_Design(1); % default design | |
60 | |
61 CF_struct = CARFAC_Init(CF_struct); | |
62 | |
63 [frame_rate, num_frames] = SAI_RunLayered(CF_struct, test_signal); | |
64 | |
65 %% | |
66 png_name_pattern = 'frames/frame%05d.png'; | |
67 MakeMovieFromPngsAndWav(round(frame_rate), png_name_pattern, ... | |
68 wav_fn, ['CARFAC_SAI_movie_', wav_fn(1:end-4), '.mpg']) | |
69 | |
70 %% | |
71 system('rm -r frames'); | |
72 |