我在Matlab中录制了自己的声音,我打算给它添加一些回声。我想出了一个获得所需回声效果的解决方案:
为了做到这一点,我使用的是Matlab,我基本上完成了以下工作:
recObj = audiorecorder(44100, 16, 2);%sampling rate of 44100Hz, stereo
recordblocking(recObj,length);%record audio for a fixed length duration
y = time_delay(getaudiodata(recObj) , 5000 );%set a delay of 5000 to original sampled audio data
function [ y ] = time_delay ( x , R )
%this function sets a delay to x of R
y = zeros(length(x) + R , 1);
y(R + 1:length(y)) = x(1:length(x));
正如你所看到的,我有一个recObj,我可以用它来播放录制的音频。为了获得录制音频的延迟版本,我使用了getaudiodata(recObj)和我自己的函数time_delay.A我有一个问题是因为我不知道如何从time_delay函数检索到的延迟音频数据中获取新的延迟的audiorecorder对象,我需要一个audiorecord对象,因为这是播放内容的唯一方法。 所以,我的问题是:
答案 0 :(得分:1)
以下是添加两个信号(延迟和未延迟)的代码:
x = getaudiodata(recObj); n1 = 1:size(x,1);%audiodata of original signal
y = time_delay(x , 50000 ); n2 = 1:size(y,1);%audiodata of delayed signal
mixed = sigadd(x,y,n1,n2); %audiodata of mixed signal
mixrecObj = audioplayer(mixed,44100);
play(mixrecObj);
这是sigadd函数:
function [ y,n ] = sigadd( x1,x2,n1,n2 )
%implements y[n] = x1[n] + x2[n]
%y = sum sequence over n wich includes n1 and n2
%x1 = first sequence over n1
%x2 = second sequence over n2
%
n = min(min(n1),min(n2)):max(max(n1),max(n2)); %duration of y(n)
y1 = zeros(1,length(n)); y2 = y1;
y1(find((n >= min(n1))&(n <= max(n1)) == 1)) = x1;
y2(find((n >= min(n2))&(n <= max(n2)) == 1)) = x2;
y = y1 + y2;
end
这很有效,但不足以获得真实的回声效果。为了达到这个目的,我们必须这样做 创建更多延迟信号(当然有不同的延迟),然后将它们全部添加,如下所示:
x = getaudiodata(recObj); n1 = 1:size(x,1);
y = tim_delay(x , 5000 ); n2 = 1:size(y,1);
s = time_delay(x , 4000 ); n3 = 1:size(s,1);
d = time_delay(x , 3000 ); n4 = 1:size(d,1);
mixed1 = sigadd(s,d,n3,n4);n5 = 1:size(mixed1,2);
mixed2 = sigadd(x,y,n1,n2);n6 = 1:size(mixed2,2);
totmixed = sigadd(mixed1,mixed2,n5,n6);
mixrecObj = audioplayer(totmixed,44100);
play(mixrecObj);
我已经用三个延迟加上原始测试来测试这个,你可以听到一个非常好的回声。
注意:在第三段代码中,如果有一个函数通过将回声效果索引作为参数传递给它来返回带回声的信号会更好,但是我离开了为了简单起见,这样做。
答案 1 :(得分:0)
获得更逼真的回声 在每个回声中,必须减少回声的音量。 它可以实现
y=y/5;
完整的修改示例,以实现减少每个回声的音量
recObj = audiorecorder(44100, 16, 2);%sampling rate of 44100Hz, stereo
disp('Start speaking.')
%recordblocking(recObj, 5);
recordblocking(recObj,5);%record audio for a fixed length duration
disp('End of Recording.');
x = getaudiodata(recObj);
plot(x);
hold on;
x = getaudiodata(recObj); n1 = 1:size(x,1);
s = time_delay(x , 0 ); n3 = 1:size(s,1); %original
plot(s,'b');
d = time_delay(x , 20000 ); n4 = 1:size(d,1);%delayed by 20000
d=d/1.5;
plot(d,'y');
y = time_delay(x , 40000 ); n2 = 1:size(y,1);% delyaed by 50000
y=y/2;
plot(y,'g');
z = time_delay(x , 60000 ); n8 = 1:size(z,1);% delyaed by 70000
z=z/4;
plot(z,'r');
mixed1 = sigadd(s,d,n3,n4);n5 = 1:size(mixed1,2);
mixed2 = sigadd(y,z,n2,n8);n6 = 1:size(mixed2,2);
totmixed = sigadd(mixed1,mixed2,n5,n6);
mixrecObj = audioplayer(totmixed,44100);
%mixrecObj = audioplayer(mixed1,44100);
play(mixrecObj);