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

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

Réponse acceptée

jibrahim
jibrahim le 22 Déc 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
  1 commentaire
Bernd
Bernd le 23 Déc 2022
Thank you for your quick reply! Your code works and the MEX file is generated by the Matlab Coder.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by