Revise device configuration logic and settings

The ALSA device scanner no longer inserts default sample rates when it cannot read them, preventing invalid frequency choices

Jack server settings now accept independent input and output devices during construction

The latency test utility was updated to handle separate input and output device parameters and display them accordingly

The help text for the latency tool documents the new usage with optional output device specification

Device lists in the configuration dialog are sorted to prefer devices supporting capture and playback, then USB devices, while refresh preserves existing selections
This commit is contained in:
Extremesecrecy
2025-07-24 07:45:02 -07:00
parent 798a8c8708
commit 43cc758d18
5 changed files with 90 additions and 70 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ public:
AlsaFormatEncodeDecodeTest(this);
JackServerSettings serverSettings("hw:M2",48000,32,3);
JackServerSettings serverSettings("hw:M2","hw:M2",48000,32,3);
JackConfiguration jackConfiguration;
if (useJack)
+4 -3
View File
@@ -41,14 +41,15 @@ namespace pipedal
void SetAlsaInputDevice(const std::string &d){ alsaInputDevice_ = d; }
void SetAlsaOutputDevice(const std::string &d){ alsaOutputDevice_ = d; }
JackServerSettings();
JackServerSettings(
const std::string alsaInputDevice,
JackServerSettings(
const std::string &alsaInputDevice,
const std::string &alsaOutputDevice,
uint64_t sampleRate,
uint32_t bufferSize,
uint32_t numberOfBuffers)
: valid_(true),
alsaInputDevice_(alsaInputDevice),
alsaOutputDevice_(alsaInputDevice), // default same
alsaOutputDevice_(alsaOutputDevice),
sampleRate_(sampleRate),
bufferSize_(bufferSize),
numberOfBuffers_(numberOfBuffers),
+25 -16
View File
@@ -57,9 +57,9 @@ void PrintHelp()
pp << "Copyright (c) 2022 Robin Davies\n";
pp << "\n";
pp << Indent(0) << "Syntax\n\n";
pp << Indent(2) << "pipedal_latency_test [<options>] <device-name>\n\n";
pp << "where <device-name> is the name of an ALSA device. Typically this should be the name of a hardware "
"device (a device name starting with 'hw:').\n\n";
pp << Indent(2) << "pipedal_latency_test [<options>] <input-device> [<output-device>]\n\n";
pp << "where <input-device> is the name of an ALSA capture device and <output-device> is the name of a playback device. "
"If <output-device> is omitted, the input device will be used for both capture and playback. Typically the device names start with 'hw:'.\n\n";
pp << Indent(0) << "Options\n\n";
pp << Indent(15);
@@ -95,7 +95,8 @@ void PrintHelp()
pp << Indent(0) << "Examples\n\n";
pp << Indent(2) << "pipedal_latency_test --list\n\n";
pp << Indent(2) << "pipedal_latency_test hw:M2\n\n";
pp << Indent(2) << "pipedal_latency_test hw:M2\n";
pp << Indent(2) << "pipedal_latency_test hw:M2 hw:Device2\n\n";
}
void ListDevices()
@@ -138,7 +139,8 @@ public:
private:
AudioDriver *audioDriver = nullptr;
const std::string &deviceId;
const std::string &inputDeviceId;
const std::string &outputDeviceId;
ChannelsT inputChannels;
ChannelsT outputChannels;
uint32_t sampleRate;
@@ -147,11 +149,13 @@ private:
public:
AlsaTester(
const std::string &deviceId,
const std::string &inputDeviceId,
const std::string &outputDeviceId,
const ChannelsT &inputChannels,
const ChannelsT &outputChannels,
uint32_t sampleRate, int bufferSize, int buffers)
: deviceId(deviceId),
: inputDeviceId(inputDeviceId),
outputDeviceId(outputDeviceId),
sampleRate(sampleRate),
inputChannels(inputChannels),
outputChannels(outputChannels),
@@ -186,7 +190,7 @@ public:
TestResult result;
try
{
JackServerSettings serverSettings(deviceId, sampleRate, bufferSize, buffers);
JackServerSettings serverSettings(inputDeviceId, outputDeviceId, sampleRate, bufferSize, buffers);
JackConfiguration jackConfiguration;
jackConfiguration.AlsaInitialize(serverSettings);
@@ -403,12 +407,13 @@ public:
};
TestResult RunLatencyTest(
const std::string deviceId,
const std::string inputDeviceId,
const std::string outputDeviceId,
const ChannelsT &inputChannels,
const ChannelsT &outputChannels,
uint32_t sampleRate, int bufferSize, int buffers)
{
AlsaTester tester(deviceId, inputChannels, outputChannels, sampleRate, bufferSize, buffers);
AlsaTester tester(inputDeviceId, outputDeviceId, inputChannels, outputChannels, sampleRate, bufferSize, buffers);
return tester.Test();
}
@@ -428,13 +433,14 @@ static std::string overheadDisplay(float value)
}
void RunLatencyTest(
const std::string &deviceId,
const std::string &inputDeviceId,
const std::string &outputDeviceId,
const ChannelsT &inputChannels,
const ChannelsT &outputChannels,
uint32_t sampleRate)
{
PrettyPrinter pp;
pp << "Device: " << deviceId << " Rate: " << sampleRate << "\n\n";
pp << "Input: " << inputDeviceId << " Output: " << outputDeviceId << " Rate: " << sampleRate << "\n\n";
const int SIZE_COLUMN_WIDTH = 8;
const int BUFFERS_COLUMN_WIDTH = 20;
@@ -461,7 +467,7 @@ void RunLatencyTest(
for (auto bufferCount : bufferCounts)
{
auto result = RunLatencyTest(deviceId, inputChannels,outputChannels, sampleRate, bufferSize, bufferCount);
auto result = RunLatencyTest(inputDeviceId, outputDeviceId, inputChannels,outputChannels, sampleRate, bufferSize, bufferCount);
pp.Column(column);
column += BUFFERS_COLUMN_WIDTH;
@@ -556,11 +562,14 @@ std:
{
ListDevices();
}
else if (parser.Arguments().size() == 1)
else if (parser.Arguments().size() >= 1 && parser.Arguments().size() <= 2)
{
inputChannels = ParseChannels(strInputChannels);
outputChannels = ParseChannels(strInputChannels);
RunLatencyTest(parser.Arguments()[0], inputChannels, outputChannels, sampleRate);
outputChannels = ParseChannels(strOutputChannels);
std::string inDev = parser.Arguments()[0];
std::string outDev = parser.Arguments().size() == 2 ? parser.Arguments()[1] : inDev;
RunLatencyTest(inDev, outDev, inputChannels, outputChannels, sampleRate);
}
else
{
+13 -20
View File
@@ -119,21 +119,10 @@ std::vector<AlsaDeviceInfo> PiPedalAlsaDevices::GetAlsaDevices()
int dir;
err = snd_pcm_hw_params_get_rate_min(params, &minRate, &dir);
if (err != 0)
if (err == 0)
{
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
}
else
{
int err2 = snd_pcm_hw_params_get_rate_max(params, &maxRate, &dir);
if (err2 != 0)
{
Lv2Log::warning(SS("Failed to get maximum sample rate for device '" << info.name_ << "'. Using default 48000."));
info.sampleRates_.push_back(48000);
}
else
int err2 = snd_pcm_hw_params_get_rate_max(params, &maxRate, &dir);
if (err2 == 0)
{
for (size_t i = 0; i < sizeof(RATES) / sizeof(RATES[0]); ++i)
{
@@ -142,14 +131,18 @@ std::vector<AlsaDeviceInfo> PiPedalAlsaDevices::GetAlsaDevices()
{
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);
}
}
}
else
{
Lv2Log::warning(SS("Failed to get maximum sample rate for device '" << info.name_ << "'."));
}
}
else
{
Lv2Log::warning(SS("Failed to get minimum sample rate for device '" << info.name_ << "'."));
err = 0; // continue using fallback rate for other parameters
}
err = snd_pcm_hw_params_get_buffer_size_min(params, &minBufferSize);
if (err == 0)