MATLAB中的audioplayer函數只支持2個通道。但是您可以使用DSP系統工具箱中的功能。下面的代碼片段可以幫助:
hafr1 = dsp.AudioFileReader('myfile1.wav');% Can be other formats as well
hafr2 = dsp.AudioFileReader('myfile2.wav');
hafr3 = dsp.AudioFileReader('myfile3.wav');
hap = dsp.AudioPlayer;
hap.SampleRate = hafr1.SampleRate; % Assuming that all files have same sample rate or else you have to do some clever mixing.
while ~isDone(hafr1) % assuming same size. You need to add some clever logic to adjust the number of channels if they are of different sizes
data1 = step(hafr1);
data2 = step(hafr2);
data3 = step(hafr3);
step(hap, [data1 data2 data3]);
end
此代碼將在默認輸出設備上播放音頻。如果有三個或更多頻道,您將在三個獨立頻道收聽音頻。如果不是,取決於平臺,它會混合到兩個通道。
您可以參考doc頁面獲取相關信息。
Dinesh
謝謝親愛的Dinesh,我會檢查它並通知你結果。 – Abraham