Recognizing 8 audio channels not stereo
5 次查看(过去 30 天)
显示 更早的评论
setpref('dsp', 'portaudioHostApi', 3)
[audioData, Fs] = audioread('speech.wav');
ad = audiodevinfo;
deviceID = audiodevinfo(0,ad.output(2).Name); % select audio device
channelmapping = zeros(size(audioData,1),8);
channelmapping(:,1) = audioData(:,1); % audio data with selected channels of devices
p = audioplayer(channelmapping,Fs,8, deviceID);
play(p)
Dear community,
I want to select 1 channel to play audio data among 8 channels of devices.
However, Matlab does recognize stereo instead of 8 channels.
Could you help me fixing my code?
Thank you.
0 个评论
回答(1 个)
Paras Gupta
2023-10-18
Hi Jihyun,
I understand that you want to select and play one channel's audio data from an 8 channel audio file. MATLAB's 'audiplayer' function only supports mono (one-channel) and stereo (two-channel) audio data, and thus it cannot play 8 channela audio.
The error in the code provided is that the variable 'channelmapping' is created with 8 columns which is equivalent to 8 channles, even though only one column contains audio data and the remaining columns contain zeros.
You can refer the following code to achieve the desired results:
setpref('dsp', 'portaudioHostApi', 3);
[audioData, Fs] = audioread('8_Channel_ID.wav');
ad = audiodevinfo;
deviceID = ad.output(2).ID; % Select audio output device
channelmapping = zeros(size(audioData, 1), 1); % second dimension set to 1
selectedChannel = 1; % Select the desired channel (1 to 8)
channelmapping(:, selectedChannel) = audioData(:, selectedChannel); % Audio data with selected channel
p = audioplayer(channelmapping, Fs, 8, deviceID);
play(p);
Please find below the link to the documentaion of the 'audioplayer' function.
Hope this answer helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!