我已经实现了噪声门以使语音wav文件中的噪声(不包括语音)变为静音,但是有五个参数(由主程序发出)我必须自己填充参数。我有疑问,我的程序如何在每次输入具有不同噪声特性的语音wav文件时给出建议参数? 我在想什么:我可以使用语音wav文件幅度的平均值来获得建议参数吗?
function n = noisegate( x, Fs, AT, RT, holdtime, ltrhold, utrhold)
% ------- Parameter Input ---------
% x - Input file
% Fs - sample frequency
% AT - Attack time
% RT - Release time
% ltrhold - lower threshold
% utrhold - upper threshold
att = round(AT*Fs); %calculate attack time in samples
rel = round(RT*Fs); %calculate release time in samples
ht = round(holdtime*Fs); %calculate hold time in samples
g = zeros(size(x)); %allocate an array for gain
%initialize low and high threshold counters
ltcnt = 0;
utcnt = 0;
%Calculate RMS Peak
%time average for peak measurement
tav = 0.2;
TAV =1 - exp(-2.2/(Fs*tav));
xrms(1) = 0;
for n = 2 : length(x)
xrms(n) = (1-TAV)*xrms(n-1) + TAV*x(n)^2;
if (xrms(n) <= ltrhold || (xrms(n) < utrhold && ltcnt > 0))
ltcnt = ltcnt + 1;
utcnt = 0;
if (ltcnt > ht), %hold time of low threshold exceeded
if(ltcnt > (ht + rel)) %hold and release time exceeded
%set gain to zero to completely fade out the sound
g(n) = 0;
else
%fade out the sound here
g(n) = 1 - (ltcnt - ht)/rel;
end
elseif (ltcnt < ht & (ltcnt == n))
g(n) = 0;
else
g(n) = 1;
end
elseif (xrms(n) > utrhold || (xrms(n) > ltrhold && utcnt > 0))
ltcnt = 0;
utcnt = utcnt + 1;
if(utcnt > ht)
%maximum attack and hold time exceeded
if(utcnt > (ht + att))
%set gain to 1
g(n) = 1;
else
%applay gain smoothening
g(n) = (utcnt - ht)/att;
end
else
g(n) = 0;
end
end
end
n = x.*g;
end