Mixing one audio signal to another at a specific point

3 ビュー (過去 30 日間)
dan bloodworth
dan bloodworth 2021 年 3 月 16 日
コメント済み: dan bloodworth 2021 年 3 月 16 日
I'm trying to figure out how to mix one audio signal to another at a specific point.
For example, mixing them together at the same starting point would be a case of
newaudio = a1+a2;
However, I would like to specify the point at which a2 is mixed into a1. For example, being able to mix a2 10 seconds into a1.
Any help would be appreciated.

採用された回答

David K.
David K. 2021 年 3 月 16 日
This is fairly easy at first. You just need to pad the signal a2 with enough zeros to equal 10 seconds. This requires knowledge of the signals sampling fequency.
fs = % your audio fs
timeStart = 10; % time in seconds
a2Pad = [zeros(1,fs*timeStart),a2]; % if a2 is vertical use [zeros(fs*timeStart,1);a2];
newaudio = a1+a2pad
However, this will likely result in the arrays being different sizes so you need to pad the end of the shorter one ( or cut the longer) to be able to add them. This can be done in nearly the same way.
  3 件のコメント
David K.
David K. 2021 年 3 月 16 日
Tried to point this out in the comment on that line in my answer. But this meant that your vectors were oriented different than expected and you had to use this instead:
[zeros(fs*timeStart,1);a2];
I think this should work for you:
% Pad a2
a2 = [zeros(fs*timeStart,1);a2];
sl = min([length(a1), length(a2)]); %Gets the shortest length of a1,a2.
%Ensure both audio is the same length.
a1 = a1(1:sl);
a2 = a2(1:sl);
%Mix
newaudio = a1+a2;
dan bloodworth
dan bloodworth 2021 年 3 月 16 日
Perfect, that works great thank you very much!
I did try the alternative method that you provided however, the padding was being conducted after the shortest lengths had been established and not beforehand. However, applying the vertical approach Before finding the shortest lengths has worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by