Skip to content

alsa: simplify probing for default latency#1152

Draft
philburk wants to merge 3 commits into
masterfrom
alsa_grope_1145
Draft

alsa: simplify probing for default latency#1152
philburk wants to merge 3 commits into
masterfrom
alsa_grope_1145

Conversation

@philburk
Copy link
Copy Markdown
Collaborator

@philburk philburk commented May 8, 2026

Use a method that is less prone to failure.
Also change GropeDevice() to ProbeDeviceDefaults().

Fixes #1145

Use a method that is less prone to failure.
Also change GropeDevice() to ProbeDeviceDefaults().

Fixes #1145
@philburk philburk requested review from RossBencina and dmitrykos May 8, 2026 00:40
}

{
/* It happens that this call fails because the device is busy */
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment explain a bug?
Or is it expected behavior?

@philburk philburk marked this pull request as draft May 14, 2026 23:06
double defaultSr = devInfo->baseDeviceInfo.defaultSampleRate;
unsigned int approximateSampleRate = 0;
const int kLowBufferFrames = 512;
const int kHighBufferFrames = 2048;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check style guide. k prefix is not our style for constants.

*defaultHighLatency = (double) (alsaBufferFrames - alsaPeriodFrames) / defaultSr;
ret = alsa_snd_pcm_hw_params_get_buffer_size_min( hwParams, &lowBufferFrames );
if (ret) {
printf( "%s: alsa_snd_pcm_hw_params_get_buffer_size_min() returned %d !\n", __FUNCTION__, ret );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make it clear that this is the failure case. "... failed, returnd %d"

Copy link
Copy Markdown
Collaborator

@RossBencina RossBencina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that you've removed setting the sample rate. I wonder whether you get different buffer bounds back from alsa if you set the sample rate first, as in the old code. The function do query the current state of the configuration space:

https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_2pcm_8c.html#a3caf61ab086028067b602d48182df708

@philburk
Copy link
Copy Markdown
Collaborator Author

I notice that you've removed setting the sample rate.

Yes. The old code had to reset the sample rate any time it tried to set buffer or period sizes.
I no longer set the buffer size so I figured I didn't need to set the sample rate.
But who does set it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proposal: pa_linux_alsa.c: do we want to pass dir (direction) param to alsa_snd_pcm_hw_params_set_period_size_near?

2 participants