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

3 Ansichten (letzte 30 Tage)
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.

Antworten (1)

Morio Nishigaki
Morio Nishigaki am 27 Jul. 2022
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?

Kategorien

Mehr zu Measurements and Spatial Audio finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by