Skip to content

Commit b44ee4c

Browse files
committed
fixes for modern matlab
1 parent 7af6b7e commit b44ee4c

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

matlab/CARFAC_Run.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
maxmax = 0;
148148
for ear = 1:n_ears
149149
hold on
150-
for stage = 1:4;
150+
for stage = 1:4
151151
stage_response = 2^(stage-1) * CF.ears(ear).AGC_state(stage).AGC_memory;
152152
plot(stage_response);
153153
maxmax = max(maxmax, max(stage_response));

matlab/CARFAC_Run_Segment.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
BM(k, :, ear) = car_out;
9595
state = CF.ears(ear).CAR_state;
9696
seg_ohc(k, :, ear) = state.zA_memory;
97-
seg_agc(k, :, ear) = state.zB_memory;;
97+
seg_agc(k, :, ear) = state.zB_memory;
9898
end
9999
end
100100

matlab/CARFAC_SAI_hacking.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
%% Test/demo hacking for CARFAC_SAI Matlab stuff:
2020

2121
clear variables
22+
clear_old_files = true;
23+
24+
[status, msg, msgID] = mkdir('frames');
25+
26+
if (status && clear_old_files && strcmp(msgID, 'MATLAB:MKDIR:DirectoryExists'))
27+
disp("Clearing old frames");
28+
delete('frames/*');
29+
end
2230

23-
system('mkdir frames');
2431

2532
%%
2633

@@ -32,8 +39,8 @@
3239
error('wav file not found')
3340
end
3441

35-
wav_fn
36-
[file_signal, fs] = wavread(wav_fn);
42+
disp(wav_fn)
43+
[file_signal, fs] = audioread(wav_fn);
3744

3845
% if fs == 44100
3946
% file_signal = (file_signal(1:2:end-1, :) + file_signal(2:2:end, :)) / 2;
@@ -64,9 +71,5 @@
6471
%%
6572
png_name_pattern = 'frames/frame%05d.png';
6673
MakeMovieFromPngsAndWav(round(frame_rate), png_name_pattern, ...
67-
wav_fn, ['CARFAC_SAI_movie_', wav_fn(1:end-4), '.mpg'])
68-
69-
%%
70-
system('rm -r frames');
71-
74+
wav_fn, [wav_fn(1:end-4), '.mpg'])
7275

matlab/CARFAC_binaural.m

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,32 @@
2424

2525
tic
2626

27-
file_signal = wavread('../test_data/binaural_test.wav');
27+
file_signal = audioread('../test_data/binaural_test.wav');
2828
file_signal = file_signal(9000+(1:15000)); % trim for a faster test
2929

3030
itd_offset = 22; % about 1 ms
3131
test_signal = [file_signal((itd_offset+1):end), ...
3232
file_signal(1:(end-itd_offset))] / 10;
33-
34-
CF_struct = CARFAC_Design; % default design
35-
3633
% Run stereo test:
37-
n_ears = 2
38-
CF_struct = CARFAC_Init(CF_struct, n_ears);
34+
n_ears = 2;
35+
CF_struct = CARFAC_Design(n_ears); % default design with 2 ears
36+
CF_struct = CARFAC_Init(CF_struct);
3937

4038
[CF_struct, nap_decim, nap] = CARFAC_Run(CF_struct, test_signal, agc_plot_fig_num);
4139

4240
% Display results for 2 ears:
4341
for ear = 1:n_ears
4442
smooth_nap = nap_decim(:, :, ear);
4543
figure(ear + n_ears) % Makes figures 3 and 4
46-
image(63 * ((smooth_nap)' .^ 0.5))
47-
44+
% Rectify since nap can go slightly negative.
45+
image(63 * (max(0, smooth_nap)' .^ 0.5));
4846
colormap(1 - gray);
4947
end
5048

5149
toc
5250

5351
% Show resulting data, even though M-Lint complains:
54-
CF_struct
55-
CF_struct.CAR_state
56-
CF_struct.AGC_state
52+
CF_struct;
5753
min_max = [min(nap(:)), max(nap(:))]
5854
min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]
5955

matlab/CARFAC_hacking.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
if use_wav_file
2929
wav_fn = '../test_data/binaural_test.wav';
3030

31-
wav_fn
32-
file_signal = wavread(wav_fn);
31+
disp(wav_fn)
32+
file_signal = audioread(wav_fn);
3333
file_signal = file_signal(:, 1); % Mono test only.
3434
else
3535
% A tone complex.
@@ -93,7 +93,7 @@
9393
end
9494

9595
% Show resulting data, even though M-Lint complains:
96-
CF_struct
96+
disp(CF_struct)
9797
CF_struct.ears(1).CAR_state
9898
CF_struct.ears(1).AGC_state
9999
min_max_decim = [min(nap_decim(:)), max(nap_decim(:))]

matlab/MakeMovieFromPngsAndWav.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
function MakeMovieFromPngsAndWav(frame_rate, png_name_pattern, ...
2020
wav_filename, out_filename)
2121

22-
system(['rm "', out_filename, '"']);
22+
if exist(out_filename, 'file')
23+
disp("Deleting existing file: " + out_filename);
24+
delete(out_filename);
25+
end
2326

2427
if ~exist(wav_filename, 'file')
2528
error('wave file is missing', wav_filename)
2629
end
2730

28-
ffmpeg_command = ['/opt/local/bin/ffmpeg' ...
31+
% Expect FFMPEG to be on path for all systems
32+
ffmpeg_command = ['ffmpeg' ...
2933
' -r ' num2str(frame_rate) ...
3034
' -i ' png_name_pattern ...
3135
' -i "' wav_filename ...

0 commit comments

Comments
 (0)