加入多首曲目时匹配音频持续时间 [英] Match audio duration when joining multiple tracks

查看:71
本文介绍了加入多首曲目时匹配音频持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将音轨组合在一起的程序,当前的系统是我可以编写两个音轨并使它们同时播放.我遇到的问题是,它只能在最短的轨道上播放,例如:

I have a program that combines audio tracks together, the current system I have is that I can write two audio tracks and make them play simultaneously. The problem I am having is that it only plays for the duration of the shortest track, so for instance:

曲目1的持续时间= 2:00

Track 1's duration = 2:00

Track 2的持续时间= 1:12

Track 2's duration = 1:12

仅当我要为2:00(全长)播放时,它才为1:12播放.解决此问题的最佳方法是什么?

It will only play for 1:12 when I want it to play for 2:00 (the whole length). What's the best way to go about solving this issue?

到目前为止,我的解决方案是

My solution so far:

length = min([length(s1), length(s2)]);

s1 = s1(1:length);
s2 = s2(1:length);
s3 = s1 + s2;

推荐答案

首先不要使用函数名称"length"来定义新变量,您将无法在下一条语句中将其用作函数. 其次,当您播放多首曲目时,您希望一开始就可以进行某种同步,因此我为您添加了此选项.

First of all don't use function name "length" as to define new variable, You will not be able to use it as function in the next statement. Second, when you play multiple tracks you want to be able to do some kind of sync in the beginning, so i added for you this option.

解决方案是这样的:

s1=[ 0.5, 0.2, 0.2, 0.1 ];
s2=[ 0.1, 0.4 ];

s1_pad_delay=8; s1_pad_after=5;
s2_pad_delay=4; s2_pad_after=3;

s1_len=s1_pad_delay+length(s1)+s1_pad_after;
s2_len=s2_pad_delay+length(s2)+s2_pad_after;
mix_len=max(s1_len,s2_len);

s1_padded=[ zeros(1,s1_pad_delay), s1, zeros(1,mix_len-length(s1)-s1_pad_delay) ];
s2_padded=[ zeros(1,s2_pad_delay), s2, zeros(1,mix_len-length(s2)-s2_pad_delay) ];

mix=s1_padded+s2_padded

这篇关于加入多首曲目时匹配音频持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆