Skip to content

Commit

Permalink
fixes for modern matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
sedurCode committed Mar 2, 2021
1 parent 598551e commit 5ceca36
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion matlab/CARFAC_Run.m
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion matlab/CARFAC_Run_Segment.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 11 additions & 8 deletions matlab/CARFAC_SAI_hacking.m
Original file line number Diff line number Diff line change
Expand Up @@ -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');

%%

Expand All @@ -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;
Expand Down Expand Up @@ -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'])

18 changes: 7 additions & 11 deletions matlab/CARFAC_binaural.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,32 @@

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);

% Display results for 2 ears:
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(:))]

6 changes: 3 additions & 3 deletions matlab/CARFAC_hacking.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(:))]
Expand Down
8 changes: 6 additions & 2 deletions matlab/MakeMovieFromPngsAndWav.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down

0 comments on commit 5ceca36

Please sign in to comment.