Playing sound using 4 channels or converting 4 channels to two
Show older comments
I am trying to mix two wav sound files (lets say two different songs) that have two chanels each. I then want to make a single sound file that has two chanels and has both those songs on it playing at the same time. I managed to achive this however my output mix file has 4 chanels which doesnt let me play the sound using audioplayer. I also tried using 1 chanel from each original file which lets me play the song as it has two chanels however i can only hear 1 song on each side of my headphones. My goal is to either find a method to play the 4 chanels song or make it so i can convert the 4 chanels in to two and still hear the mixed songs in both sides of my headset.
I have the following code:
This generates 4 chanels ( i can play the output of this on other software i.e Grove Music )
audioMix1 = [app.y1(:,1),app.y1(:,2)]; % get signals from first song
audioMix2 = [app.y2(:,1),app.y2(:,2)]; % get signals from second song
maxlength = max(length(audioMix1), length(audioMix2)); %find the longest song
audioMix1(end+1:maxlength,:) = 0;
audioMix2(end+1:maxlength,:) = 0;
app.outputMixedTrack = [audioMix1, audioMix2]; %mix the songs together
length(app.outputMixedTrack)
plot(app.UIAxes3,app.outputMixedTrack); %plot spectogram
%save new file
[file, path] = uiputfile({'.wav';},'Save Trim As...', 'C:\Users\Alex\Desktop\audio');
if(file)
p = fullfile(path,file);
audiowrite(p, app.outputMixedTrack, 44000);
end
This generates only two chanels but i can only hear each of them on one side of my headset
track1Left = app.y1(:,1); %get only 1 signal from first song
track2Left = app.y2(:,1); %get only 1 signal from second song
maxlength = max(length(track1Left), length(track2Left)); %find the longest song
track1Left(end+1:maxlength,:) = 0;
track2Left(end+1:maxlength,:) = 0;
app.outputMixedTrack = [track1Left, track2Left]; %mix the songs together
size(app.outputMixedTrack)
%save new file
[file, path] = uiputfile({'.wav';},'Save Trim As...', 'C:\Users\Alex\Desktop\audio');
if(file)
p = fullfile(path,file);
audiowrite(p, app.outputMixedTrack, 44000);
end
Accepted Answer
More Answers (0)
Categories
Find more on Audio and Video Data 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!