How do you concatenate two audio files horizontally? (.WAV)
16 views (last 30 days)
Show older comments
dan bloodworth
on 12 Mar 2021
Commented: dan bloodworth
on 13 Mar 2021
I'm trying to merge two .WAV files together so that they can be played at the same time.
The problem is they may be of different frequencies as one may be a voice recording. I've learnt how to concat vertically but require some insight into the process of concatenating two separate audios horizontally.
Any help would be appreciated.
0 Comments
Accepted Answer
Walter Roberson
on 13 Mar 2021
Edited: Walter Roberson
on 13 Mar 2021
[wav1, Fs1] = audioread('RockGuitar.wav');
[wav2, Fs2] = audioread('guitartune.wav');
maxFs = max(Fs1, Fs2);
rs1 = resample(wav1, maxFs, Fs1);
rs2 = resample(wav2, maxFs, Fs2);
maxlength = max(size(rs1,1), size(rs2,1));
rs1(end+1:maxlength,:) = 0;
rs2(end+1:maxlength,:) = 0;
horizontal_wav = [rs1, rs2];
size(horizontal_wav)
p = audioplayer(horizontal_wav(:,end-1:end), maxFs);
play(p)
You are going to need more work to be able to play the 3 or 4 channels simultaneously. Note that the channels have not been processed for Dolby Surround or Dolby DTS, but you could use them for front and back speakers, for example.
Remember to pay attention to the fact you are not promised that they are all the same number of channels, so horizontal concatenation like you asked for loses the boundaries between which channel came from which sound.
... And you did not ask to play them as separate stereo channels, and you did not ask that the respective channels be mixed together.
More Answers (0)
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!