From 25b2e07d3ba94fafeab80257ec9f101568a67e7c Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 2 Jan 2022 13:48:14 -0800 Subject: [PATCH] Added an option to `WasapiOut` to enable its internal resampler. --- src/plugins/wasapiout/WasapiOut.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/plugins/wasapiout/WasapiOut.cpp b/src/plugins/wasapiout/WasapiOut.cpp index a308d172b..70c40be43 100644 --- a/src/plugins/wasapiout/WasapiOut.cpp +++ b/src/plugins/wasapiout/WasapiOut.cpp @@ -47,6 +47,7 @@ #define PREF_DEVICE_ID "device_id" #define PREF_ENDPOINT_ROUTING "enable_audio_endpoint_routing" #define PREF_BUFFER_LENGTH_SECONDS "buffer_length_seconds" +#define PREF_DISABLE_INTERNAL_RESAMPLER "disable_internal_resampler" /* NOTE! device init and deinit logic was stolen and modified from QMMP's WASAPI output plugin! http://qmmp.ylsoftware.com/ */ @@ -106,6 +107,7 @@ extern "C" __declspec(dllexport) void SetPreferences(musik::core::sdk::IPreferen ::prefs = prefs; prefs->GetString(PREF_DEVICE_ID, nullptr, 0, ""); prefs->GetBool(PREF_ENDPOINT_ROUTING, false); + prefs->GetBool(PREF_DISABLE_INTERNAL_RESAMPLER, true); prefs->Save(); } @@ -113,6 +115,7 @@ extern "C" __declspec(dllexport) musik::core::sdk::ISchema* GetSchema() { auto schema = new TSchema<>(); schema->AddBool(PREF_ENDPOINT_ROUTING, false); schema->AddDouble(PREF_BUFFER_LENGTH_SECONDS, 1.0, 2, 0.25, 5.0); + schema->AddBool(PREF_DISABLE_INTERNAL_RESAMPLER, true); return schema; } @@ -120,6 +123,10 @@ static bool audioRoutingEnabled() { return ::prefs && prefs->GetBool(PREF_ENDPOINT_ROUTING, false); } +static bool disableInternalResampler() { + return ::prefs && prefs->GetBool(PREF_DISABLE_INTERNAL_RESAMPLER, true); +} + class NotificationClient : public IMMNotificationClient { public: NotificationClient(WasapiOut* owner) @@ -519,6 +526,12 @@ found_or_done: int WasapiOut::GetDefaultSampleRate() { int result = -1; Lock lock(this->stateMutex); + if (!disableInternalResampler()) { + /* if our internal sampler is not disabled, we'll let WASAPI take care of + resampling; return -1 here to have audio delivered in its native bitrate, + and don't allow decoders to resample. */ + return -1; + } this->InitializeAudioClient(); if (this->audioClient) { WAVEFORMATEX* deviceFormat = nullptr;