dicklyon@604: % Copyright 2013, Google, Inc. dicklyon@604: % Author: Richard F. Lyon dicklyon@604: % dicklyon@604: % This Matlab file is part of an implementation of Lyon's cochlear model: dicklyon@604: % "Cascade of Asymmetric Resonators with Fast-Acting Compression" dicklyon@604: % to supplement Lyon's upcoming book "Human and Machine Hearing" dicklyon@604: % dicklyon@604: % Licensed under the Apache License, Version 2.0 (the "License"); dicklyon@604: % you may not use this file except in compliance with the License. dicklyon@604: % You may obtain a copy of the License at dicklyon@604: % dicklyon@604: % http://www.apache.org/licenses/LICENSE-2.0 dicklyon@604: % dicklyon@604: % Unless required by applicable law or agreed to in writing, software dicklyon@604: % distributed under the License is distributed on an "AS IS" BASIS, dicklyon@604: % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. dicklyon@604: % See the License for the specific language governing permissions and dicklyon@604: % limitations under the License. dicklyon@604: dicklyon@604: %% Test/demo hacking for CARFAC_SAI Matlab stuff: dicklyon@604: dicklyon@604: clear variables dicklyon@604: dicklyon@604: system('mkdir frames'); dicklyon@604: dicklyon@604: %% dicklyon@604: dicklyon@604: dB_list = -40; % -60:20:0 dicklyon@604: dicklyon@604: wav_fn = 'plan.wav'; dicklyon@623: wav_fn = 'Stiletto44.wav'; dicklyon@623: wav_fn = 'You Can Call Me Al.wav'; dicklyon@604: dicklyon@604: if ~exist(['./', wav_fn], 'file') dicklyon@604: error('wav file not found') dicklyon@604: end dicklyon@604: dicklyon@604: wav_fn dicklyon@604: [file_signal, fs] = wavread(wav_fn); dicklyon@604: dicklyon@623: % if fs == 44100 dicklyon@623: % file_signal = (file_signal(1:2:end-1, :) + file_signal(2:2:end, :)) / 2; dicklyon@623: % fs = fs / 2; dicklyon@623: % end dicklyon@623: % dicklyon@623: % if fs ~= 22050 dicklyon@623: % error('unexpected sample rate') dicklyon@623: % end dicklyon@604: dicklyon@604: file_signal = file_signal(:, 1); % mono dicklyon@604: file_signal = [file_signal; zeros(fs, 1)]; % pad with a second of silence dicklyon@604: dicklyon@604: dicklyon@604: % make a long test signal by repeating at different levels: dicklyon@604: test_signal = []; dicklyon@604: for dB = dB_list dicklyon@604: test_signal = [test_signal; file_signal * 10^(dB/20)]; dicklyon@604: end dicklyon@604: dicklyon@604: %% dicklyon@623: CF_struct = CARFAC_Design(1, fs); % default design dicklyon@604: dicklyon@604: CF_struct = CARFAC_Init(CF_struct); dicklyon@604: dicklyon@604: [frame_rate, num_frames] = SAI_RunLayered(CF_struct, test_signal); dicklyon@604: dicklyon@604: %% dicklyon@604: png_name_pattern = 'frames/frame%05d.png'; dicklyon@604: MakeMovieFromPngsAndWav(round(frame_rate), png_name_pattern, ... dicklyon@604: wav_fn, ['CARFAC_SAI_movie_', wav_fn(1:end-4), '.mpg']) dicklyon@604: dicklyon@604: %% dicklyon@604: system('rm -r frames'); dicklyon@604: dicklyon@623: