-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPQevalAudio_fn.m
177 lines (140 loc) · 4.19 KB
/
PQevalAudio_fn.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
function [ODG, MOVB] = PQevalAudio_fn (Fref, Ftest, StartS, EndS)
% Perceptual evaluation of audio quality.
% - StartS shifts the frames, so that the first frame starts at that sample.
% This is a two element array, one element for each input file. If StartS is
% a scalar, it applies to both files.
% - EndS marks the end of data. The processing stops with the last frame that
% contains that sample. This is a two element array, one element for each
% input file. If EndS is as scalar, it applies to both files.
% P. Kabal $Revision: 1.2 $ $Date: 2004/02/05 04:25:24 $
% Globals (to save on copying in/out of functions)
global MOVC PQopt
% Analysis parameters
NF = 2048;
Nadv = NF / 2;
Version = 'Basic';
% Options
PQopt.ClipMOV = 0;
PQopt.PCinit = 0;
PQopt.PDfactor = 1;
PQopt.Ni = 1;
PQopt.DelayOverlap = 1;
PQopt.DataBounds = 1;
PQopt.EndMin = NF / 2;
%addpath ('CB', 'MOV', 'Misc', 'Patt');
if (nargin < 3)
StartS = [0, 0];
end
if (nargin < 4)
EndS = [];
end
% Get the number of samples and channels for each file
WAV(1) = PQwavFilePar (Fref);
WAV(2) = PQwavFilePar (Ftest);
% Reconcile file differences
PQ_CheckWAV (WAV);
if (WAV(1).Nframe ~= WAV(2).Nframe)
disp ('>>> Number of samples differ: using the minimum');
end
% Data boundaries
Nchan = WAV(1).Nchan;
[StartS, Fstart, Fend] = PQ_Bounds (WAV, Nchan, StartS, EndS, PQopt);
% Number of PEAQ frames
Np = Fend - Fstart + 1;
if (PQopt.Ni < 0)
PQopt.Ni = ceil (Np / abs(PQopt.Ni));
end
% Initialize the MOV structure
MOVC = PQ_InitMOVC (Nchan, Np);
% Initialize the filter memory
Nc = PQCB (Version);
for (j = 0:Nchan-1)
Fmem(j+1) = PQinitFMem (Nc, PQopt.PCinit);
end
is = 0;
for (i = -Fstart:Np-1)
% Read a frame of data
xR = PQgetData (WAV(1), StartS(1) + is, NF); % Reference file
xT = PQgetData (WAV(2), StartS(2) + is, NF); % Test file
is = is + Nadv;
% Process a frame
for (j = 0:Nchan-1)
[MOVI(j+1), Fmem(j+1)] = PQeval (xR(j+1,:), xT(j+1,:), Fmem(j+1));
end
if (i >= 0)
% Move the MOV precursors into a new structure
PQframeMOV (i, MOVI); % Output is in global MOVC
% Print the MOV precursors
% if (PQopt.Ni ~= 0 & mod (i, PQopt.Ni) == 0)
% PQprtMOVCi (Nchan, i, MOVC);
% end
end
end
% Time average of the MOV values
if (PQopt.DelayOverlap)
Nwup = Fstart;
else
Nwup = 0;
end
MOVB = PQavgMOVB (MOVC, Nchan, Nwup);
% Neural net
ODG = PQnNet (MOVB);
% Summary printout
%PQprtMOV (MOVB, ODG);
%----------
function PQ_CheckWAV (WAV)
% Check the file parameters
Fs = 48000;
if (WAV(1).Nchan ~= WAV(2).Nchan)
error ('>>> Number of channels differ');
end
if (WAV(1).Nchan > 2)
error ('>>> Too many input channels');
end
if (WAV(1).Nframe ~= WAV(2).Nframe)
disp ('>>> Number of samples differ');
end
if (WAV(1).Fs ~= WAV(2).Fs)
error ('>>> Sampling frequencies differ');
end
if (WAV(1).Fs ~= Fs)
error ('>>> Invalid Sampling frequency: only 48 kHz supported');
end
%----------
function [StartS, Fstart, Fend] = PQ_Bounds (WAV, Nchan, StartS, EndS, PQopt)
PQ_NF = 2048;
PQ_NADV = (PQ_NF / 2);
if (isempty (StartS))
StartS(1) = 0;
StartS(2) = 0;
elseif (length (StartS) == 1)
StartS(2) = StartS(1);
end
Ns = WAV(1).Nframe;
% Data boundaries (determined from the reference file)
if (PQopt.DataBounds)
Lim = PQdataBoundary (WAV(1), Nchan, StartS(1), Ns);
fprintf ('PEAQ Data Boundaries: %ld (%.3f s) - %ld (%.3f s)\n', ...
Lim(1), Lim(1)/WAV(1).Fs, Lim(2), Lim(2)/WAV(1).Fs);
else
Lim = [Starts(1), StartS(1) + Ns - 1];
end
% Start frame number
Fstart = floor ((Lim(1) - StartS(1)) / PQ_NADV);
% End frame number
Fend = floor ((Lim(2) - StartS(1) + 1 - PQopt.EndMin) / PQ_NADV);
%----------
function MOVC = PQ_InitMOVC (Nchan, Np)
MOVC.MDiff.Mt1B = zeros (Nchan, Np);
MOVC.MDiff.Mt2B = zeros (Nchan, Np);
MOVC.MDiff.Wt = zeros (Nchan, Np);
MOVC.NLoud.NL = zeros (Nchan, Np);
MOVC.Loud.NRef = zeros (Nchan, Np);
MOVC.Loud.NTest = zeros (Nchan, Np);
MOVC.BW.BWRef = zeros (Nchan, Np);
MOVC.BW.BWTest = zeros (Nchan, Np);
MOVC.NMR.NMRavg = zeros (Nchan, Np);
MOVC.NMR.NMRmax = zeros (Nchan, Np);
MOVC.PD.Pc = zeros (1, Np);
MOVC.PD.Qc = zeros (1, Np);
MOVC.EHS.EHS = zeros (Nchan, Np);