-
Notifications
You must be signed in to change notification settings - Fork 0
/
strans.m
152 lines (135 loc) · 4.74 KB
/
strans.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
% Calculate features in batch.
WIN_SIZE = 2048;
HOP_SIZE = 256;
MIN_F0 = 70;
MAX_F0 = 1000;
WAV_DIR = '/highway/strans_621/waves';
FEAT_DIR = '/highway/strans_621/train';
FEATURES = {
'SpectralCentroid', % 1
'SpectralCrest', % 1
'SpectralDecrease', % 1
'SpectralFlatness', % 1
'SpectralFlux', % 1
'SpectralKurtosis', % 1
'SpectralMfccs', % 13
%'SpectralPitchChroma', % 12
'SpectralRolloff', % 1
'SpectralSkewness', % 1
'SpectralSlope', % 1
'SpectralSpread', % 1
'SpectralTonalPowerRatio', % 1
%%%%%'TimeAcfCoeff',
%%%%%'TimeMaxAcf',
'TimePeakEnvelope', % 2
'TimePredictivityRatio', % 1
'TimeRms', % 1
'TimeStd', % 1
%%%%%'TimeZeroCrossingRate',
'PitchSpectralAcf', % 1
'PitchSpectralHps', % 1
'PitchTimeAcf', % 1
'PitchTimeAmdf', % 1
'PitchTimeAuditory', % 1
'PitchTimeZeroCrossings', % 1
'NoveltyFlux', % 1
'NoveltyLaroche', % 1
'NoveltyHainsworth', % 1
'YIN', % de Cheveigne % 3
'pitchflow', % https://github.com/dpwe/pitchflow % 3
};
addpath('./plugins/yin');
addpath('./plugins/pitchflow');
%%%%%%%%%%%%%%%%%%%%%
stream_infos = [];
wavfiles = dir([WAV_DIR '/*.wav']);
for i = 1:length(wavfiles)
wavfile = wavfiles(i);
[path, base, ext] = fileparts(wavfile.name);
[audiodata, fs] = wavread([WAV_DIR '/' wavfile.name]);
% calculate feat ASCII
featfilename = [FEAT_DIR '/' base '.feat_ascii'];
disp(wavfile.name);
if fs ~= 44100
disp(['WARNING: fs should be 44100, instead of: ', num2str(fs), ' in ', wavfile.name]);
continue;
end
all_features = [];
for j = 1:length(FEATURES)
feat_name = FEATURES{j};
if strcmp(feat_name, 'YIN')
p.minf0 = MIN_F0;
p.maxf0 = MAX_F0;
p.thresh = 0.1;
p.hop = HOP_SIZE;
p.bufsize = WIN_SIZE;
p.sr = fs;
r = yin(audiodata, p);
v = [r.f0; r.ap; r.pwr];
elseif strcmp(feat_name, 'pitchflow')
p.t_win = WIN_SIZE / fs;
p.t_hop = HOP_SIZE / fs;
vall = pitchflow(audiodata, fs, p);
v = pitchflow_collapse(vall);
elseif strcmp(feat_name(1:5), 'Pitch')
name = feat_name(6:end);
[f, t] = ComputePitch(name, audiodata, fs, [], WIN_SIZE, HOP_SIZE);
v = f; % f -- seems to be in log domain
elseif strcmp(feat_name(1:7), 'Novelty')
name = feat_name(8:end);
[d, t, iPeaks] = ComputeNoveltyFunction(name, audiodata, fs, [], WIN_SIZE, HOP_SIZE);
v = d;
else
[v, t] = ComputeFeature(FEATURES{j}, audiodata, fs, [], WIN_SIZE, HOP_SIZE);
end
dim = size(v, 1);
disp(['INFO: dimension of feature ' FEATURES{j} ': ' num2str(dim) ' length: ' num2str(size(v, 2))]);
laf = size(all_features, 2);
lv = size(v, 2);
if laf > lv && laf ~= 0
all_features = [all_features(:,1:lv); v];
elseif laf < lv && laf ~= 0
all_features = [all_features; v(:, 1:laf)];
else
all_features = [all_features; v];
end
this_stream_info = any(isnan(v), 2);
disp(this_stream_info);
end
% calculate delta and delta-delta
dims = size(all_features, 1);
delta_all_features = [zeros(dims, 1) diff(all_features, 1, 2)];
len = size(all_features, 2);
delta_delta_all_features = zeros(dims, len);
delta_delta_all_features(:,1) = all_features(:,2)-all_features(:,1);
for j = 2:(len-1)
delta_delta_all_features(:,j) = (all_features(:,j+1)-all_features(:,j-1))/2;
end
delta_delta_all_features(:,len) = (all_features(:,len)-all_features(:,len-1));
all_features = [all_features;delta_all_features;delta_delta_all_features];
this_stream_infos = any(isnan(all_features), 2);
if i == 1
stream_infos = this_stream_infos;
else
stream_infos = stream_infos | this_stream_infos;
end
all_features(isnan(all_features)) = -1e+10; % hts convention
dims = size(all_features, 1);
size(all_features)
all_features_reshaped = reshape(all_features, [], 1);
dlmwrite(featfilename, all_features_reshaped);
% x2x & htkheader
cmd = ['/usr/local/SPTK/bin/x2x +af ' FEAT_DIR '/' base '.feat_ascii > ' FEAT_DIR '/' base '.feat_f'];
disp(cmd);
system(cmd);
byte_per_frame = 4 * dims;
cmd = ['/highway/strans_621/addhtkheader.pl ' num2str(fs) ' ' ...
num2str(HOP_SIZE) ' ' num2str(byte_per_frame) ' 9 '...
FEAT_DIR '/' base '.feat_f > ' ...
FEAT_DIR '/' base '.feat'];
disp(cmd);
system(cmd);
%%break;
end
stream_infos
dlmwrite([FEAT_DIR '/msdInfo'], stream_infos);