From 00cc9677399f4246aa8a74a0f85dbcf8ce6177a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 7 Nov 2015 19:32:28 +0100 Subject: [PATCH] Audio: make the frequency setting optional too. --- src/Magnum/Audio/Context.cpp | 24 ++++++++++++++---------- src/Magnum/Audio/Context.h | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Magnum/Audio/Context.cpp b/src/Magnum/Audio/Context.cpp index 0983ffed9..179e07425 100644 --- a/src/Magnum/Audio/Context.cpp +++ b/src/Magnum/Audio/Context.cpp @@ -125,7 +125,7 @@ bool Context::tryCreateContext(const Configuration& config) { Make sure to always add sufficient space at end of the attributes array.*/ Int attributes[]{ - ALC_FREQUENCY, config.frequency(), + 0, 0, 0, 0, 0, 0, 0, 0, @@ -134,24 +134,28 @@ bool Context::tryCreateContext(const Configuration& config) { }; /* last valid index in the attributes array */ - Int last = 1; + Int last = 0; + if(config.frequency() != -1) { + attributes[last++] = ALC_FREQUENCY; + attributes[last++] = config.frequency(); + } if(config.hrtf() != Configuration::Hrtf::Default) { - attributes[++last] = ALC_HRTF_SOFT; - attributes[++last] = (config.hrtf() == Configuration::Hrtf::Enabled) + attributes[last++] = ALC_HRTF_SOFT; + attributes[last++] = (config.hrtf() == Configuration::Hrtf::Enabled) ? ALC_TRUE : ALC_FALSE; } if(config.monoSourceCount() != -1) { - attributes[++last] = ALC_MONO_SOURCES; - attributes[++last] = config.monoSourceCount(); + attributes[last++] = ALC_MONO_SOURCES; + attributes[last++] = config.monoSourceCount(); } if(config.stereoSourceCount() != -1) { - attributes[++last] = ALC_STEREO_SOURCES; - attributes[++last] = config.stereoSourceCount(); + attributes[last++] = ALC_STEREO_SOURCES; + attributes[last++] = config.stereoSourceCount(); } if(config.refreshRate() != -1) { - attributes[++last] = ALC_REFRESH; - attributes[++last] = config.refreshRate(); + attributes[last++] = ALC_REFRESH; + attributes[last++] = config.refreshRate(); } _context = alcCreateContext(_device, attributes); diff --git a/src/Magnum/Audio/Context.h b/src/Magnum/Audio/Context.h index dbbdaed96..8cb4214bc 100644 --- a/src/Magnum/Audio/Context.h +++ b/src/Magnum/Audio/Context.h @@ -220,7 +220,7 @@ class MAGNUM_AUDIO_EXPORT Context::Configuration { /** @brief Constructor */ explicit Configuration(): - _frequency(44100), + _frequency(-1), _monoSources(-1), _stereoSources(-1), _refreshRate(-1) @@ -233,7 +233,7 @@ class MAGNUM_AUDIO_EXPORT Context::Configuration { * @brief Set sampling rate * @return Reference to self (for method chaining) * - * Default is `44100`. + * If set to `-1` (the default), system OpenAL configuration is used. */ Configuration& setFrequency(Int hz) { _frequency = hz;