Recognizing 8 audio channels not stereo

조회 수: 3 (최근 30일)
Jihyun Lee
Jihyun Lee 2022년 6월 22일
답변: Paras Gupta 2023년 10월 18일
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.

답변 (1개)

Paras Gupta
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.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by