Error when recording multi-channel audio with loopback
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Charlotte Mock
el 15 de Dic. de 2022
Comentada: Jimmy Lapierre
el 16 de Dic. de 2022
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.
0 comentarios
Respuesta aceptada
Jimmy Lapierre
el 15 de Dic. de 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 comentarios
Jimmy Lapierre
el 16 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!