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 Center および File ExchangeCode 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