aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-11-20 01:37:19 -0800
committerChris Robinson <[email protected]>2020-11-20 01:37:19 -0800
commitf85e76285f8ad0824f6d6b1e02bb468597b006d4 (patch)
tree01d68abce2d52e328c133f2ddf59d6a1d4d55920
parentbee9917598b59f00b0bfa8145dd5b8968e25b12c (diff)
Disassociate internal voice enums from AL enums
-rw-r--r--al/source.cpp74
-rw-r--r--alc/alc.cpp1
-rw-r--r--alc/voice.cpp4
-rw-r--r--alc/voice.h62
4 files changed, 95 insertions, 46 deletions
diff --git a/al/source.cpp b/al/source.cpp
index c7676481..cb304d5f 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -819,6 +819,51 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
}
+al::optional<SpatializeMode> SpatializeModeFromEnum(ALenum mode)
+{
+ switch(mode)
+ {
+ case AL_FALSE: return al::make_optional(SpatializeMode::Off);
+ case AL_TRUE: return al::make_optional(SpatializeMode::On);
+ case AL_AUTO_SOFT: return al::make_optional(SpatializeMode::Auto);
+ }
+ WARN("Unsupported spatialize mode: 0x%04x\n", mode);
+ return al::nullopt;
+}
+ALenum EnumFromSpatializeMode(SpatializeMode mode)
+{
+ switch(mode)
+ {
+ case SpatializeMode::Off: return AL_FALSE;
+ case SpatializeMode::On: return AL_TRUE;
+ case SpatializeMode::Auto: return AL_AUTO_SOFT;
+ }
+ throw std::runtime_error{"Invalid SpatializeMode: "+std::to_string(int(mode))};
+}
+
+al::optional<DirectMode> DirectModeFromEnum(ALenum mode)
+{
+ switch(mode)
+ {
+ case AL_FALSE: return al::make_optional(DirectMode::Off);
+ case AL_DROP_UNMATCHED_SOFT: return al::make_optional(DirectMode::DropMismatch);
+ case AL_REMIX_UNMATCHED_SOFT: return al::make_optional(DirectMode::RemixMismatch);
+ }
+ WARN("Unsupported direct mode: 0x%04x\n", mode);
+ return al::nullopt;
+}
+ALenum EnumFromDirectMode(DirectMode mode)
+{
+ switch(mode)
+ {
+ case DirectMode::Off: return AL_FALSE;
+ case DirectMode::DropMismatch: return AL_DROP_UNMATCHED_SOFT;
+ case DirectMode::RemixMismatch: return AL_REMIX_UNMATCHED_SOFT;
+ }
+ throw std::runtime_error{"Invalid DirectMode: "+std::to_string(int(mode))};
+}
+
+
enum SourceProp : ALenum {
srcPitch = AL_PITCH,
srcGain = AL_GAIN,
@@ -1431,11 +1476,13 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
case AL_DIRECT_CHANNELS_SOFT:
CHECKSIZE(values, 1);
- CHECKVAL(values[0] == AL_FALSE || values[0] == AL_DROP_UNMATCHED_SOFT /* aka AL_TRUE */
- || values[0] == AL_REMIX_UNMATCHED_SOFT);
-
- Source->DirectChannels = static_cast<DirectMode>(values[0]);
- return UpdateSourceProps(Source, Context);
+ if(auto mode = DirectModeFromEnum(values[0]))
+ {
+ Source->DirectChannels = *mode;
+ return UpdateSourceProps(Source, Context);
+ }
+ Context->setError(AL_INVALID_VALUE, "Unsupported AL_DIRECT_CHANNELS_SOFT: 0x%04x\n",
+ values[0]);
case AL_DISTANCE_MODEL:
CHECKSIZE(values, 1);
@@ -1458,11 +1505,14 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
case AL_SOURCE_SPATIALIZE_SOFT:
CHECKSIZE(values, 1);
- CHECKVAL(values[0] >= AL_FALSE && values[0] <= AL_AUTO_SOFT);
-
- Source->mSpatialize = static_cast<SpatializeMode>(values[0]);
- return UpdateSourceProps(Source, Context);
-
+ if(auto mode = SpatializeModeFromEnum(values[0]))
+ {
+ Source->mSpatialize = *mode;
+ return UpdateSourceProps(Source, Context);
+ }
+ Context->setError(AL_INVALID_VALUE, "Unsupported AL_SOURCE_SPATIALIZE_SOFT: 0x%04x\n",
+ values[0]);
+ return false;
case AL_AUXILIARY_SEND_FILTER:
CHECKSIZE(values, 3);
@@ -1982,7 +2032,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
case AL_DIRECT_CHANNELS_SOFT:
CHECKSIZE(values, 1);
- values[0] = static_cast<int>(Source->DirectChannels);
+ values[0] = EnumFromDirectMode(Source->DirectChannels);
return true;
case AL_DISTANCE_MODEL:
@@ -1997,7 +2047,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
case AL_SOURCE_SPATIALIZE_SOFT:
CHECKSIZE(values, 1);
- values[0] = static_cast<int>(Source->mSpatialize);
+ values[0] = EnumFromSpatializeMode(Source->mSpatialize);
return true;
/* 1x float/double */
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 5ef1e6d8..073fe6bf 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -58,6 +58,7 @@
#include "AL/efx.h"
#include "al/auxeffectslot.h"
+#include "al/buffer.h"
#include "al/effect.h"
#include "al/event.h"
#include "al/filter.h"
diff --git a/alc/voice.cpp b/alc/voice.cpp
index 5d23f376..ee7c2bcb 100644
--- a/alc/voice.cpp
+++ b/alc/voice.cpp
@@ -184,7 +184,7 @@ void aluInitMixer()
namespace {
-void SendSourceStoppedEvent(ALCcontext *context, ALuint id)
+void SendSourceStoppedEvent(ALCcontext *context, uint id)
{
RingBuffer *ring{context->mAsyncEvents.get()};
auto evt_vec = ring->getWriteVector();
@@ -445,7 +445,7 @@ void DoNfcMix(const al::span<const float> samples, FloatBufferLine *OutBuffer, D
} // namespace
-void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToDo)
+void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
{
static constexpr std::array<float,MAX_OUTPUT_CHANNELS> SilentTarget{};
diff --git a/alc/voice.h b/alc/voice.h
index 69efbf82..5900d849 100644
--- a/alc/voice.h
+++ b/alc/voice.h
@@ -3,10 +3,6 @@
#include <array>
-#include "AL/al.h"
-#include "AL/alext.h"
-
-#include "al/buffer.h"
#include "almalloc.h"
#include "alspan.h"
#include "alu.h"
@@ -21,17 +17,19 @@ struct EffectSlot;
struct BufferlistItem;
enum class DistanceModel;
+using uint = unsigned int;
+
enum class SpatializeMode : unsigned char {
- Off = AL_FALSE,
- On = AL_TRUE,
- Auto = AL_AUTO_SOFT
+ Off,
+ On,
+ Auto
};
enum class DirectMode : unsigned char {
- Off = AL_FALSE,
- DropMismatch = AL_DROP_UNMATCHED_SOFT,
- RemixMismatch = AL_REMIX_UNMATCHED_SOFT
+ Off,
+ DropMismatch,
+ RemixMismatch
};
enum class Resampler {
@@ -54,8 +52,8 @@ extern Resampler ResamplerDefault;
*/
struct BsincState {
float sf; /* Scale interpolation factor. */
- ALuint m; /* Coefficient count. */
- ALuint l; /* Left coefficient offset. */
+ uint m; /* Coefficient count. */
+ uint l; /* Left coefficient offset. */
/* Filter coefficients, followed by the phase, scale, and scale-phase
* delta coefficients. Starting at phase index 0, each subsequent phase
* index follows contiguously.
@@ -68,9 +66,9 @@ union InterpState {
};
using ResamplerFunc = const float*(*)(const InterpState *state, const float *RESTRICT src,
- ALuint frac, ALuint increment, const al::span<float> dst);
+ uint frac, uint increment, const al::span<float> dst);
-ResamplerFunc PrepareResampler(Resampler resampler, ALuint increment, InterpState *state);
+ResamplerFunc PrepareResampler(Resampler resampler, uint increment, InterpState *state);
enum {
@@ -83,7 +81,7 @@ enum {
struct MixHrtfFilter {
const HrirArray *Coeffs;
- std::array<ALuint,2> Delay;
+ std::array<uint,2> Delay;
float Gain;
float GainStep;
};
@@ -177,13 +175,13 @@ struct VoicePropsItem : public VoiceProps {
DEF_NEWDEL(VoicePropsItem)
};
-constexpr ALuint VoiceIsStatic{ 1u<<0};
-constexpr ALuint VoiceIsCallback{ 1u<<1};
-constexpr ALuint VoiceIsAmbisonic{ 1u<<2}; /* Needs HF scaling for ambisonic upsampling. */
-constexpr ALuint VoiceCallbackStopped{1u<<3};
-constexpr ALuint VoiceIsFading{ 1u<<4}; /* Use gain stepping for smooth transitions. */
-constexpr ALuint VoiceHasHrtf{ 1u<<5};
-constexpr ALuint VoiceHasNfc{ 1u<<6};
+constexpr uint VoiceIsStatic{ 1u<<0};
+constexpr uint VoiceIsCallback{ 1u<<1};
+constexpr uint VoiceIsAmbisonic{ 1u<<2}; /* Needs HF scaling for ambisonic upsampling. */
+constexpr uint VoiceCallbackStopped{1u<<3};
+constexpr uint VoiceIsFading{ 1u<<4}; /* Use gain stepping for smooth transitions. */
+constexpr uint VoiceHasHrtf{ 1u<<5};
+constexpr uint VoiceHasNfc{ 1u<<6};
struct Voice {
enum State {
@@ -197,7 +195,7 @@ struct Voice {
VoiceProps mProps;
- std::atomic<ALuint> mSourceID{0u};
+ std::atomic<uint> mSourceID{0u};
std::atomic<State> mPlayState{Stopped};
std::atomic<bool> mPendingChange{false};
@@ -205,9 +203,9 @@ struct Voice {
* Source offset in samples, relative to the currently playing buffer, NOT
* the whole queue.
*/
- std::atomic<ALuint> mPosition;
+ std::atomic<uint> mPosition;
/** Fractional (fixed-point) offset to the next sample. */
- std::atomic<ALuint> mPositionFrac;
+ std::atomic<uint> mPositionFrac;
/* Current buffer queue item being played. */
std::atomic<BufferlistItem*> mCurrentBuffer;
@@ -219,21 +217,21 @@ struct Voice {
/* Properties for the attached buffer(s). */
FmtChannels mFmtChannels;
- ALuint mFrequency;
- ALuint mSampleSize;
+ uint mFrequency;
+ uint mSampleSize;
AmbiLayout mAmbiLayout;
AmbiScaling mAmbiScaling;
- ALuint mAmbiOrder;
+ uint mAmbiOrder;
/** Current target parameters used for mixing. */
- ALuint mStep{0};
+ uint mStep{0};
ResamplerFunc mResampler;
InterpState mResampleState;
- ALuint mFlags{};
- ALuint mNumCallbackSamples{0};
+ uint mFlags{};
+ uint mNumCallbackSamples{0};
struct TargetData {
int FilterType;
@@ -258,7 +256,7 @@ struct Voice {
~Voice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); }
Voice& operator=(const Voice&) = delete;
- void mix(const State vstate, ALCcontext *Context, const ALuint SamplesToDo);
+ void mix(const State vstate, ALCcontext *Context, const uint SamplesToDo);
DEF_NEWDEL(Voice)
};