How to mix two sound of different channel?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
John Harris
el 8 de En. de 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?
0 comentarios
Jan
el 8 de En. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!