Realtime audio capture and playback using session-based interface
Show older comments
Hello I am using one USB audio device (XMOS Mic array) which acts as audio input and output device. I am trying to capture mic data and play in real time. I am able to plot all 8 channels mic data. But now I want to simultaneously play one of the channel data. I am not getting what I am doing wrong. Below is my code for capture and playback:
d = daq.getDevices
data = zeros(4800,1);
ai = daq.createSession('DirectSound');
addAudioInputChannel(ai, 'Audio1', 1:8);
addAudioOutputChannel(ai, 'Audio5', 1:1);
ai.Rate = 48000;
% ai.DurationInSeconds = 10; %commented for playback purpose
addlistener(ai, 'DataAvailable', @plotData);
queueOutputData(ai, data); %make some data available before calling startBackground
startBackground(ai);
function plotData(~,event)
plot(event.TimeStamps,event.Data);
queueOutputData(ai, event.Data(0)); %this should play automatically but exits quickly?
end
Output
d =
Data acquisition devices:
index Vendor Device ID Description
----- ----------- --------- -----------------------------------------------------------------
1 directsound Audio0 DirectSound Primary Sound Capture Driver
2 directsound Audio1 DirectSound XMOS Microphone Array UAC1.0 (USB Audio Device)
3 directsound Audio2 DirectSound Stereo Mix (Realtek High Definition Audio)
4 directsound Audio3 DirectSound Primary Sound Driver
5 directsound Audio4 DirectSound Speakers / Headphones (Realtek High Definition Audio)
6 directsound Audio5 DirectSound Speakers (USB Audio Device)
Can you please suggest some solution.
Thanks, Shailesh
Answers (0)
Categories
Find more on Multichannel Audio Input and Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!