ALSA output frame size
Moderators: MattKingUSA, khz, muldjord, deva
ALSA output frame size
As far as I understood, if I use the jack audio interface, the Drumgizmo internal frame size (block size) is the same as the jack audio server uses, right? But what frame size is used if the ALSA output is selected? I assume the default value of 1024 is used since the latency seems to be very high if I use the ALSA output interface (even if I select "-O frames=2"). Is there a way to configure the frame size with the CLI?
- deva
- Established Member
- Posts: 285
- Joined: Sun Oct 23, 2016 10:15 am
- Has thanked: 3 times
- Been thanked: 31 times
- Contact:
Re: ALSA output frame size
You should be able to set the framesize with the -O parameter. If this is not the case then perhaps there is a bug in the alsa output module.
I don't think it has been used much, so it is entirely possible that this part of the code has never worked as intended without any of us noticing...
I don't think it has been used much, so it is entirely possible that this part of the code has never worked as intended without any of us noticing...
Re: ALSA output frame size
Yes, we can set the frame size with the -O parameter (which is then actually the period size since we use the snd_pcm_hw_params_set_period_size_near() function). According to https://www.alsa-project.org/wiki/FramesPeriods, a frame is just a sample if we assume a mono stream and the period size is basically the block size, i.e., what we set with the "-O frame" parameter. But then you could also specify the number of periods in the buffer with snd_pcm_hw_params_set_periods_near as far as I understand. If we do not set it explicitely, I am not sure what is then used in the ALSA interface.
Anyway, in the ALSA output module run() function, we provide the ALSA interface with a sample buffer of size nsamples and send this buffer to the ALSA interface with the snd_pcm_writei() function. The question is, can I modify the parameter nsamples? As far as I understand, the minimum latency between the MIDI input and ALSA output is depending on the nsamples number, the ALSA period size and the number of ALSA periods, right? So, currently I can change the period size with the CLI but not the other parameters. Or maybe I have missed something obvious.
Anyway, in the ALSA output module run() function, we provide the ALSA interface with a sample buffer of size nsamples and send this buffer to the ALSA interface with the snd_pcm_writei() function. The question is, can I modify the parameter nsamples? As far as I understand, the minimum latency between the MIDI input and ALSA output is depending on the nsamples number, the ALSA period size and the number of ALSA periods, right? So, currently I can change the period size with the CLI but not the other parameters. Or maybe I have missed something obvious.
- deva
- Established Member
- Posts: 285
- Joined: Sun Oct 23, 2016 10:15 am
- Has thanked: 3 times
- Been thanked: 31 times
- Contact:
Re: ALSA output frame size
At initialisation timt the engine will ask the output module which ramesize to use through the getBufferSize() method. But for the alsa output module this does not seem to be implemented... which will hit the base-class (in src/audiooutputengine.h) implementation which always return 1024.
So you can try adding that method and return the actual framesize and see if that helps?
So you can try adding that method and return the actual framesize and see if that helps?
Re: ALSA output frame size
Yes, you are right. The ALSA out interface does not yet implement the getBufferSize function. I've added it to the following branch: http://git.drumgizmo.org/drumgizmo.git/ ... aoutbuffer
Re: ALSA output frame size
Have you used a cherry-pick for putting my commit on the develop branch because I did not see any merge commit?
Should I now remove my branch and the commit on my branch will then be deleted by the git garbage collector?
BTW: I found out that there are more changes to the ALSA output interface necessary. I'll do some more tests and will create another branch for it soon.
Should I now remove my branch and the commit on my branch will then be deleted by the git garbage collector?
BTW: I found out that there are more changes to the ALSA output interface necessary. I'll do some more tests and will create another branch for it soon.
- deva
- Established Member
- Posts: 285
- Joined: Sun Oct 23, 2016 10:15 am
- Has thanked: 3 times
- Been thanked: 31 times
- Contact:
Re: ALSA output frame size
Here are my new changes: http://git.drumgizmo.org/drumgizmo.git/ ... 4c51cea44d
With this change, low latency audio is now possible with my audio hardware.
With this change, low latency audio is now possible with my audio hardware.
Re: ALSA output frame size
On my PC I had a default value of 1024 which gave me more than a second latency.
- deva
- Established Member
- Posts: 285
- Joined: Sun Oct 23, 2016 10:15 am
- Has thanked: 3 times
- Been thanked: 31 times
- Contact:
Re: ALSA output frame size
That seems completely useless ... I definitely vote for the 3 periods default that you put in.