audioPlayerRecorder returns an array of zeros during simultaneous playback and recording

3 visualizzazioni (ultimi 30 giorni)
Hi, I'm trying to play and record simultaneously using the audioPlayerRecorder object. I have a multi-channel pink noise signal that I generate in my script and I use that as the audioToDevice matrix. I have an audio interface (Focusrite Scarlett 18i20) plus amp for output to speaker and the same audio interface for input. Here is how I've set up the audioPlayerRecorder object:
device = 'Focusrite USB ASIO';
num_ch_out = 3;
num_ch_in = 3;
Fs = 48000;
apr = audioPlayerRecorder('SampleRate',Fs, ...
'Device',device, ...
'BitDepth','24-bit integer', ...
'PlayerChannelMapping',1:num_ch_out,...
'RecorderChannelMapping',1:num_ch_in);
audioFromDevice = apr(audioToDevice);
On calling the apr object for playback and recording, the speaker I have connected down the line outputs what I expect it to. But the audioFromDevice matrix that I get back is 48000x3 array of zeros. I've checked all my connections and everything is working as it should. And I know the gains of all channels/devices in the chain which I'm scaling th eincoming/outgoing signals with.
Am I using the audioPlayerRecorder object incorrectly? A side note: latency is not hugely important to me as I have a different part of code that deals with that. For now, I just want to be able to play and record simultaneously.
Alternatively, I've tried to use audioDeviceWriter and audioDeviceReader for this same purpose but I'm having trouble getting that to work as well: the buffer size needs to be same for both the objects but in the same 'duration', as the writer objects plays back a signal that is 48000 samples long, the reader object only acquires and returns number of samples equivalent to the buffer size (2048).
Note: I'm on PC and need to use ASIO driver so I can't use the audioplayer, audiorecorder objects as they default to Windows Direct Sound driver that only support two-channel playback.
edit: changed 'two-channel pink noise' to 'multi-channel pink noise'
  1 Commento
jibrahim
jibrahim il 18 Giu 2021
Hi Karan,
This object is designed for streaming, real-time operation, with expected latency. So make sure you are calling the object multiple times (typically in a FOR loop). I would expect an initial output of zeros (due to latency) after which you should see your expected output.
Let us know if you are still having problems, and we'll take a closer look

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Audio I/O and Waveform Generation in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by