-
Notifications
You must be signed in to change notification settings - Fork 49
/
pesq_mex_vec.m
83 lines (73 loc) · 2.66 KB
/
pesq_mex_vec.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
function [ res ] = pesq_mex_vec( reference_sig, degraded_sig, Fs, modeOfOperation )
% Accepts vectors for a mex compiled version of the objective Perceptual Evaluation of Speech Quality measure
%
% Syntax: [ res ] = pesq_mex_vec( reference_sig, degraded_sig, Fs )
%
% Inputs:
% reference_sig - Reference (clean, talker, sender) speech signal
% degraded_sig - Degraded (noisy, listener, receiver) speech signal
% Fs - Sampling Frequency
% modeOfOperation - This optional string argument is used to specify
% whether the PESQ mex function runs in narrowband,
% wideband or both. The possible values are
% 'narrowband', 'wideband' (default) or 'both'.
%
% Outputs:
% res - MOS-LQO result for given modeOfOperation (wideband by default).
% If 'both' is specified as the modeOfOperation then res is a
% column vector of the format [narrowband_result; wideband_result].
%
% See also: pesq2mos.m
% Author: Jacob Donley
% University of Wollongong
% Email: jrd089@uowmail.edu.au
% Copyright: Jacob Donley 2017
% Date: 2 August 2017
% Revision: 0.3 (2 August 2017)
% Revision: 0.2 (16 June 2016)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Just incase this function tries to call within a class folder we should
% create a function handle for this function to use instead
infun = dbstack('-completenames');
funcName = 'pesq_mex';
funcPath = infun.file;
classDirs = getClassDirs(funcPath);
pesq_mex_ = str2func([classDirs funcName]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin < 4
modeOfOperation = 'wideband';
end
switch lower(modeOfOperation)
case 'narrowband'
mOp = {''};
case 'wideband'
mOp = {'+wb'};
case 'both'
mOp = {'';'+wb'};
otherwise
error(['''' modeOfOperation ''' is not a recognised ''modeOfOperation'' value.'])
end
max_val = max(abs([reference_sig(:); degraded_sig(:)]));
tmpref = [tempname '.wav'];
tmpdeg = [tempname '.wav'];
audiowrite( tmpref, reference_sig / max_val, Fs);
audiowrite( tmpdeg, degraded_sig / max_val, Fs);
for m = 1:numel(mOp)
pesqArgs = {['+' num2str(Fs)], ...
mOp{m}, ...
tmpref, ...
tmpdeg};
res(m,:) = pesq_mex_(pesqArgs{~cellfun(@isempty,pesqArgs)});
end
delete( tmpref, tmpdeg );
end
function classDirs = getClassDirs(FullPath)
classDirs = '';
classes = strfind(FullPath,'+');
for c = 1:length(classes)
clas = FullPath(classes(c):end);
stp = strfind(clas,filesep);
classDirs = [classDirs clas(2:stp(1)-1) '.'];
end
end