diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-08-03 11:54:08 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-08-03 11:54:08 +1000 |
commit | 908fa1ee606b80eec47c6fc70ce018308ef06e98 (patch) | |
tree | 61b3248cb01c1946f169612a15f04e7cbd4c068a /source/frontend/StarVoice.cpp | |
parent | 497c6efc5555f3c45b7e092b461f39a3d89de865 (diff) |
Add libsamplerate, make Voice bitrate configurable
Diffstat (limited to 'source/frontend/StarVoice.cpp')
-rw-r--r-- | source/frontend/StarVoice.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/source/frontend/StarVoice.cpp b/source/frontend/StarVoice.cpp index 0d56089..1328846 100644 --- a/source/frontend/StarVoice.cpp +++ b/source/frontend/StarVoice.cpp @@ -211,14 +211,26 @@ void Voice::loadJson(Json const& config, bool skipSave) { m_lastInputTime = 0; } + bool shouldResetEncoder = false; if (auto channelMode = config.optString("channelMode")) { if (change(m_channelMode, VoiceChannelModeNames.getLeft(*channelMode), changed)) { closeDevice(); - resetEncoder(); + shouldResetEncoder = true; resetDevice(); } } + // not saving this setting to disk, as it's just for audiophiles + // don't want someone fudging their bitrate from the intended defaults and forgetting + if (auto bitrate = config.opt("bitrate")) { + unsigned newBitrate = bitrate->canConvert(Json::Type::Int) + ? clamp((unsigned)bitrate->toUInt(), 6000u, 510000u) : 0; + shouldResetEncoder |= change(m_bitrate, newBitrate, changed); + } + + if (shouldResetEncoder) + resetEncoder(); + if (changed && !skipSave) scheduleSave(); } @@ -607,7 +619,8 @@ void Voice::resetEncoder() { int channels = encoderChannels(); MutexLocker locker(m_threadMutex); m_encoder.reset(createEncoder(channels)); - opus_encoder_ctl(m_encoder.get(), OPUS_SET_BITRATE(channels == 2 ? 50000 : 24000)); + int bitrate = m_bitrate > 0 ? (int)m_bitrate : (channels == 2 ? 50000 : 24000); + opus_encoder_ctl(m_encoder.get(), OPUS_SET_BITRATE(bitrate)); } void Voice::resetDevice() { |