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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Denis Gurchenkov
Denis Gurchenkov am 23 Jun. 2021
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 :))

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guilhem Schena
Guilhem Schena am 23 Jun. 2021
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

Kategorien

Mehr zu Code Generation and Deployment finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by