Why do I receive the error "The input frame size must be less than or equal to twice the SampleRate property value" when using audioDeviceWriter in Audio Toolbox?

24 Ansichten (letzte 30 Tage)
I get the following error when run my audio stream loop with input from file and output to device.
Error using audioDeviceWriter/validateInputsImpl
The input frame size must be less than or equal to twice the SampleRate property value (or two
seconds of audio samples). Either increase the device sample rate or reduce the input frame size.
This is my code to reproduce the above error.
frameLength =44100*2;
fileReader = dsp.AudioFileReader('speech_dft.mp3', 'SamplesPerFrame',frameLength,'ReadRange',[1,44100]);
fileInfo = audioinfo('speech_dft.mp3');
fs = fileReader.SampleRate;
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);
setup(deviceWriter,zeros(fileReader.SamplesPerFrame,fileInfo.NumChannels))
while ~isDone(fileReader)
input = fileReader();
numUnderrun = deviceWriter(input);
end

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 12 Apr. 2021
'audioDeviceWriter' object writes only one frame at a time. You can know more about it in this documentation https://www.mathworks.com/help/releases/R2021a/audio/ref/audiodevicewriter-system-object.html
The error occurs because, the input frame size should be less than or equal to 2*fs (Fs is the sampling frequency). Which means the length of 'frameLength' variable used should be less than or equal to 2*fs. 
In your code, 'fs' is 22050. Accordingly, the size of the input frame('frameLength') should be less than or equal to a length of 44100 samples. This is satisfied when you use 'duration' as 1 sec. Hence you can see no error in that case.
 

Weitere Antworten (0)

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by