How to mix two sound of different channel?

조회 수: 6 (최근 30일)
Sushil Pun
Sushil Pun 2018년 1월 8일
답변: Jan 2018년 1월 8일
Here is my code
handles.y = (handles.y2)'; lenY = size(handles.y1, 1); lenZ = size(handles.y, 1);
handles
len = max(lenY, lenZ);
S = zeros(len, size(handles.y1, 2));
S(1:lenY, :) = handles.y1;
S(1:lenZ, :) = S(1:lenZ, :) + handles.y;
maxValue = max(abs(S(:)));
S = S / maxValue;
handles.mPlayer = audioplayer(S, 44100);
handles.y3 = S;
handles.Fs3 = 44100;
% save the updated handles object
guidata(hObject,handles);
msgbox('Sound Mixed');
  댓글 수: 2
Birdman
Birdman 2018년 1월 8일
What is your code that causes this error?
Sushil Pun
Sushil Pun 2018년 1월 8일
y2 has number of channel 1 and y has number of channel 2, i think thats causing a problem i don't know how to fix it, i have provided the code above.

댓글을 달려면 로그인하십시오.

답변 (2개)

John Harris
John Harris 2018년 1월 8일
It's that you're trying to add 1-dimensional and 2-dimensional matrix, but look at your dimensions for y1 and y. y1 (and thus, S) is tall, while handles.y is wide.
Try transposing handles.y:
S(1:lenZ, :) = S(1:lenZ, :) + handles.y';
Check the results; are you trying to add handles.y to one column of S, or both?

Jan
Jan 2018년 1월 8일
Insert some meaningful comments in your code, such that it gets clear, what you want to achieve. I assume, you want to mix the 2 channel handles.y1 and the 1 channel handles.y - by the way: there might be more useful names for the fields.
I omit the "handles" for clarity:
y1 = rand(220500, 2) - 0.5;
y = rand(1, 220501) - 0.5;
s1 = y1;
s2 = y.'; % Transpose to have the same orientation
[len1, w1] = size(s1);
[len2, w2] = size(s2, 1);
s = zeros(max(len1, len2), max(w1,w2));
s(1:len1, 1:w1) = s1;
s(1:len2, 1:w2) = s(1:len2, 1:w2) + s2;
s = s / max(s(:)); % Normalize to [-1.0, 1.0]
This adds the two signals independent from their number of channels and lengths.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by