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 i
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.
The solution is this:
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