How to reduce the ALSA latency when deploying Matlab scripts on Raspberry ?

조회 수: 1 (최근 30일)
Guilhem Schena
Guilhem Schena 2021년 6월 23일
답변: Guilhem Schena 2021년 6월 23일
I would like to have the lowest audio latency possible on Raspberry Pi when deploying a Matlab script. However, it seems that Matlab introduce 0.5 second of latency because of the buffer size. I would like to know how I can reduce that without simulink.
I saw here https://fr.mathworks.com/matlabcentral/answers/164113-high-latency-for-audio-use-on-a-raspberry-pi-using-simulink that my answer has beens partly answered, but I would like to have more details.
Thank you !
  댓글 수: 1
Denis Gurchenkov
Denis Gurchenkov 2021년 6월 23일
Hi Guilhem, it often helps if you attach an example (or have a description) that shows the issue and the code that you have. The way you formulate the question, a reader has hard time knowing if the issue is in some audio processing or singal processing function, or the issue is related to interfacing between MATLAB host and Raspberry PI target, or the issue is elsewhere, so it is hard for anyone to offer good suggestions. Please consider elaborating your question (and you may be able to find the answer in that process :))

댓글을 달려면 로그인하십시오.

답변 (1개)

Guilhem Schena
Guilhem Schena 2021년 6월 23일
I was apparently not very clear, excuse me for that.
I am trying to have the lowest latency possible for recording and play sounds. So, I use audiocapture and audioplayer objects and the functions capture() and play() to do that in the same script. For now I am just recording sounds from my USB mic and directly play it through speakers, but I have to wait more or less 0.5s before the sound I make in the microphone is played through the speakers.
Here's my code :
function latence()
%#codegen
Fs = 44100;
spf = 441;
D = 10;
N = D * Fs;
Nb = N/spf;
r = raspi();
captureObj = audiocapture(r,'plughw:2,0','SampleRate', Fs, 'SamplesPerFrame', spf);
playbackObj = audioplayer(r,'plughw:1,0', 'SampleRate', Fs);
for k = 1:Nb
input = capture(captureObj);
play(playbackObj,input);
end
end

카테고리

Help CenterFile Exchange에서 Code Generation and Deployment에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by