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