Skip to content

Commit

Permalink
google#5 Now matlab scripts run correctly with modern matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
sedurCode committed Feb 11, 2021
1 parent 7196669 commit 416976e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Matlab ASV autosave files
*.asv
# Pychache files
*.pyc
23 changes: 16 additions & 7 deletions matlab/CARFAC_SAI_hacking.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@

clear variables

% Clear old files
if false
if ismac % Code to run on Mac platform
system('rm -r frames');
elseif isunix % Code to run on Linux platform
system('rm -r frames');
elseif ispc % Code to run on Windows platform
system('del frames');
else
disp('Platform not supported');
end
end

system('mkdir frames');

%%
Expand All @@ -32,8 +45,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 +77,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'])

16 changes: 6 additions & 10 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))
image(63 * abs((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
17 changes: 15 additions & 2 deletions matlab/MakeMovieFromPngsAndWav.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@
function MakeMovieFromPngsAndWav(frame_rate, png_name_pattern, ...
wav_filename, out_filename)

system(['rm "', out_filename, '"']);

if ismac
% Code to run on Mac platform
system(['rm "', out_filename, '"']);
elseif isunix
% Code to run on Linux platform
system(['rm "', out_filename, '"']);
elseif ispc
% Code to run on Windows platform
system(['del "', out_filename, '"']);
else
disp('Platform not supported');
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 416976e

Please sign in to comment.