Error in Matlab Coder: "Property 'pBuffer.Cache' is undefined on some execution paths but is used inside the called function."
조회 수: 3 (최근 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?
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Code Generation and Deployment에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!