我想在音频文件上应用TSM(时标修改),并且该音频文件已经被图像加水印,下面给出了执行此操作的代码: 调用TSM函数的代码段
if ok_TSM_w
%TSM with Stftm
alp_t = 1.8;
yW = tsm_using_stftm(y1,alp_t);
audiowrite('tsm_w.wav', yW,Fs);
disp(' TSM of watermaked audio has been done')
end
tsm_using_stftm
代码:
function [xfinal] = tsm_using_stftm(filename, scale)
% Usage:
% tsm_using_stftm('sp01.wav', 1.5)
%[x,Fs] = audioread(filename);
x = filename;
%Fs = freq;
sent_L = length(x);
if scale>2 || scale<0.5
scale = 1.5;
fprintf('scale has to be in [0.5 2].\n scale is reset to be 1.5.\n')
end
L = 256; %frame length
S = L/4; %hop size
m_S = round(S/scale);
overlap = L - S;
Nframe = floor((sent_L-overlap)/S);
a = 0.50;
b = -0.50;
n = 1:L;
win = sqrt(S)/sqrt((4*a^2+2*b^2)*L)*(a+b*cos(2*pi*n/L));
win = win(:);
Nit = 5;
L_recon = round(sent_L/scale);
xfinal = zeros(L_recon,1);
U = sum(win)/(m_S);
k = 1;
kk = 1;
h = waitbar(0,'Please wait...');
for n = 1:Nframe
frm = win.*x(k:k+L-1)/U;
xSTFTM = abs(fft(frm));
if kk+L-1<=L_recon
res = xfinal(kk:kk+L-1);
else
res = [xfinal(kk:L_recon);zeros(L - (L_recon-kk+1),1)];
end
x_recon = iterated_recon(xSTFTM, res, Nit, win);
if (kk+L-1<=L_recon)
xfinal(kk:kk+L-1) = xfinal(kk:kk+L-1) + x_recon;
else
xfinal(kk:L_recon) = xfinal(kk:L_recon) + x_recon(1:L_recon-kk+1);
end
k = k + S;
kk = kk + m_S;
waitbar(n/Nframe, h)
end
close(h)
% outfile = [filename(1:end-4),'_recon.wav'];
% audiowrite(xfinal, Fs, outfile);
function x_recon = iterated_recon(xSTFTM, x_res, Nit, win)
j = sqrt(-1);
for i = 1:Nit
phi = phase(fft(win.*x_res)) + randn(size(x_res))*0.01*pi;
% random phase purturbation will reduce some resonance.
% added by Yang Lu
x = xSTFTM.*exp(j*phi); %M-constraint
x_recon = ifft(x);
x_res = real(x_recon);
end
x_recon = x_res;
但是我遇到一个错误:
使用tsm_using_stftm时出错
输出参数太多。
音频水印添加错误(第378行)
yW = tsm_using_stftm(y1,alp_t);
为什么会出现此错误以及如何解决。 非常感谢您为我提供的帮助,并宽恕有问题的错误。
更新1
尝试使用另一种方法(TSM工具箱)
用于调用TSM函数的代码:
if ok_TSM_wsola
%TSM with waveform similirity overlap add
alpha_tsm = 1.8;
yWSOLA = wsolaTSM(y1,alpha_tsm);
audiowrite('tsm_wsola.wav', yWSOLA,Fs);
disp(' TSM of watermaked audio has been done')
end
和wsolaTSM.m
函数被使用,下面是链接
MATLAB ToolBox
使用方法,它给出了一个错误:
索引超出数组范围。
wsolaTSM错误(第153行) natProg = xC(currAnaWinRan + ...%
Audio_watermarking_sbr_2015中的错误(第378行) yWSOLA = wsolaTSM(y1,alpha_tsm);
请提供有关此问题的任何建议。