Error when recording multi-channel audio with loopback

12 ビュー (過去 30 日間)
Charlotte Mock
Charlotte Mock 2022 年 12 月 15 日
コメント済み: Jimmy Lapierre 2022 年 12 月 16 日
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.

採用された回答

Jimmy Lapierre
Jimmy Lapierre 2022 年 12 月 15 日
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 件のコメント
Charlotte Mock
Charlotte Mock 2022 年 12 月 16 日
編集済み: Charlotte Mock 2022 年 12 月 16 日
Thanks, Jimmy! It solved the problem.
Regarding using audioPlayerRecorder, as far as I know it doesn't allow loopback...?
Jimmy Lapierre
Jimmy Lapierre 2022 年 12 月 16 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by