comparison toolboxes/AudioInpaintingToolbox/Utils/evaluation/exclude_audioQualityMeasures.m @ 138:56d719a5fd31 ivand_dev

Audio Inpaintin Toolbox
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Thu, 21 Jul 2011 14:27:47 +0100
parents
children
comparison
equal deleted inserted replaced
137:9207d56c5547 138:56d719a5fd31
1 function [SNRx, PSM, PSMt, PESQ_MOS, EAQUAL_ODG, EAQUAL_DIX] = ...
2 audioQualityMeasures(xRef,xTest,fs,options)
3 %
4 %
5 % Usage:
6 %
7 %
8 % Inputs:
9 % -
10 % -
11 % -
12 % -
13 % -
14 % -
15 % -
16 % -
17 %
18 % Outputs:
19 % -
20 % -
21 % -
22 % -
23 %
24 % Note that the CVX library is needed.
25 %
26 % -------------------
27 %
28 % Audio Inpainting toolbox
29 % Date: June 28, 2011
30 % By Valentin Emiya, Amir Adler, Maria Jafari
31 % This code is distributed under the terms of the GNU Public License version 3 (http://www.gnu.org/licenses/gpl.txt).
32 % Computes a series of audio quality measures
33 %
34 % Usage:
35 % [PSM,PSMt] = ...
36 % audioQualityMeasures(xRef,xTest,fs,options)
37 %
38 % Inputs:
39 % - xRef: reference signal
40 % - xTest: test signal (to be compared to xRef)
41 % - fs: sampling frequency
42 % - optional parameters [default]:
43 % - options.ENABLE_PEMOQ: flag to use PEMO-Q or not [true]
44 % - options.pemoQExec: name of PEMO-Q executable ['"./PEMO-Q v1.1.2 demo/audioqual_demo.exe"']
45 % - options.PESQExec: name of PESQ executable [''./PESQ/pesq'']
46 % - options.EAQUALExec: name of EAQUAL (PEAQ) executable ['./EAQUAL/eaqual.exe']
47 %
48 % Note that PEMO-Q and EAQUAL programs are Windows executable and that
49 % under unix, they can be used by means of wine (Windows Emulator). One
50 % just have to have wine installed.
51 %
52 % Valentin Emiya, INRIA, 2010.
53
54
55 %% default options
56 defaultOptions.pemoQExec = '"C:/Program Files/PEMO-Q v1.2/audioqual.exe"'; % Full licensed version
57 if isempty(dir(defaultOptions.pemoQExec))
58 defaultOptions.pemoQExec = '"./PEMO-Q v1.1.2 demo/audioqual_demo.exe"'; % Demo version
59 end
60 defaultOptions.ENABLE_PEMOQ = true;
61 defaultOptions.PESQExec = './PESQ/pesq';
62
63 if ispc
64 defaultOptions.EAQUALExec = './EAQUAL/eaqual.exe';
65 else % if unix, use wine
66 defaultOptions.EAQUALExec = 'wine ./EAQUAL/eaqual.exe';
67 defaultOptions.pemoQExec = ['wine ' defaultOptions.pemoQExec];
68 end
69
70 if nargin<4
71 options = defaultOptions;
72 else
73 names = fieldnames(defaultOptions);
74 for k=1:length(names)
75 if ~isfield(options,names{k}) || isempty(options.(names{k}))
76 options.(names{k}) = defaultOptions.(names{k});
77 end
78 end
79 end
80
81 if ~ischar(xRef) && ~ischar(xTest) && length(xRef)~=length(xTest)
82 warning('EVAL:LENGTH','Different lengths');
83 L = min(length(xRef),length(xTest));
84 xRef = xRef(1:L);
85 xTest = xTest(1:L);
86 end
87
88 if ischar(xRef)
89 refFile = xRef;
90 sRef = wavread(refFile);
91 else
92 refFile = [tempname '.wav'];
93 sRef = xRef;
94 wavwrite(xRef,fs,refFile);
95 end
96 if ischar(xTest)
97 testFile = xTest;
98 sTest = wavread(testFile);
99 else
100 testFile = [tempname '.wav'];
101 sTest = xTest;
102 wavwrite(xTest,fs,testFile);
103 end
104
105
106 SNRx = SNR(sRef,sTest);
107
108 try
109 % if ispc && options.ENABLE_PEMOQ
110 if options.ENABLE_PEMOQ
111 %% PEMO-Q
112 [PSM,PSMt] = aux_pemoq(refFile,testFile,options);
113 else
114 warning('audioQualityMeasures:noPQ','PEMO-Q is not available (requires Windows plateform)')
115 PSM = NaN;
116 PSMt = NaN;
117 end
118
119 %% PESQ
120 PESQ_MOS = aux_pesq(refFile,testFile,options);
121
122 %% EAQUAL (PEAQ)
123 [EAQUAL_ODG, EAQUAL_DIX] = aux_eaqual(refFile,testFile,options);
124
125 if ~ischar(xRef)
126 %% Delete temporary files
127 delete(refFile);
128 end
129 if ~ischar(xTest)
130 delete(testFile);
131 end
132
133 catch
134 if ~ischar(xRef)
135 %% In case of error, delete the temporary files
136 delete(refFile);
137 end
138 if ~ischar(xTest)
139 delete(testFile);
140 end
141 rethrow;
142 end
143
144
145 return
146
147 function [PSM,PSMt] = aux_pemoq(refFile,testFile,options)
148 if ~isempty(findstr(options.pemoQExec, 'demo'))
149 fprintf('To unlock PEMO-Q demo, please enter the PIN shown in the new window\n');
150 end
151 [dum, pemo] = system(sprintf('%s %s %s [] [] 0 0 0', options.pemoQExec, refFile, testFile));
152 pemo = regexp(pemo, 'PSM.? = \d*.\d*', 'match');
153 PSM = str2double(cell2mat(regexp(pemo{1},'\d+.?\d*', 'match')));
154 PSMt = str2double(cell2mat(regexp(pemo{2},'\d+.?\d*', 'match')));
155
156 return
157
158 function PESQ_MOS = aux_pesq(refFile,testFile,options)
159 [dum fs] = wavread(refFile,'size');
160 if ~ismember(fs,[8000 16000])
161 error('audioQualityMeasures:badFs',...
162 '8kHz or 16 kHz sampling frequency required for PESQ');
163 end
164 [dum,s] = system(sprintf('%s +%d %s %s',options.PESQExec,fs,refFile,testFile));
165 PESQ_MOS = regexp(s, 'Prediction : PESQ_MOS = \d*.\d*', 'match');
166 PESQ_MOS = str2double(PESQ_MOS{end}(length('Prediction : PESQ_MOS = ')+1:end));
167 return
168
169 function [EAQUAL_ODG, EAQUAL_DIX] = aux_eaqual(refFile,testFile,options)
170 [dum fs] = wavread(refFile,'size');
171 DELETE_FLAG = false;
172 if fs<44100
173 warning('EAQUAL:BAD_FS',...
174 'Sampling frequency is too low for Eaqual (<44.1kHz).\nResampling first (result not relevant)');
175 DELETE_FLAG = true;
176
177 x = wavread(refFile);
178 fsEaqual = 48000;
179 x = resample(x,fsEaqual,fs);
180 refFile = [tempname '.wav'];
181 wavwrite(x,fsEaqual,refFile);
182
183 x = wavread(testFile);
184 fsEaqual = 48000;
185 x = resample(x,fsEaqual,fs);
186 testFile = [tempname '.wav'];
187 wavwrite(x,fsEaqual,testFile);
188
189 fs = fsEaqual;
190 end
191
192 [dum,s] = system(sprintf('%s -fref %s -ftest %s -srate %d',options.EAQUALExec,refFile,testFile,fs));
193
194 EAQUAL_ODG = regexp(s, 'Resulting ODG:\t.?\d*(\.\d*)?', 'match');
195 EAQUAL_ODG = str2double(EAQUAL_ODG{end}(length('Resulting ODG: ')+1:end));
196 EAQUAL_DIX = regexp(s, 'Resulting DIX:\t.?\d*(\.\d*)?', 'match');
197 EAQUAL_DIX = str2double(EAQUAL_DIX{end}(length('Resulting DIX: ')+1:end));
198
199 if DELETE_FLAG
200 delete(refFile);
201 delete(testFile);
202 end
203 return