필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
  댓글 수: 3
Muhammad Saim Nasir Siddiqui
Muhammad Saim Nasir Siddiqui 2015년 5월 4일
편집: 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
Muhammad Saim Nasir Siddiqui 2015년 5월 4일
편집: 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
Muhammad Saim Nasir Siddiqui 2015년 5월 4일
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에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by