How can I simultaneously play and record from the same audio device?

11 views (last 30 days)
Hi guys,
I am trying to do a super simple operation of playing the signal and recording it at the same time through my RME audio interface. I have the DSP toolbox so I wanted to use the audioPlayerRecorder object to do that however my output is just a bunch of zeros with couple of non-zero values at the very end of the vector. I have been trying to figure out what would seem to be super simple operation for couple of days now and I just cannot figure it out. Please, any advice would be a lifesaver! My code so far is below
clear all
close all
%%DEFINE PARAMETERS FOR EXTERNAL SOUND CARD
internaldata.driver = 'ASIO';
internaldata.audio_device = 'ASIO Fireface USB';
internaldata.framesize = 30*2^13;
internaldata.samplerate = 48000;
internaldata.tfe_FFTLength = 512;
internaldata.spectral_averages = 1;
internaldata.input_channel_map = 5;
internaldata.output_channel_map = 5;
internaldata.deviceReader = audioDeviceReader('Driver',internaldata.driver,'SampleRate',internaldata.samplerate,...
'Device',internaldata.audio_device,'ChannelMappingSource','Property','ChannelMapping',internaldata.input_channel_map);
internaldata.deviceWriter = audioDeviceWriter('Driver',internaldata.driver,'SampleRate',internaldata.samplerate,...
'Device',internaldata.audio_device,'ChannelMappingSource','Property','ChannelMapping',internaldata.output_channel_map);
input = step(dsp.ColoredNoise('Color','pink','SamplesPerFrame',internaldata.framesize,'NumChannels',1));
aPR = audioPlayerRecorder('SampleRate',internaldata.samplerate,'PlayerChannelMapping',internaldata.output_channel_map,...
'RecorderChannelMapping',internaldata.input_channel_map);
output=aPR(input);
figure
subplot 211
plot(input)
subplot 212
plot(output)
release(internaldata.deviceWriter)
release(internaldata.deviceReader)

Answers (1)

Sharan Paramasivam Murugesan
1. Is your audio device capable of simultaneous playback and recording (Full duplex sound card)?
2. Following is an example on how to perform simultaneous playback and recording: https://www.mathworks.com/help/audio/ref/audioplayerrecorder-class.html#examples
Please take a look at the above example - especially the frame based loop. If you want to specify channel mapping manually, the section on "Specify non-default channel mapping" might help.

Community Treasure Hunt

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

Start Hunting!