forked from speechLabBcCuny/messlJsalt15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstub_messlMcIld2Hard.m
54 lines (43 loc) · 1.52 KB
/
stub_messlMcIld2Hard.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
function Y = stub_messlMcIld2Hard(X, N, Ncov, fail, TDOA, fs, allPairs, varargin)
% Multichannel MESSL mask applied to MVDR output initialized from ILD
% between MVDR output and mic 2 (rear-facing)
if ~exist('allPairs', 'var') || isempty(allPairs), allPairs = true; end
% Check that mrfHardCompatExp is not zero
ind = find(strcmp(varargin, 'mrfHardCompatExp'));
if isempty(ind) || (varargin{ind+1} == 0)
error('Must set "mrfHardCompatExp" to nonzero value for stub_messlMcIld2Hard')
end
threshold_db = 12;
maxSup_db = -40;
maxSup = 10^(maxSup_db/20);
tau = tauGrid(0.35, fs, 31);
% MVDR for linear beamforming
mvdr = stub_baselineMvdr(X, N, Ncov, fail, TDOA, fs);
if ~fail(2)
% Compute ILD between MVDR output and mic 2 (rear-facing)
maskInit = maxSup + (1-2*maxSup)*(db(magSq(mvdr(2:end-1,:)) ./ magSq(X(2:end-1,:,2))) > threshold_db);
maskInit = cat(3, maskInit, 1 - maskInit);
else
maskInit = [];
end
% Figure out which mic to use for reference
if allPairs
refMic = 0;
else
if ~fail(2)
refMic = 2;
else
refMic = find(~fail, 1, 'first');
end
if isempty(refMic)
error('All potential reference mics have failed')
end
end
% MESSL for mask
messlOpts = [{'GarbageSrc', 1, 'fixIPriors', 1, 'maskInit', maskInit, 'refMic', refMic} varargin];
[p_lr_iwt params hardMasks] = messlMultichannel(X(2:end-1,:,~fail), tau, 1, messlOpts{:});
z = zeros(1, size(X,2));
mask = [z; squeeze(hardMasks(1,:,:,1)); z];
mask = maxSup + (1 - maxSup) * mask;
% Output spectrogram
Y = mvdr .* mask;