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

2 vues (au cours des 30 derniers jours)
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.

Réponses (1)

Morio Nishigaki
Morio Nishigaki le 27 Juil 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?

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by