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

2 views (last 30 days)
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?

Accepted Answer

jibrahim
jibrahim on 22 Dec 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

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!