From b44ee4ccb9d1615a8dd17df99daeabdf6a761c28 Mon Sep 17 00:00:00 2001 From: sedurCode Date: Tue, 2 Mar 2021 21:59:34 +0000 Subject: [PATCH] fixes for modern matlab --- matlab/CARFAC_Run.m | 2 +- matlab/CARFAC_Run_Segment.m | 2 +- matlab/CARFAC_SAI_hacking.m | 19 +++++++++++-------- matlab/CARFAC_binaural.m | 18 +++++++----------- matlab/CARFAC_hacking.m | 6 +++--- matlab/MakeMovieFromPngsAndWav.m | 8 ++++++-- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/matlab/CARFAC_Run.m b/matlab/CARFAC_Run.m index 76358ac..6735152 100644 --- a/matlab/CARFAC_Run.m +++ b/matlab/CARFAC_Run.m @@ -147,7 +147,7 @@ maxmax = 0; for ear = 1:n_ears hold on - for stage = 1:4; + for stage = 1:4 stage_response = 2^(stage-1) * CF.ears(ear).AGC_state(stage).AGC_memory; plot(stage_response); maxmax = max(maxmax, max(stage_response)); diff --git a/matlab/CARFAC_Run_Segment.m b/matlab/CARFAC_Run_Segment.m index 7671ec4..9a5b372 100644 --- a/matlab/CARFAC_Run_Segment.m +++ b/matlab/CARFAC_Run_Segment.m @@ -94,7 +94,7 @@ BM(k, :, ear) = car_out; state = CF.ears(ear).CAR_state; seg_ohc(k, :, ear) = state.zA_memory; - seg_agc(k, :, ear) = state.zB_memory;; + seg_agc(k, :, ear) = state.zB_memory; end end diff --git a/matlab/CARFAC_SAI_hacking.m b/matlab/CARFAC_SAI_hacking.m index fd89eb3..574a359 100644 --- a/matlab/CARFAC_SAI_hacking.m +++ b/matlab/CARFAC_SAI_hacking.m @@ -19,8 +19,15 @@ %% Test/demo hacking for CARFAC_SAI Matlab stuff: clear variables +clear_old_files = true; + +[status, msg, msgID] = mkdir('frames'); + +if (status && clear_old_files && strcmp(msgID, 'MATLAB:MKDIR:DirectoryExists')) + disp("Clearing old frames"); + delete('frames/*'); +end -system('mkdir frames'); %% @@ -32,8 +39,8 @@ error('wav file not found') end -wav_fn -[file_signal, fs] = wavread(wav_fn); +disp(wav_fn) +[file_signal, fs] = audioread(wav_fn); % if fs == 44100 % file_signal = (file_signal(1:2:end-1, :) + file_signal(2:2:end, :)) / 2; @@ -64,9 +71,5 @@ %% png_name_pattern = 'frames/frame%05d.png'; MakeMovieFromPngsAndWav(round(frame_rate), png_name_pattern, ... - wav_fn, ['CARFAC_SAI_movie_', wav_fn(1:end-4), '.mpg']) - -%% -system('rm -r frames'); - + wav_fn, [wav_fn(1:end-4), '.mpg']) diff --git a/matlab/CARFAC_binaural.m b/matlab/CARFAC_binaural.m index 635d616..80ba1f0 100644 --- a/matlab/CARFAC_binaural.m +++ b/matlab/CARFAC_binaural.m @@ -24,18 +24,16 @@ tic -file_signal = wavread('../test_data/binaural_test.wav'); +file_signal = audioread('../test_data/binaural_test.wav'); file_signal = file_signal(9000+(1:15000)); % trim for a faster test itd_offset = 22; % about 1 ms test_signal = [file_signal((itd_offset+1):end), ... file_signal(1:(end-itd_offset))] / 10; - -CF_struct = CARFAC_Design; % default design - % Run stereo test: -n_ears = 2 -CF_struct = CARFAC_Init(CF_struct, n_ears); +n_ears = 2; +CF_struct = CARFAC_Design(n_ears); % default design with 2 ears +CF_struct = CARFAC_Init(CF_struct); [CF_struct, nap_decim, nap] = CARFAC_Run(CF_struct, test_signal, agc_plot_fig_num); @@ -43,17 +41,15 @@ for ear = 1:n_ears smooth_nap = nap_decim(:, :, ear); figure(ear + n_ears) % Makes figures 3 and 4 - image(63 * ((smooth_nap)' .^ 0.5)) - + % Rectify since nap can go slightly negative. + image(63 * (max(0, smooth_nap)' .^ 0.5)); colormap(1 - gray); end toc % Show resulting data, even though M-Lint complains: -CF_struct -CF_struct.CAR_state -CF_struct.AGC_state +CF_struct; min_max = [min(nap(:)), max(nap(:))] min_max_decim = [min(nap_decim(:)), max(nap_decim(:))] diff --git a/matlab/CARFAC_hacking.m b/matlab/CARFAC_hacking.m index e256e35..a956d33 100644 --- a/matlab/CARFAC_hacking.m +++ b/matlab/CARFAC_hacking.m @@ -28,8 +28,8 @@ if use_wav_file wav_fn = '../test_data/binaural_test.wav'; - wav_fn - file_signal = wavread(wav_fn); + disp(wav_fn) + file_signal = audioread(wav_fn); file_signal = file_signal(:, 1); % Mono test only. else % A tone complex. @@ -93,7 +93,7 @@ end % Show resulting data, even though M-Lint complains: - CF_struct + disp(CF_struct) CF_struct.ears(1).CAR_state CF_struct.ears(1).AGC_state min_max_decim = [min(nap_decim(:)), max(nap_decim(:))] diff --git a/matlab/MakeMovieFromPngsAndWav.m b/matlab/MakeMovieFromPngsAndWav.m index 5141de1..750e5be 100644 --- a/matlab/MakeMovieFromPngsAndWav.m +++ b/matlab/MakeMovieFromPngsAndWav.m @@ -19,13 +19,17 @@ function MakeMovieFromPngsAndWav(frame_rate, png_name_pattern, ... wav_filename, out_filename) -system(['rm "', out_filename, '"']); +if exist(out_filename, 'file') + disp("Deleting existing file: " + out_filename); + delete(out_filename); +end if ~exist(wav_filename, 'file') error('wave file is missing', wav_filename) end -ffmpeg_command = ['/opt/local/bin/ffmpeg' ... +% Expect FFMPEG to be on path for all systems +ffmpeg_command = ['ffmpeg' ... ' -r ' num2str(frame_rate) ... ' -i ' png_name_pattern ... ' -i "' wav_filename ...