Added an option to WasapiOut to enable its internal resampler.

This commit is contained in:
casey langen 2022-01-02 13:48:14 -08:00
parent 9fb2c6412d
commit 25b2e07d3b

View File

@ -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;