Error when selecting single audio frame using audioDeviceReader() and saving to buffer

4 次查看(过去 30 天)
fs = 16000; % Define Sampling Frequency
AudioIn = audioDeviceReader(fs);
audioBuffer = dsp.AsyncBuffer(fs);
while true
x = AudioIn(); % Select Single Audio Frame
audioBuffer(1:end-numel(x)) = audioBuffer(nemel(x)+1:end); % Progress Audio Buffer
audioBuffer(end-nemel(x)+1:end) = x; % Add audio Frame to buffer
end
Hi, I am having issues implementing the above section of code.
As I understand it, calling the function audioDeviceReader returns a system object that reads audio samples using an audio input device in real time. One frame of this real time audio signal can be returned in matrix form using the first line within the while loop.
However, this returns the following error message:
Error using audioDeviceReader/setup
PortAudio Error: Unanticipated host error
Error in audioDeviceReader/setupImpl
Does this mean an audio input has not been detected?
Any help with this issue would be greatly appreciated.

回答(1 个)

Morio Nishigaki
Morio Nishigaki 2022-7-27
Hello,
I think it's wrong usage of 'dsp.AsyncBuffer'.
Help Center of MathWorks says "AsyncBuffer FIFO Input & Output should be used write/read".
AsyncBuffer FIFO is a special variable, not an array.
For example,
clear;
asyncBuff = dsp.AsyncBuffer;
a=-99:0;
write(asyncBuff,a');% input a to FIFO
b=2:2:200;
write(asyncBuff,b');% add b to FIFO
readOut = read(asyncBuff,200);
figure(1);
plot(readOut);
OK?

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by