-
Notifications
You must be signed in to change notification settings - Fork 6
/
make_autoco_movie.m
106 lines (78 loc) · 2.26 KB
/
make_autoco_movie.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function make_autoco_movie(d,sr,moviename,name,slowdown)
% make_autoco_movie(d,sr,moviename,name,slowdown)
% Make a movie of the subband autocorrelation for the specified
% sound. Slow down by factor.
% 2013-05-27 Dan Ellis [email protected]
if nargin < 4; name = '<unk>'; end
if nargin < 5; slowdown = 1.0; end
if exist('pvoc') ~= 2
% for slowing down the sound
addpath('~/projects/pvoc');
end
targetsr = 8000;
if sr ~= targetsr
d = resample(d,targetsr,sr);
sr = targetsr;
end
%frameRate = 25;
%mvo = avifile(moviename,'fps',frameRate);
%mvo = addframe(mvo,framecdata);
MakeQTMovie('start',moviename);
params.wintime = 0.025;
params.hoptime = 0.010;
params.sr = sr;
params.maxlags = round(params.wintime * params.sr);
params.fbank = sbpca_filterbank(params.sr);
[subbands,freqs] = sbpca_subbands(d,sr,params);
autocos = sbpca_autoco(subbands, params);
framerate = 25;
frametime = 1/framerate;
dur = length(d)/sr;
nframes = floor(dur*slowdown/frametime);
subplot(211)
specgram(d,256,sr,224);
caxis([-60 0]+max(caxis()));
tw = 2.0;
ax = axis();
fmin = ax(3);
fmax = ax(4);
hold on;
redline = plot([0 0], [fmin fmax], '-r');
hold off;
%rgcolor();
gcolor();
tt = [0:size(autocos,1)-1]/sr;
ff = 1:size(autocos,2);
for frame = 1:nframes
ftime = (frame-1)*frametime/slowdown;
aframe = 1+round(ftime/params.hoptime);
if aframe < size(autocos,3)
subplot(212);
imgsc(tt,ff,squeeze(autocos(:,:,aframe))');
xx = 1:3:length(ff);
set(gca, 'YTick', xx);
set(gca, 'YTickLabel', round(freqs(xx)));
xlabel('lag / s');
ylabel('freq / Hz');
title(sprintf('%s - %.2f', name, ftime), 'interpreter', 'none');
subplot(211)
axis([ftime - tw, ftime + tw, fmin, fmax]);
hold on;
delete(redline);
redline = plot([ftime ftime], [fmin fmax], '-r');
hold off;
MakeQTMovie('addfigure');
end
end
MakeQTMovie('framerate', framerate);
if slowdown ~= 1
nfft = 256;
d = pvoc(d,1/slowdown,nfft);
end
MakeQTMovie('addsound', d, sr);
MakeQTMovie('finish');
lastdot = [max(find(moviename=='.')), length(moviename)+1];
mp4name = [moviename(1:lastdot(1)-1), '.mp4'];
disp(['ffmpeg -i ',moviename, ...
' -vcodec libx264 -preset fast -crf 28 -threads ' ...
'0 -acodec libfaac -ac 1 -ar 16000 -ab 64k ', mp4name]);