Error in Matlab Coder: "Property 'pBuffer.Cache' is undefined on some execution paths but is used inside the called function."

3 visualizaciones (últimos 30 días)
I am trying to create a mex file based on the code below using the Matlab Coder app. I want to implement an audio recording of 10 seconds in length at 48000 Hz of a sampling rate from my sound card and store the data in array x for further calculations.
function [x] = AudioRec()
deviceReader = audioDeviceReader('SampleRate',48000,'Device','"What U Hear" (Sound Blaster Audigy 5/Rx)');
buff = dsp.AsyncBuffer('Capacity',10*48000);
N = deviceReader.SamplesPerFrame;
while buff.NumUnreadSamples+N <= buff.Capacity
audioIn = deviceReader();
write(buff,audioIn);
end
release(deviceReader);
x = read(buff);
end
Matlab Coder gives me this error message:
Property 'pBuffer.Cache' is undefined on some execution paths but is used inside the called function.
Error in == AudioRec Line 16 Column 10
Code generation failed View Error Report
How can i solve the problem?

Respuesta aceptada

jibrahim
jibrahim el 22 de Dic. de 2022
He Bernd,
I suspect coder is not sure this while loop will ever be entered. This should work (I added a call to write outside the while loop)
function [x] = AudioRec()
deviceReader = audioDeviceReader('SampleRate',48000);
buff = dsp.AsyncBuffer('Capacity',10*48000);
N = deviceReader.SamplesPerFrame;
write(buff,zeros(N,1));
while buff.NumUnreadSamples+N <= buff.Capacity
audioIn = deviceReader();
write(buff,audioIn);
end
release(deviceReader);
x = read(buff);
end

Más respuestas (0)

Categorías

Más información sobre Code Generation and Deployment en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by