Error when recording multi-channel audio with loopback
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!