Freq Bug
Temporary default frequency causing crash when the frequency is not available.
This commit is contained in:
@@ -59,6 +59,7 @@ namespace pipedal
|
||||
}
|
||||
|
||||
uint64_t GetSampleRate() const { return sampleRate_; }
|
||||
void SetSampleRate(uint64_t sampleRate) { sampleRate_ = sampleRate; }
|
||||
uint32_t GetBufferSize() const { return bufferSize_; }
|
||||
uint32_t GetNumberOfBuffers() const { return numberOfBuffers_; }
|
||||
const std::string &GetAlsaInputDevice() const { return alsaInputDevice_; }
|
||||
|
||||
@@ -1376,6 +1376,31 @@ void PiPedalModel::RestartAudio(bool useDummyAudioDriver)
|
||||
{
|
||||
jackServerSettings.UseDummyAudioDevice();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto devices = GetAlsaDevices();
|
||||
AlsaDeviceInfo inDev, outDev;
|
||||
bool inFound = false, outFound = false;
|
||||
for (auto &d : devices)
|
||||
{
|
||||
if (d.id_ == jackServerSettings.GetAlsaInputDevice())
|
||||
{
|
||||
inDev = d;
|
||||
inFound = true;
|
||||
}
|
||||
if (d.id_ == jackServerSettings.GetAlsaOutputDevice())
|
||||
{
|
||||
outDev = d;
|
||||
outFound = true;
|
||||
}
|
||||
}
|
||||
if (inFound && outFound)
|
||||
{
|
||||
uint32_t best = SelectBestSampleRate(inDev, outDev, (uint32_t)jackServerSettings.GetSampleRate());
|
||||
jackServerSettings.SetSampleRate(best);
|
||||
this->jackServerSettings.SetSampleRate(best);
|
||||
}
|
||||
}
|
||||
|
||||
auto jackConfiguration = this->jackConfiguration;
|
||||
jackConfiguration.AlsaInitialize(jackServerSettings);
|
||||
@@ -2747,6 +2772,31 @@ static bool HasAlsaDevice(const std::vector<AlsaDeviceInfo> devices, const std::
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint32_t SelectBestSampleRate(const AlsaDeviceInfo &inDev, const AlsaDeviceInfo &outDev, uint32_t desiredRate)
|
||||
{
|
||||
std::vector<uint32_t> intersection;
|
||||
for (auto sr : inDev.sampleRates_)
|
||||
{
|
||||
if (std::find(outDev.sampleRates_.begin(), outDev.sampleRates_.end(), sr) != outDev.sampleRates_.end())
|
||||
{
|
||||
intersection.push_back(sr);
|
||||
}
|
||||
}
|
||||
if (intersection.empty()) return desiredRate;
|
||||
if (desiredRate != 0 && std::find(intersection.begin(), intersection.end(), desiredRate) != intersection.end())
|
||||
{
|
||||
return desiredRate;
|
||||
}
|
||||
uint32_t best = 0;
|
||||
for (auto sr : intersection)
|
||||
{
|
||||
if (sr == 48000) return 48000;
|
||||
if (sr <= 48000 && sr > best) best = sr;
|
||||
}
|
||||
if (best == 0) best = intersection.back();
|
||||
return best;
|
||||
}
|
||||
|
||||
void PiPedalModel::StartHotspotMonitoring()
|
||||
{
|
||||
this->avahiService = std::make_unique<AvahiService>();
|
||||
|
||||
Reference in New Issue
Block a user