Add libsamplerate, make Voice bitrate configurable

This commit is contained in:
Kae 2024-08-03 11:54:08 +10:00
parent 497c6efc55
commit 908fa1ee60
6 changed files with 28 additions and 4 deletions

View File

@ -177,6 +177,7 @@ endif()
message(STATUS "Using Lua API checks: ${STAR_LUA_APICHECK}") message(STATUS "Using Lua API checks: ${STAR_LUA_APICHECK}")
message(STATUS "Using jemalloc: ${STAR_USE_JEMALLOC}") message(STATUS "Using jemalloc: ${STAR_USE_JEMALLOC}")
message(STATUS "Using mimalloc: ${STAR_USE_MIMALLOC}") message(STATUS "Using mimalloc: ${STAR_USE_MIMALLOC}")
message(STATUS "Using rpmalloc: ${STAR_USE_RPMALLOC}")
# Set C defines and cmake variables based on the build settings we have now # Set C defines and cmake variables based on the build settings we have now
# determined... # determined...
@ -486,8 +487,10 @@ set(STAR_EXT_LIBS ${STAR_EXT_LIBS}
if(STAR_BUILD_GUI) if(STAR_BUILD_GUI)
find_package(SDL2 CONFIG REQUIRED) find_package(SDL2 CONFIG REQUIRED)
find_package(SampleRate CONFIG REQUIRED)
set(STAR_EXT_GUI_LIBS set(STAR_EXT_GUI_LIBS
SampleRate::samplerate
$<TARGET_NAME_IF_EXISTS:SDL2::SDL2main> $<TARGET_NAME_IF_EXISTS:SDL2::SDL2main>
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static> $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
) )

View File

@ -271,6 +271,9 @@ public:
#endif #endif
Logger::info("Application: Initializing SDL Audio"); Logger::info("Application: Initializing SDL Audio");
#if SDL_VERSION_ATLEAST(2, 0, 26)
SDL_SetHint(SDL_HINT_AUDIO_RESAMPLING_MODE, "fast");
#endif
if (SDL_InitSubSystem(SDL_INIT_AUDIO)) if (SDL_InitSubSystem(SDL_INIT_AUDIO))
throw ApplicationException(strf("Couldn't initialize SDL Audio: {}", SDL_GetError())); throw ApplicationException(strf("Couldn't initialize SDL Audio: {}", SDL_GetError()));

View File

@ -211,14 +211,26 @@ void Voice::loadJson(Json const& config, bool skipSave) {
m_lastInputTime = 0; m_lastInputTime = 0;
} }
bool shouldResetEncoder = false;
if (auto channelMode = config.optString("channelMode")) { if (auto channelMode = config.optString("channelMode")) {
if (change(m_channelMode, VoiceChannelModeNames.getLeft(*channelMode), changed)) { if (change(m_channelMode, VoiceChannelModeNames.getLeft(*channelMode), changed)) {
closeDevice(); closeDevice();
resetEncoder(); shouldResetEncoder = true;
resetDevice(); 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) if (changed && !skipSave)
scheduleSave(); scheduleSave();
} }
@ -607,7 +619,8 @@ void Voice::resetEncoder() {
int channels = encoderChannels(); int channels = encoderChannels();
MutexLocker locker(m_threadMutex); MutexLocker locker(m_threadMutex);
m_encoder.reset(createEncoder(channels)); 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() { void Voice::resetDevice() {

View File

@ -195,6 +195,7 @@ private:
Maybe<String> m_deviceName; Maybe<String> m_deviceName;
VoiceInputMode m_inputMode; VoiceInputMode m_inputMode;
VoiceChannelMode m_channelMode; VoiceChannelMode m_channelMode;
unsigned m_bitrate = 0;
ThreadFunction<void> m_thread; ThreadFunction<void> m_thread;
Mutex m_threadMutex; Mutex m_threadMutex;

View File

@ -2,7 +2,7 @@
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-configuration.schema.json", "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-configuration.schema.json",
"default-registry": { "default-registry": {
"kind": "git", "kind": "git",
"baseline": "f4456c1b974131b8467c7371a3c302b7f58a99f2", "baseline": "1de2026f28ead93ff1773e6e680387643e914ea1",
"repository": "https://github.com/microsoft/vcpkg" "repository": "https://github.com/microsoft/vcpkg"
} }
} }

View File

@ -2,7 +2,11 @@
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [ "dependencies": [
"glew", "glew",
"sdl2", "libsamplerate",
{
"name": "sdl2",
"features": [ "samplerate" ]
},
"libvorbis", "libvorbis",
"zlib", "zlib",
"freetype", "freetype",