From 83432a7e5c7f565a08c41bb104ae25286c5fc82b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Jul 2019 19:09:07 -0700 Subject: Move some headers out of the Include subdirectory --- CMakeLists.txt | 16 ++--- OpenAL32/Include/alAuxEffectSlot.h | 100 ----------------------------- OpenAL32/Include/alBuffer.h | 120 ----------------------------------- OpenAL32/Include/alEffect.h | 59 ----------------- OpenAL32/Include/alError.h | 22 ------- OpenAL32/Include/alFilter.h | 56 ---------------- OpenAL32/Include/alListener.h | 59 ----------------- OpenAL32/Include/alSource.h | 127 ------------------------------------- OpenAL32/alAuxEffectSlot.h | 100 +++++++++++++++++++++++++++++ OpenAL32/alBuffer.h | 120 +++++++++++++++++++++++++++++++++++ OpenAL32/alEffect.h | 59 +++++++++++++++++ OpenAL32/alError.h | 22 +++++++ OpenAL32/alFilter.h | 56 ++++++++++++++++ OpenAL32/alListener.h | 59 +++++++++++++++++ OpenAL32/alSource.h | 127 +++++++++++++++++++++++++++++++++++++ 15 files changed, 551 insertions(+), 551 deletions(-) delete mode 100644 OpenAL32/Include/alAuxEffectSlot.h delete mode 100644 OpenAL32/Include/alBuffer.h delete mode 100644 OpenAL32/Include/alEffect.h delete mode 100644 OpenAL32/Include/alError.h delete mode 100644 OpenAL32/Include/alFilter.h delete mode 100644 OpenAL32/Include/alListener.h delete mode 100644 OpenAL32/Include/alSource.h create mode 100644 OpenAL32/alAuxEffectSlot.h create mode 100644 OpenAL32/alBuffer.h create mode 100644 OpenAL32/alEffect.h create mode 100644 OpenAL32/alError.h create mode 100644 OpenAL32/alFilter.h create mode 100644 OpenAL32/alListener.h create mode 100644 OpenAL32/alSource.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 190692c8..65e9ebd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -619,21 +619,21 @@ SET(COMMON_OBJS common/vecmat.h ) SET(OPENAL_OBJS - OpenAL32/Include/alAuxEffectSlot.h OpenAL32/alAuxEffectSlot.cpp - OpenAL32/Include/alBuffer.h + OpenAL32/alAuxEffectSlot.h OpenAL32/alBuffer.cpp - OpenAL32/Include/alEffect.h + OpenAL32/alBuffer.h OpenAL32/alEffect.cpp - OpenAL32/Include/alError.h + OpenAL32/alEffect.h OpenAL32/alError.cpp + OpenAL32/alError.h OpenAL32/alExtension.cpp - OpenAL32/Include/alFilter.h OpenAL32/alFilter.cpp - OpenAL32/Include/alListener.h + OpenAL32/alFilter.h OpenAL32/alListener.cpp - OpenAL32/Include/alSource.h + OpenAL32/alListener.h OpenAL32/alSource.cpp + OpenAL32/alSource.h OpenAL32/alState.cpp OpenAL32/event.cpp ) @@ -1313,7 +1313,7 @@ TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET} ${INC_PATHS} ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/alc - ${OpenAL_SOURCE_DIR}/OpenAL32/Include + ${OpenAL_SOURCE_DIR}/OpenAL32 ${OpenAL_SOURCE_DIR}/common ) diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h deleted file mode 100644 index b6976d13..00000000 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef _AL_AUXEFFECTSLOT_H_ -#define _AL_AUXEFFECTSLOT_H_ - -#include - -#include "alcmain.h" -#include "alEffect.h" -#include "ambidefs.h" -#include "effects/base.h" - -#include "almalloc.h" -#include "atomic.h" - - -struct ALeffectslot; - - -using ALeffectslotArray = al::FlexArray; - - -struct ALeffectslotProps { - ALfloat Gain; - ALboolean AuxSendAuto; - ALeffectslot *Target; - - ALenum Type; - EffectProps Props; - - EffectState *State; - - std::atomic next; -}; - - -struct ALeffectslot { - ALfloat Gain{1.0f}; - ALboolean AuxSendAuto{AL_TRUE}; - ALeffectslot *Target{nullptr}; - - struct { - ALenum Type{AL_EFFECT_NULL}; - EffectProps Props{}; - - EffectState *State{nullptr}; - } Effect; - - std::atomic_flag PropsClean; - - RefCount ref{0u}; - - std::atomic Update{nullptr}; - - struct { - ALfloat Gain{1.0f}; - ALboolean AuxSendAuto{AL_TRUE}; - ALeffectslot *Target{nullptr}; - - ALenum EffectType{AL_EFFECT_NULL}; - EffectProps mEffectProps{}; - EffectState *mEffectState{nullptr}; - - ALfloat RoomRolloff{0.0f}; /* Added to the source's room rolloff, not multiplied. */ - ALfloat DecayTime{0.0f}; - ALfloat DecayLFRatio{0.0f}; - ALfloat DecayHFRatio{0.0f}; - ALboolean DecayHFLimit{AL_FALSE}; - ALfloat AirAbsorptionGainHF{1.0f}; - } Params; - - /* Self ID */ - ALuint id{}; - - /* Mixing buffer used by the Wet mix. */ - al::vector MixBuffer; - - /* Wet buffer configuration is ACN channel order with N3D scaling. - * Consequently, effects that only want to work with mono input can use - * channel 0 by itself. Effects that want multichannel can process the - * ambisonics signal and make a B-Format source pan. - */ - MixParams Wet; - - ALeffectslot() { PropsClean.test_and_set(std::memory_order_relaxed); } - ALeffectslot(const ALeffectslot&) = delete; - ALeffectslot& operator=(const ALeffectslot&) = delete; - ~ALeffectslot(); - - static ALeffectslotArray *CreatePtrArray(size_t count) noexcept; - - DEF_PLACE_NEWDEL() -}; - -ALenum InitEffectSlot(ALeffectslot *slot); -void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context); -void UpdateAllEffectSlotProps(ALCcontext *context); - - -ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); - -#endif diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h deleted file mode 100644 index 92655784..00000000 --- a/OpenAL32/Include/alBuffer.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef _AL_BUFFER_H_ -#define _AL_BUFFER_H_ - -#include "AL/alc.h" -#include "AL/al.h" -#include "AL/alext.h" - -#include "inprogext.h" -#include "atomic.h" -#include "vector.h" -#include "albyte.h" - - -/* User formats */ -enum UserFmtType : unsigned char { - UserFmtUByte, - UserFmtShort, - UserFmtFloat, - UserFmtDouble, - UserFmtMulaw, - UserFmtAlaw, - UserFmtIMA4, - UserFmtMSADPCM, -}; -enum UserFmtChannels : unsigned char { - UserFmtMono, - UserFmtStereo, - UserFmtRear, - UserFmtQuad, - UserFmtX51, /* (WFX order) */ - UserFmtX61, /* (WFX order) */ - UserFmtX71, /* (WFX order) */ - UserFmtBFormat2D, /* WXY */ - UserFmtBFormat3D, /* WXYZ */ -}; - -ALsizei BytesFromUserFmt(UserFmtType type); -ALsizei ChannelsFromUserFmt(UserFmtChannels chans); -inline ALsizei FrameSizeFromUserFmt(UserFmtChannels chans, UserFmtType type) -{ return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type); } - - -/* Storable formats */ -enum FmtType : unsigned char { - FmtUByte = UserFmtUByte, - FmtShort = UserFmtShort, - FmtFloat = UserFmtFloat, - FmtDouble = UserFmtDouble, - FmtMulaw = UserFmtMulaw, - FmtAlaw = UserFmtAlaw, -}; -enum FmtChannels : unsigned char { - FmtMono = UserFmtMono, - FmtStereo = UserFmtStereo, - FmtRear = UserFmtRear, - FmtQuad = UserFmtQuad, - FmtX51 = UserFmtX51, - FmtX61 = UserFmtX61, - FmtX71 = UserFmtX71, - FmtBFormat2D = UserFmtBFormat2D, - FmtBFormat3D = UserFmtBFormat3D, -}; -#define MAX_INPUT_CHANNELS (8) - -/* DevFmtType traits, providing the type, etc given a DevFmtType. */ -template -struct FmtTypeTraits { }; - -template<> -struct FmtTypeTraits { using Type = ALubyte; }; -template<> -struct FmtTypeTraits { using Type = ALshort; }; -template<> -struct FmtTypeTraits { using Type = ALfloat; }; -template<> -struct FmtTypeTraits { using Type = ALdouble; }; -template<> -struct FmtTypeTraits { using Type = ALubyte; }; -template<> -struct FmtTypeTraits { using Type = ALubyte; }; - - -ALsizei BytesFromFmt(FmtType type); -ALsizei ChannelsFromFmt(FmtChannels chans); -inline ALsizei FrameSizeFromFmt(FmtChannels chans, FmtType type) -{ return ChannelsFromFmt(chans) * BytesFromFmt(type); } - - -struct ALbuffer { - al::vector mData; - - ALsizei Frequency{0}; - ALbitfieldSOFT Access{0u}; - ALsizei SampleLen{0}; - - FmtChannels mFmtChannels{}; - FmtType mFmtType{}; - - UserFmtType OriginalType{}; - ALsizei OriginalSize{0}; - ALsizei OriginalAlign{0}; - - ALsizei LoopStart{0}; - ALsizei LoopEnd{0}; - - std::atomic UnpackAlign{0}; - std::atomic PackAlign{0}; - - ALbitfieldSOFT MappedAccess{0u}; - ALsizei MappedOffset{0}; - ALsizei MappedSize{0}; - - /* Number of times buffer was attached to a source (deletion can only occur when 0) */ - RefCount ref{0u}; - - /* Self ID */ - ALuint id{0}; -}; - -#endif diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h deleted file mode 100644 index d43aa206..00000000 --- a/OpenAL32/Include/alEffect.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _AL_EFFECT_H_ -#define _AL_EFFECT_H_ - -#include "alcmain.h" -#include "effects/base.h" - - -enum { - EAXREVERB_EFFECT = 0, - REVERB_EFFECT, - AUTOWAH_EFFECT, - CHORUS_EFFECT, - COMPRESSOR_EFFECT, - DISTORTION_EFFECT, - ECHO_EFFECT, - EQUALIZER_EFFECT, - FLANGER_EFFECT, - FSHIFTER_EFFECT, - MODULATOR_EFFECT, - PSHIFTER_EFFECT, - VMORPHER_EFFECT, - DEDICATED_EFFECT, - - MAX_EFFECTS -}; -extern ALboolean DisabledEffects[MAX_EFFECTS]; - -extern ALfloat ReverbBoost; - -struct EffectList { - const char name[16]; - int type; - ALenum val; -}; -extern const EffectList gEffectList[15]; - - -struct ALeffect { - // Effect type (AL_EFFECT_NULL, ...) - ALenum type{AL_EFFECT_NULL}; - - EffectProps Props{}; - - const EffectVtable *vtab{nullptr}; - - /* Self ID */ - ALuint id{0u}; -}; - -inline ALboolean IsReverbEffect(ALenum type) -{ return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; } - -EffectStateFactory *getFactoryByType(ALenum type); - -void InitEffect(ALeffect *effect); - -void LoadReverbPreset(const char *name, ALeffect *effect); - -#endif diff --git a/OpenAL32/Include/alError.h b/OpenAL32/Include/alError.h deleted file mode 100644 index 0abd6b26..00000000 --- a/OpenAL32/Include/alError.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _AL_ERROR_H_ -#define _AL_ERROR_H_ - -#include "alcmain.h" -#include "logging.h" - - -extern bool TrapALError; - -void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) DECL_FORMAT(printf, 3, 4); - -#define SETERR_GOTO(ctx, err, lbl, ...) do { \ - alSetError((ctx), (err), __VA_ARGS__); \ - goto lbl; \ -} while(0) - -#define SETERR_RETURN(ctx, err, retval, ...) do { \ - alSetError((ctx), (err), __VA_ARGS__); \ - return retval; \ -} while(0) - -#endif diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h deleted file mode 100644 index 1c033ac3..00000000 --- a/OpenAL32/Include/alFilter.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _AL_FILTER_H_ -#define _AL_FILTER_H_ - -#include "AL/alc.h" -#include "AL/al.h" - - -#define LOWPASSFREQREF (5000.0f) -#define HIGHPASSFREQREF (250.0f) - - -struct ALfilter; - -struct ALfilterVtable { - void (*const setParami)(ALfilter *filter, ALCcontext *context, ALenum param, ALint val); - void (*const setParamiv)(ALfilter *filter, ALCcontext *context, ALenum param, const ALint *vals); - void (*const setParamf)(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val); - void (*const setParamfv)(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals); - - void (*const getParami)(ALfilter *filter, ALCcontext *context, ALenum param, ALint *val); - void (*const getParamiv)(ALfilter *filter, ALCcontext *context, ALenum param, ALint *vals); - void (*const getParamf)(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val); - void (*const getParamfv)(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals); -}; - -#define DEFINE_ALFILTER_VTABLE(T) \ -const ALfilterVtable T##_vtable = { \ - T##_setParami, T##_setParamiv, T##_setParamf, T##_setParamfv, \ - T##_getParami, T##_getParamiv, T##_getParamf, T##_getParamfv, \ -} - -struct ALfilter { - // Filter type (AL_FILTER_NULL, ...) - ALenum type; - - ALfloat Gain; - ALfloat GainHF; - ALfloat HFReference; - ALfloat GainLF; - ALfloat LFReference; - - const ALfilterVtable *vtab; - - /* Self ID */ - ALuint id; -}; -#define ALfilter_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v)) -#define ALfilter_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v)) -#define ALfilter_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v)) -#define ALfilter_setParamfv(o, c, p, v) ((o)->vtab->setParamfv(o, c, p, v)) -#define ALfilter_getParami(o, c, p, v) ((o)->vtab->getParami(o, c, p, v)) -#define ALfilter_getParamf(o, c, p, v) ((o)->vtab->getParamf(o, c, p, v)) -#define ALfilter_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v)) -#define ALfilter_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v)) - -#endif diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h deleted file mode 100644 index 4d59dbf9..00000000 --- a/OpenAL32/Include/alListener.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _AL_LISTENER_H_ -#define _AL_LISTENER_H_ - -#include - -#include "AL/alc.h" -#include "AL/al.h" -#include "AL/alext.h" - -#include "atomic.h" -#include "vecmat.h" - -enum class DistanceModel; - - -struct ALlistenerProps { - std::array Position; - std::array Velocity; - std::array OrientAt; - std::array OrientUp; - ALfloat Gain; - - std::atomic next; -}; - -struct ALlistener { - std::array Position{{0.0f, 0.0f, 0.0f}}; - std::array Velocity{{0.0f, 0.0f, 0.0f}}; - std::array OrientAt{{0.0f, 0.0f, -1.0f}}; - std::array OrientUp{{0.0f, 1.0f, 0.0f}}; - ALfloat Gain{1.0f}; - - std::atomic_flag PropsClean; - - /* Pointer to the most recent property values that are awaiting an update. - */ - std::atomic Update{nullptr}; - - struct { - alu::Matrix Matrix; - alu::Vector Velocity; - - ALfloat Gain; - ALfloat MetersPerUnit; - - ALfloat DopplerFactor; - ALfloat SpeedOfSound; /* in units per sec! */ - ALfloat ReverbSpeedOfSound; /* in meters per sec! */ - - ALboolean SourceDistanceModel; - DistanceModel mDistanceModel; - } Params; - - ALlistener() { PropsClean.test_and_set(std::memory_order_relaxed); } -}; - -void UpdateListenerProps(ALCcontext *context); - -#endif diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h deleted file mode 100644 index 330bb9f4..00000000 --- a/OpenAL32/Include/alSource.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef _AL_SOURCE_H_ -#define _AL_SOURCE_H_ - -#include - -#include "alcmain.h" -#include "alu.h" -#include "hrtf.h" -#include "almalloc.h" -#include "atomic.h" - -#define DEFAULT_SENDS 2 - -struct ALbuffer; -struct ALsource; -struct ALeffectslot; - - -struct ALbufferlistitem { - std::atomic next; - ALsizei max_samples; - ALsizei num_buffers; - ALbuffer *buffers[]; - - static constexpr size_t Sizeof(size_t num_buffers) noexcept - { - return maxz(offsetof(ALbufferlistitem, buffers) + sizeof(ALbuffer*)*num_buffers, - sizeof(ALbufferlistitem)); - } -}; - - -struct ALsource { - /** Source properties. */ - ALfloat Pitch; - ALfloat Gain; - ALfloat OuterGain; - ALfloat MinGain; - ALfloat MaxGain; - ALfloat InnerAngle; - ALfloat OuterAngle; - ALfloat RefDistance; - ALfloat MaxDistance; - ALfloat RolloffFactor; - std::array Position; - std::array Velocity; - std::array Direction; - std::array OrientAt; - std::array OrientUp; - ALboolean HeadRelative; - ALboolean Looping; - DistanceModel mDistanceModel; - Resampler mResampler; - ALboolean DirectChannels; - SpatializeMode mSpatialize; - - ALboolean DryGainHFAuto; - ALboolean WetGainAuto; - ALboolean WetGainHFAuto; - ALfloat OuterGainHF; - - ALfloat AirAbsorptionFactor; - ALfloat RoomRolloffFactor; - ALfloat DopplerFactor; - - /* NOTE: Stereo pan angles are specified in radians, counter-clockwise - * rather than clockwise. - */ - std::array StereoPan; - - ALfloat Radius; - - /** Direct filter and auxiliary send info. */ - struct { - ALfloat Gain; - ALfloat GainHF; - ALfloat HFReference; - ALfloat GainLF; - ALfloat LFReference; - } Direct; - struct SendData { - ALeffectslot *Slot; - ALfloat Gain; - ALfloat GainHF; - ALfloat HFReference; - ALfloat GainLF; - ALfloat LFReference; - }; - al::vector Send; - - /** - * Last user-specified offset, and the offset type (bytes, samples, or - * seconds). - */ - ALdouble Offset; - ALenum OffsetType; - - /** Source type (static, streaming, or undetermined) */ - ALint SourceType; - - /** Source state (initial, playing, paused, or stopped) */ - ALenum state; - - /** Source Buffer Queue head. */ - ALbufferlistitem *queue; - - std::atomic_flag PropsClean; - - /* Index into the context's Voices array. Lazily updated, only checked and - * reset when looking up the voice. - */ - ALint VoiceIdx; - - /** Self ID */ - ALuint id; - - - ALsource(ALsizei num_sends); - ~ALsource(); - - ALsource(const ALsource&) = delete; - ALsource& operator=(const ALsource&) = delete; -}; - -void UpdateAllSourceProps(ALCcontext *context); - -#endif diff --git a/OpenAL32/alAuxEffectSlot.h b/OpenAL32/alAuxEffectSlot.h new file mode 100644 index 00000000..b6976d13 --- /dev/null +++ b/OpenAL32/alAuxEffectSlot.h @@ -0,0 +1,100 @@ +#ifndef _AL_AUXEFFECTSLOT_H_ +#define _AL_AUXEFFECTSLOT_H_ + +#include + +#include "alcmain.h" +#include "alEffect.h" +#include "ambidefs.h" +#include "effects/base.h" + +#include "almalloc.h" +#include "atomic.h" + + +struct ALeffectslot; + + +using ALeffectslotArray = al::FlexArray; + + +struct ALeffectslotProps { + ALfloat Gain; + ALboolean AuxSendAuto; + ALeffectslot *Target; + + ALenum Type; + EffectProps Props; + + EffectState *State; + + std::atomic next; +}; + + +struct ALeffectslot { + ALfloat Gain{1.0f}; + ALboolean AuxSendAuto{AL_TRUE}; + ALeffectslot *Target{nullptr}; + + struct { + ALenum Type{AL_EFFECT_NULL}; + EffectProps Props{}; + + EffectState *State{nullptr}; + } Effect; + + std::atomic_flag PropsClean; + + RefCount ref{0u}; + + std::atomic Update{nullptr}; + + struct { + ALfloat Gain{1.0f}; + ALboolean AuxSendAuto{AL_TRUE}; + ALeffectslot *Target{nullptr}; + + ALenum EffectType{AL_EFFECT_NULL}; + EffectProps mEffectProps{}; + EffectState *mEffectState{nullptr}; + + ALfloat RoomRolloff{0.0f}; /* Added to the source's room rolloff, not multiplied. */ + ALfloat DecayTime{0.0f}; + ALfloat DecayLFRatio{0.0f}; + ALfloat DecayHFRatio{0.0f}; + ALboolean DecayHFLimit{AL_FALSE}; + ALfloat AirAbsorptionGainHF{1.0f}; + } Params; + + /* Self ID */ + ALuint id{}; + + /* Mixing buffer used by the Wet mix. */ + al::vector MixBuffer; + + /* Wet buffer configuration is ACN channel order with N3D scaling. + * Consequently, effects that only want to work with mono input can use + * channel 0 by itself. Effects that want multichannel can process the + * ambisonics signal and make a B-Format source pan. + */ + MixParams Wet; + + ALeffectslot() { PropsClean.test_and_set(std::memory_order_relaxed); } + ALeffectslot(const ALeffectslot&) = delete; + ALeffectslot& operator=(const ALeffectslot&) = delete; + ~ALeffectslot(); + + static ALeffectslotArray *CreatePtrArray(size_t count) noexcept; + + DEF_PLACE_NEWDEL() +}; + +ALenum InitEffectSlot(ALeffectslot *slot); +void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context); +void UpdateAllEffectSlotProps(ALCcontext *context); + + +ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); + +#endif diff --git a/OpenAL32/alBuffer.h b/OpenAL32/alBuffer.h new file mode 100644 index 00000000..92655784 --- /dev/null +++ b/OpenAL32/alBuffer.h @@ -0,0 +1,120 @@ +#ifndef _AL_BUFFER_H_ +#define _AL_BUFFER_H_ + +#include "AL/alc.h" +#include "AL/al.h" +#include "AL/alext.h" + +#include "inprogext.h" +#include "atomic.h" +#include "vector.h" +#include "albyte.h" + + +/* User formats */ +enum UserFmtType : unsigned char { + UserFmtUByte, + UserFmtShort, + UserFmtFloat, + UserFmtDouble, + UserFmtMulaw, + UserFmtAlaw, + UserFmtIMA4, + UserFmtMSADPCM, +}; +enum UserFmtChannels : unsigned char { + UserFmtMono, + UserFmtStereo, + UserFmtRear, + UserFmtQuad, + UserFmtX51, /* (WFX order) */ + UserFmtX61, /* (WFX order) */ + UserFmtX71, /* (WFX order) */ + UserFmtBFormat2D, /* WXY */ + UserFmtBFormat3D, /* WXYZ */ +}; + +ALsizei BytesFromUserFmt(UserFmtType type); +ALsizei ChannelsFromUserFmt(UserFmtChannels chans); +inline ALsizei FrameSizeFromUserFmt(UserFmtChannels chans, UserFmtType type) +{ return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type); } + + +/* Storable formats */ +enum FmtType : unsigned char { + FmtUByte = UserFmtUByte, + FmtShort = UserFmtShort, + FmtFloat = UserFmtFloat, + FmtDouble = UserFmtDouble, + FmtMulaw = UserFmtMulaw, + FmtAlaw = UserFmtAlaw, +}; +enum FmtChannels : unsigned char { + FmtMono = UserFmtMono, + FmtStereo = UserFmtStereo, + FmtRear = UserFmtRear, + FmtQuad = UserFmtQuad, + FmtX51 = UserFmtX51, + FmtX61 = UserFmtX61, + FmtX71 = UserFmtX71, + FmtBFormat2D = UserFmtBFormat2D, + FmtBFormat3D = UserFmtBFormat3D, +}; +#define MAX_INPUT_CHANNELS (8) + +/* DevFmtType traits, providing the type, etc given a DevFmtType. */ +template +struct FmtTypeTraits { }; + +template<> +struct FmtTypeTraits { using Type = ALubyte; }; +template<> +struct FmtTypeTraits { using Type = ALshort; }; +template<> +struct FmtTypeTraits { using Type = ALfloat; }; +template<> +struct FmtTypeTraits { using Type = ALdouble; }; +template<> +struct FmtTypeTraits { using Type = ALubyte; }; +template<> +struct FmtTypeTraits { using Type = ALubyte; }; + + +ALsizei BytesFromFmt(FmtType type); +ALsizei ChannelsFromFmt(FmtChannels chans); +inline ALsizei FrameSizeFromFmt(FmtChannels chans, FmtType type) +{ return ChannelsFromFmt(chans) * BytesFromFmt(type); } + + +struct ALbuffer { + al::vector mData; + + ALsizei Frequency{0}; + ALbitfieldSOFT Access{0u}; + ALsizei SampleLen{0}; + + FmtChannels mFmtChannels{}; + FmtType mFmtType{}; + + UserFmtType OriginalType{}; + ALsizei OriginalSize{0}; + ALsizei OriginalAlign{0}; + + ALsizei LoopStart{0}; + ALsizei LoopEnd{0}; + + std::atomic UnpackAlign{0}; + std::atomic PackAlign{0}; + + ALbitfieldSOFT MappedAccess{0u}; + ALsizei MappedOffset{0}; + ALsizei MappedSize{0}; + + /* Number of times buffer was attached to a source (deletion can only occur when 0) */ + RefCount ref{0u}; + + /* Self ID */ + ALuint id{0}; +}; + +#endif diff --git a/OpenAL32/alEffect.h b/OpenAL32/alEffect.h new file mode 100644 index 00000000..d43aa206 --- /dev/null +++ b/OpenAL32/alEffect.h @@ -0,0 +1,59 @@ +#ifndef _AL_EFFECT_H_ +#define _AL_EFFECT_H_ + +#include "alcmain.h" +#include "effects/base.h" + + +enum { + EAXREVERB_EFFECT = 0, + REVERB_EFFECT, + AUTOWAH_EFFECT, + CHORUS_EFFECT, + COMPRESSOR_EFFECT, + DISTORTION_EFFECT, + ECHO_EFFECT, + EQUALIZER_EFFECT, + FLANGER_EFFECT, + FSHIFTER_EFFECT, + MODULATOR_EFFECT, + PSHIFTER_EFFECT, + VMORPHER_EFFECT, + DEDICATED_EFFECT, + + MAX_EFFECTS +}; +extern ALboolean DisabledEffects[MAX_EFFECTS]; + +extern ALfloat ReverbBoost; + +struct EffectList { + const char name[16]; + int type; + ALenum val; +}; +extern const EffectList gEffectList[15]; + + +struct ALeffect { + // Effect type (AL_EFFECT_NULL, ...) + ALenum type{AL_EFFECT_NULL}; + + EffectProps Props{}; + + const EffectVtable *vtab{nullptr}; + + /* Self ID */ + ALuint id{0u}; +}; + +inline ALboolean IsReverbEffect(ALenum type) +{ return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; } + +EffectStateFactory *getFactoryByType(ALenum type); + +void InitEffect(ALeffect *effect); + +void LoadReverbPreset(const char *name, ALeffect *effect); + +#endif diff --git a/OpenAL32/alError.h b/OpenAL32/alError.h new file mode 100644 index 00000000..0abd6b26 --- /dev/null +++ b/OpenAL32/alError.h @@ -0,0 +1,22 @@ +#ifndef _AL_ERROR_H_ +#define _AL_ERROR_H_ + +#include "alcmain.h" +#include "logging.h" + + +extern bool TrapALError; + +void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) DECL_FORMAT(printf, 3, 4); + +#define SETERR_GOTO(ctx, err, lbl, ...) do { \ + alSetError((ctx), (err), __VA_ARGS__); \ + goto lbl; \ +} while(0) + +#define SETERR_RETURN(ctx, err, retval, ...) do { \ + alSetError((ctx), (err), __VA_ARGS__); \ + return retval; \ +} while(0) + +#endif diff --git a/OpenAL32/alFilter.h b/OpenAL32/alFilter.h new file mode 100644 index 00000000..1c033ac3 --- /dev/null +++ b/OpenAL32/alFilter.h @@ -0,0 +1,56 @@ +#ifndef _AL_FILTER_H_ +#define _AL_FILTER_H_ + +#include "AL/alc.h" +#include "AL/al.h" + + +#define LOWPASSFREQREF (5000.0f) +#define HIGHPASSFREQREF (250.0f) + + +struct ALfilter; + +struct ALfilterVtable { + void (*const setParami)(ALfilter *filter, ALCcontext *context, ALenum param, ALint val); + void (*const setParamiv)(ALfilter *filter, ALCcontext *context, ALenum param, const ALint *vals); + void (*const setParamf)(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val); + void (*const setParamfv)(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals); + + void (*const getParami)(ALfilter *filter, ALCcontext *context, ALenum param, ALint *val); + void (*const getParamiv)(ALfilter *filter, ALCcontext *context, ALenum param, ALint *vals); + void (*const getParamf)(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val); + void (*const getParamfv)(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals); +}; + +#define DEFINE_ALFILTER_VTABLE(T) \ +const ALfilterVtable T##_vtable = { \ + T##_setParami, T##_setParamiv, T##_setParamf, T##_setParamfv, \ + T##_getParami, T##_getParamiv, T##_getParamf, T##_getParamfv, \ +} + +struct ALfilter { + // Filter type (AL_FILTER_NULL, ...) + ALenum type; + + ALfloat Gain; + ALfloat GainHF; + ALfloat HFReference; + ALfloat GainLF; + ALfloat LFReference; + + const ALfilterVtable *vtab; + + /* Self ID */ + ALuint id; +}; +#define ALfilter_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v)) +#define ALfilter_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v)) +#define ALfilter_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v)) +#define ALfilter_setParamfv(o, c, p, v) ((o)->vtab->setParamfv(o, c, p, v)) +#define ALfilter_getParami(o, c, p, v) ((o)->vtab->getParami(o, c, p, v)) +#define ALfilter_getParamf(o, c, p, v) ((o)->vtab->getParamf(o, c, p, v)) +#define ALfilter_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v)) +#define ALfilter_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v)) + +#endif diff --git a/OpenAL32/alListener.h b/OpenAL32/alListener.h new file mode 100644 index 00000000..4d59dbf9 --- /dev/null +++ b/OpenAL32/alListener.h @@ -0,0 +1,59 @@ +#ifndef _AL_LISTENER_H_ +#define _AL_LISTENER_H_ + +#include + +#include "AL/alc.h" +#include "AL/al.h" +#include "AL/alext.h" + +#include "atomic.h" +#include "vecmat.h" + +enum class DistanceModel; + + +struct ALlistenerProps { + std::array Position; + std::array Velocity; + std::array OrientAt; + std::array OrientUp; + ALfloat Gain; + + std::atomic next; +}; + +struct ALlistener { + std::array Position{{0.0f, 0.0f, 0.0f}}; + std::array Velocity{{0.0f, 0.0f, 0.0f}}; + std::array OrientAt{{0.0f, 0.0f, -1.0f}}; + std::array OrientUp{{0.0f, 1.0f, 0.0f}}; + ALfloat Gain{1.0f}; + + std::atomic_flag PropsClean; + + /* Pointer to the most recent property values that are awaiting an update. + */ + std::atomic Update{nullptr}; + + struct { + alu::Matrix Matrix; + alu::Vector Velocity; + + ALfloat Gain; + ALfloat MetersPerUnit; + + ALfloat DopplerFactor; + ALfloat SpeedOfSound; /* in units per sec! */ + ALfloat ReverbSpeedOfSound; /* in meters per sec! */ + + ALboolean SourceDistanceModel; + DistanceModel mDistanceModel; + } Params; + + ALlistener() { PropsClean.test_and_set(std::memory_order_relaxed); } +}; + +void UpdateListenerProps(ALCcontext *context); + +#endif diff --git a/OpenAL32/alSource.h b/OpenAL32/alSource.h new file mode 100644 index 00000000..330bb9f4 --- /dev/null +++ b/OpenAL32/alSource.h @@ -0,0 +1,127 @@ +#ifndef _AL_SOURCE_H_ +#define _AL_SOURCE_H_ + +#include + +#include "alcmain.h" +#include "alu.h" +#include "hrtf.h" +#include "almalloc.h" +#include "atomic.h" + +#define DEFAULT_SENDS 2 + +struct ALbuffer; +struct ALsource; +struct ALeffectslot; + + +struct ALbufferlistitem { + std::atomic next; + ALsizei max_samples; + ALsizei num_buffers; + ALbuffer *buffers[]; + + static constexpr size_t Sizeof(size_t num_buffers) noexcept + { + return maxz(offsetof(ALbufferlistitem, buffers) + sizeof(ALbuffer*)*num_buffers, + sizeof(ALbufferlistitem)); + } +}; + + +struct ALsource { + /** Source properties. */ + ALfloat Pitch; + ALfloat Gain; + ALfloat OuterGain; + ALfloat MinGain; + ALfloat MaxGain; + ALfloat InnerAngle; + ALfloat OuterAngle; + ALfloat RefDistance; + ALfloat MaxDistance; + ALfloat RolloffFactor; + std::array Position; + std::array Velocity; + std::array Direction; + std::array OrientAt; + std::array OrientUp; + ALboolean HeadRelative; + ALboolean Looping; + DistanceModel mDistanceModel; + Resampler mResampler; + ALboolean DirectChannels; + SpatializeMode mSpatialize; + + ALboolean DryGainHFAuto; + ALboolean WetGainAuto; + ALboolean WetGainHFAuto; + ALfloat OuterGainHF; + + ALfloat AirAbsorptionFactor; + ALfloat RoomRolloffFactor; + ALfloat DopplerFactor; + + /* NOTE: Stereo pan angles are specified in radians, counter-clockwise + * rather than clockwise. + */ + std::array StereoPan; + + ALfloat Radius; + + /** Direct filter and auxiliary send info. */ + struct { + ALfloat Gain; + ALfloat GainHF; + ALfloat HFReference; + ALfloat GainLF; + ALfloat LFReference; + } Direct; + struct SendData { + ALeffectslot *Slot; + ALfloat Gain; + ALfloat GainHF; + ALfloat HFReference; + ALfloat GainLF; + ALfloat LFReference; + }; + al::vector Send; + + /** + * Last user-specified offset, and the offset type (bytes, samples, or + * seconds). + */ + ALdouble Offset; + ALenum OffsetType; + + /** Source type (static, streaming, or undetermined) */ + ALint SourceType; + + /** Source state (initial, playing, paused, or stopped) */ + ALenum state; + + /** Source Buffer Queue head. */ + ALbufferlistitem *queue; + + std::atomic_flag PropsClean; + + /* Index into the context's Voices array. Lazily updated, only checked and + * reset when looking up the voice. + */ + ALint VoiceIdx; + + /** Self ID */ + ALuint id; + + + ALsource(ALsizei num_sends); + ~ALsource(); + + ALsource(const ALsource&) = delete; + ALsource& operator=(const ALsource&) = delete; +}; + +void UpdateAllSourceProps(ALCcontext *context); + +#endif -- cgit v1.2.3