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

2 次查看(过去 30 天)
  3 个评论
Muhammad Saim Nasir Siddiqui
编辑:Walter Roberson 2024-3-19
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
编辑:Walter Roberson 2024-3-19
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

请先登录,再进行评论。

采纳的回答

Jan
Jan 2015-5-4
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 个评论
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');

请先登录,再进行评论。

更多回答(1 个)

BOUGOSSA HADJER
BOUGOSSA HADJER 2024-3-19
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);

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by