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

2 次查看(过去 30 天)
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 中查找有关 MATLAB Support Package for Raspberry Pi Hardware 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by