How do you concatenate two audio files horizontally? (.WAV)

16 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Mär. 2021
Bearbeitet: Walter Roberson am 13 Mär. 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)
ans = 1×2
3195904 3
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.
  5 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by