Azzera filtri
Azzera filtri

Error when recording multi-channel audio with loopback

9 visualizzazioni (ultimi 30 giorni)
I am trying to record multi-channel audio where one channel records audio from a microphone and two channels record "internal" sound (i.e., loopback) that is played via MATLAB to headphones. I am working with a digital audio interface (Focusrite Scarlett), ASIO drivers, Windows 10 and MATLAB R2022b.
With the code below I get the following error message:
Error using audioDeviceWriter/setup
The buffer size parameter of the audio input device must match the buffer size parameter of the audio output device.
Error in audioDeviceWriter/setupImpl
I have checked the buffer size parameter using asiosettings and also the settings of the Focusrite and they are set to the same value. I would assume that this applies to both the outputs and inputs of the Focusrite so I cannot explain the error message.
%% define properties of digital audio interface and recording set-up
device = 'Focusrite USB ASIO';
driver = 'ASIO';
Fs = 44100; % sampling frequency
%% set up device reader (for recording)
deviceReader = audioDeviceReader('SampleRate',Fs, ...
'Device',device, ...
'BitDepth','24-bit integer', ...
'Driver',driver, ...
'NumChannels',6, ...
'SamplesPerFrame', Fs/4);
setup(deviceReader);
%% load audio file and set up device writer (for audio output)
fileReader = dsp.AudioFileReader('metronome90bpm.wav');
fileInfo = audioinfo('metronome90bpm.wav');
deviceWriter = audioDeviceWriter('SampleRate',fileInfo.SampleRate, ...
'Device',device, ...
'BitDepth','16-bit integer', ...
'Driver',driver);
setup(deviceWriter, zeros(fileReader.SamplesPerFrame, ...
fileInfo.NumChannels));
Each section on its own does its job, i.e., setting up the device reader and then recording something OR setting up the device writer and playing the audio.
I have tried the multichannel recording (with microphone + loopback) when playing an audiofile in the background (so not in MATLAB) with windows media player and then starting a recording using the device reader and that works fine.

Risposta accettata

Jimmy Lapierre
Jimmy Lapierre il 15 Dic 2022
Hi Charlotte,
When using the reader and writer at the same time, some settings like frame size must match.
Here, fileReader.SamplesPerFrame (1024) does not match the deviceReader SamplesPerFrame (Fs/4).
Maybe you intend to set fileReader SamplesPerFrame to Fs/4 as well.
P.S. might be easier to use audioPlayerRecorder in this case.
  2 Commenti
Charlotte Mock
Charlotte Mock il 16 Dic 2022
Modificato: Charlotte Mock il 16 Dic 2022
Thanks, Jimmy! It solved the problem.
Regarding using audioPlayerRecorder, as far as I know it doesn't allow loopback...?
Jimmy Lapierre
Jimmy Lapierre il 16 Dic 2022
You might need to specify channel mapping properties to specify which channels you need, but I'm not sure I see what the limitation is.

Accedi per commentare.

Più risposte (0)

Categorie

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

Community Treasure Hunt

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

Start Hunting!

Translated by