问题
I make a project - Piano simulator in Matlab. I am able to play multiple sounds in the same time:
M=length(number);
freq_sampling = handles.freq_sampling;
for i=1:M
filename_in=['audio/' num2str(number(i)) '.mat'];
load(filename_in)
try %just for safety
y_sound=y_sound+y;
catch
y_sound=y;
end
end
sound(y_sound,freq_sampling)
Problem is with recording and playing it later - this code below concatenates all pressed buttons into one sound vector:
if record_on == 1
sound_vector_long = handles.sound_vector;
mono = (y_sound(:,1)+y_sound(:,2))/2; %mono is needed cuz .mat files are 2ch
if sound_vector_long == 0
sound_vector_long = transpose(mono);
else
sound_vector_long = cat(2, sound_vector_long, transpose(mono));
end
handles.sound_vector = sound_vector_long;
guidata(handles.figure1, handles);
end
But I'd like to play the music like in real-time when I press multiple buttons - is it possible to do? Anyone??
P.S. For sure, the final sound vector would have a different (shorter) length and some of the values would be a superposition of two (or more) vector's values. I just don't have an idea how to do this superposition (to do a consonance in result).
来源:https://stackoverflow.com/questions/43016646/consonance-superposition-of-recorded-sounds-in-matlab