How can i mix two .wav files ..iam using this code as show in figure but it gives an error?

2 views (last 30 days)
  3 Comments
Muhammad Saim Nasir Siddiqui
Edited: Walter Roberson on 19 Mar 2024
hey.. i modify this code just recently and it play two wav files one by one i want to play these at a same time (mix)so here is the code
[y1,fs,bits] = wavread('C:\Users\Sid\Desktop\sid1.wav'); [y2,fs,bits] = wavread('C:\Users\Sid\Desktop\sid2.wav'); y3 = [y1; y2];
% To Listen: sound(y3,fs);
wavwrite(y3,fs,bits,'file3.wav');
Muhammad Saim Nasir Siddiqui
Edited: Walter Roberson on 19 Mar 2024
Thanks for guiding ..here is the code which adds both .wav files
%Sid --on the floor clc clear all close all
[y,Fs,nb]=wavread('C:\Users\Sid\Desktop\sid1.wav'); [z,Fs1,nb1]=wavread('C:\Users\Sid\Desktop\sid2.wav');
audioplayer(y, Fs,nb)
audioplayer(z, Fs,nb)
audioplayer(x, Fs,nb)
lenY = size(y, 1); % Or is this the 2nd dimension?
lenZ = size(z, 1);
len = max(lenY, lenZ);
S = zeros(len, size(y, 2));
S(1:lenY, :) = y;
S(1:lenZ, :) = S(1:lenZ, :) + z;
maxValue = max(abs(S(:)));
S = S / maxValue;
sound(S,Fs,nb)
%This codes works but when i introduce more than 2 .wav files and also do some changing in your code:
%Sid --on the floor
clc
clear all
close all
[y,Fs,nb]=wavread('C:\Users\Sid\Desktop\sid1.wav');
[z,Fs1,nb1]=wavread('C:\Users\Sid\Desktop\sid2.wav');
[x,Fs2,nb2]=wavread('C:\Users\Sid\Desktop\sid3.wav');
audioplayer(y, Fs,nb)
audioplayer(z, Fs1,nb1)
audioplayer(x, Fs2,nb2)
lenY = size(y, 1); % Or is this the 2nd dimension?
lenZ = size(z, 1);
lenX = size(x, 1);
len = max(lenY, lenZ);
S = zeros(len, size(y, 2));
S(1:lenY, :) = y;
S(1:lenZ, :) = S(1:lenZ, :) + z;
S(1:lenX, :) = S(1:lenX, :) + x;
maxValue = max(abs(S(:)));
S = S / maxValue;
sound(S,Fs,nb)
It merges three .wav files but their amplitude is not high .. so the resulting sound is not much loud ..i want to increase its amplitude as well

Sign in to comment.

Accepted Answer

Jan
Jan on 4 May 2015
It seems like y and z have different lengths. How do you want to handle this? Do you want to crop the longer signal or to pad the shorter signal with zeros? How do you want to treat amplitudes higher than 1.0 after the addition? Any kind or normalization?
Perhaps this helps:
lenY = size(y, 1); % Or is this the 2nd dimension?
lenZ = size(z, 1);
len = max(lenY, lenZ);
S = zeros(len, size(y, 2));
S(1:lenY, :) = y;
S(1:lenZ, :) = S(1:lenZ, :) + z;
mavValue = max(abs(S(:));
S = S \ maxValue;
  2 Comments
Muhammad Saim Nasir Siddiqui
hey.. i modify this code just recently and it play two wav files one by one i want to play these at a same time (mix)so here is the code
[y1,fs,bits] = wavread('C:\Users\Sid\Desktop\sid1.wav'); [y2,fs,bits] = wavread('C:\Users\Sid\Desktop\sid2.wav'); y3 = [y1; y2];
% To Listen: sound(y3,fs);
wavwrite(y3,fs,bits,'file3.wav');

Sign in to comment.

More Answers (1)

BOUGOSSA HADJER
BOUGOSSA HADJER on 19 Mar 2024
close all
clear all
clc
[y1,fs,bits] = wavread('C:\Users\Sid\Desktop\sid1.wav');
'wavread' has been removed. With appropriate code changes, use 'audioread' instead.

Caused by:
Unrecognized function or variable 'wavread'.
sound(y3,fs);

Categories

Find more on Simulation, Tuning, and Visualization 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!