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

2 次查看(过去 30 天)
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?

采纳的回答

jibrahim
jibrahim 2022-12-22
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by