Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 Now matlab scripts run correctly with modern matlab #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +22 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior of previous code: the previous code always deletes all the images but this one won't delete the images after the computation. Maybe let's move the deletion to the end of the computation?


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'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use something like fileparts to bring back the CARFAC_SAI_movie_ prefix? https://www.mathworks.com/help/matlab/ref/fileparts.html


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));
Comment on lines +44 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dick: should we rectify NAP like this or shift it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw Dick's comment in another thread, so this should be OK.

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