matlab 3D音效

 

  相较于头部函数,该算法计算量小,转载请标注原链接!

function ITD_ILD
% 读取数据
[d,sr] = audioread('C:\Users\Desktop\zyy\test\原始\DeepSide.flac');
delay_time = 512;
attention = 0.92;
% 交替处会有明显的痕迹,需要进行淡入和谈出处理
w_N = 512;
window = hann(w_N);
% 每次变换方向的窗口长度
framesize = 200000;
len = floor(size(d) / (framesize));
% 第一个frameszie单独处理,col 1 延迟并且衰减,让人感觉声音从col 2方向发出
col = 1;
d(1:framesize,col) = attention*[zeros(delay_time ,1)' d(1:framesize-delay_time ,col)']';
% 开始col 1延迟了512个点,为确保col 1和col 2同步,需要快进col 1 512个点。col 1 和 col 2同步,col 1 不再延迟和衰减,此时让人感觉声音从中间发出,需要谈入谈出进行平滑。
d(framesize-w_N/2+1:framesize,col) =  d(framesize-w_N/2+1:framesize,col).*window(w_N/2+1:w_N);
d(framesize+1:framesize+w_N/2,col) = d(framesize+1:framesize+w_N/2,col).*window(1:w_N/2);
% 中间重复数据
for i = 2:2:len-1
% col 1 和 col 2交替延迟衰减
    if col == 2
        col = 1;
    else 
        col = 2;
    end
    d(i*framesize+w_N+1+w_N/2:(i+1)*framesize,col) = attention*d(i*framesize+1+w_N/2:(i+1)*framesize-w_N,col);
% framsize 开头256个点做谈出和谈出处理,淡出处理作为延迟填充的256个点
    d(i*framesize+w_N/2+1:i*framesize+w_N,col) = (attention*d(i*framesize+1:i*framesize+w_N/2,col)).*window(w_N/2+1:w_N);
    d(i*framesize+w_N+1:i*framesize+w_N+w_N/2,col) = (attention*d(i*framesize+1:i*framesize+w_N/2,col)).*window(1:w_N/2);
% 前一个framsize的末尾256个点做谈出和谈入处理,谈入处理作为延迟填充的256个点
    d(i*framesize+1:i*framesize+w_N/2,col) = (attention*d(i*framesize-w_N/2+1:i*framesize,col)).*window(1:w_N/2);
    d(i*framesize-w_N/2+1:i*framesize,col) = attention*d(i*framesize-w_N/2+1:i*framesize,col).*window(w_N/2+1:w_N);
% col同步处理
    d((i+1)*framesize-w_N/2+1:(i+1)*framesize,col) =  d((i+1)*framesize-w_N/2+1:(i+1)*framesize,col).*window(w_N/2+1:w_N);
    d((i+1)*framesize+1:(i+1)*framesize+w_N/2,col) = d((i+1)*framesize+1:(i+1)*framesize+w_N/2,col).*window(1:w_N/2);
    
end
audiowrite('C:\Users\Desktop\moving_DeepSide_delay_sourround.wav',d,sr)

  

posted @ 2021-01-27 17:30  繁华如梦个人笔记  阅读(179)  评论(0编辑  收藏  举报