Update PiPedalAlsa.cpp

Added error checks around ALSA rate queries so that if querying the minimum rate fails, a warning is logged and 48 kHz is used as a default

When querying the maximum rate fails, the code now warns and falls back to 48 kHz; otherwise it populates valid rates and ensures a fallback if none are found

Buffer size retrieval now occurs after handling rate queries, maintaining previous behavior while supporting the new fallback logic
This commit is contained in:
Extremesecrecy
2025-07-23 22:48:22 -07:00
parent 2b5f614625
commit 059922f71f
+26 -8
View File
@@ -117,20 +117,23 @@ std::vector<AlsaDeviceInfo> PiPedalAlsaDevices::GetAlsaDevices()
unsigned int minRate = 0, maxRate = 0; unsigned int minRate = 0, maxRate = 0;
snd_pcm_uframes_t minBufferSize = 0, maxBufferSize = 0; snd_pcm_uframes_t minBufferSize = 0, maxBufferSize = 0;
int dir; int dir;
err = snd_pcm_hw_params_get_rate_min(params, &minRate, &dir); err = snd_pcm_hw_params_get_rate_min(params, &minRate, &dir);
if (err == 0) if (err != 0)
{ {
err = snd_pcm_hw_params_get_rate_max(params, &maxRate, &dir); Lv2Log::warning(SS("Failed to get minimum sample rate for device '" << info.name_ << "'. Using default 48000."));
info.sampleRates_.push_back(48000);
err = 0; // continue using fallback rate
} }
if (err == 0) else
{ {
err = snd_pcm_hw_params_get_buffer_size_min(params, &minBufferSize); int err2 = snd_pcm_hw_params_get_rate_max(params, &maxRate, &dir);
} if (err2 != 0)
if (err == 0)
{ {
err = snd_pcm_hw_params_get_buffer_size_max(params, &maxBufferSize); Lv2Log::warning(SS("Failed to get maximum sample rate for device '" << info.name_ << "'. Using default 48000."));
info.sampleRates_.push_back(48000);
} }
if (err == 0) else
{ {
for (size_t i = 0; i < sizeof(RATES) / sizeof(RATES[0]); ++i) for (size_t i = 0; i < sizeof(RATES) / sizeof(RATES[0]); ++i)
{ {
@@ -140,6 +143,21 @@ std::vector<AlsaDeviceInfo> PiPedalAlsaDevices::GetAlsaDevices()
info.sampleRates_.push_back(rate); info.sampleRates_.push_back(rate);
} }
} }
if (info.sampleRates_.empty())
{
Lv2Log::warning(SS("No supported sample rates for device '" << info.name_ << "'. Using default 48000."));
info.sampleRates_.push_back(48000);
}
}
}
err = snd_pcm_hw_params_get_buffer_size_min(params, &minBufferSize);
if (err == 0)
{
err = snd_pcm_hw_params_get_buffer_size_max(params, &maxBufferSize);
}
if (err == 0)
{
if (minBufferSize < 16) if (minBufferSize < 16)
{ {
minBufferSize = 16; minBufferSize = 16;