2

我已经在 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。我遇到的一个问题是我不知道如何从 time_delay 函数检索到的延迟音频数据中获取新的延迟音频记录器对象,我需要一个音频记录对象,因为这是播放某些东西的唯一方法。所以,我的问题是:

  • 这是在音频信号中获得所需回声效果的好方法吗?
  • 如果是,那么如何将延迟的音频数据设置为
    audiorecorder 对象?
4

2 回答 2

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);

我已经用三个延迟加上原来的延迟测试了这个,你可以听到一个非常好的回声。

注意:在第三段代码中,如果有一个函数通过将回声效果索引作为参数传递给它来返回带有回声的信号,那就更好了,但为了简单起见,我把它留了下来。

于 2013-03-02T17:33:58.980 回答
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);
于 2016-11-05T15:35:49.157 回答