Filter löschen
Filter löschen

How to mix two sound of different channel?

7 Ansichten (letzte 30 Tage)
Sushil Pun
Sushil Pun am 8 Jan. 2018
Beantwortet: Jan am 8 Jan. 2018
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 Kommentare
Birdman
Birdman am 8 Jan. 2018
What is your code that causes this error?
Sushil Pun
Sushil Pun am 8 Jan. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

John Harris
John Harris am 8 Jan. 2018
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 am 8 Jan. 2018
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.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by