diff options
-rw-r--r-- | al/buffer.cpp | 48 | ||||
-rw-r--r-- | alc/buffer_storage.cpp | 5 | ||||
-rw-r--r-- | alc/buffer_storage.h | 44 |
3 files changed, 69 insertions, 28 deletions
diff --git a/al/buffer.cpp b/al/buffer.cpp index 10849a0a..393c19da 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -274,6 +274,46 @@ ALuint ChannelsFromUserFmt(UserFmtChannels chans, ALuint ambiorder) noexcept return 0; } +al::optional<AmbiLayout> AmbiLayoutFromEnum(ALenum layout) +{ + switch(layout) + { + case AL_FUMA_SOFT: return al::make_optional(AmbiLayout::FuMa); + case AL_ACN_SOFT: return al::make_optional(AmbiLayout::ACN); + } + return al::nullopt; +} +ALenum EnumFromAmbiLayout(AmbiLayout layout) +{ + switch(layout) + { + case AmbiLayout::FuMa: return AL_FUMA_SOFT; + case AmbiLayout::ACN: return AL_ACN_SOFT; + } + throw std::runtime_error{"Invalid AmbiLayout: "+std::to_string(int(layout))}; +} + +al::optional<AmbiScaling> AmbiScalingFromEnum(ALenum scale) +{ + switch(scale) + { + case AL_FUMA_SOFT: return al::make_optional(AmbiScaling::FuMa); + case AL_SN3D_SOFT: return al::make_optional(AmbiScaling::SN3D); + case AL_N3D_SOFT: return al::make_optional(AmbiScaling::N3D); + } + return al::nullopt; +} +ALenum EnumFromAmbiScaling(AmbiScaling scale) +{ + switch(scale) + { + case AmbiScaling::FuMa: return AL_FUMA_SOFT; + case AmbiScaling::SN3D: return AL_SN3D_SOFT; + case AmbiScaling::N3D: return AL_SN3D_SOFT; + } + throw std::runtime_error{"Invalid AmbiScaling: "+std::to_string(int(scale))}; +} + constexpr ALbitfieldSOFT INVALID_STORAGE_MASK{~unsigned(AL_MAP_READ_BIT_SOFT | AL_MAP_WRITE_BIT_SOFT | AL_MAP_PERSISTENT_BIT_SOFT | AL_PRESERVE_DATA_BIT_SOFT)}; @@ -1176,7 +1216,7 @@ START_API_FUNC else if UNLIKELY(value != AL_FUMA_SOFT && value != AL_ACN_SOFT) context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic layout %04x", value); else - albuf->mBuffer.mAmbiLayout = static_cast<AmbiLayout>(value); + albuf->mBuffer.mAmbiLayout = AmbiLayoutFromEnum(value).value(); break; case AL_AMBISONIC_SCALING_SOFT: @@ -1186,7 +1226,7 @@ START_API_FUNC else if UNLIKELY(value != AL_FUMA_SOFT && value != AL_SN3D_SOFT && value != AL_N3D_SOFT) context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic scaling %04x", value); else - albuf->mBuffer.mAmbiScaling = static_cast<AmbiScaling>(value); + albuf->mBuffer.mAmbiScaling = AmbiScalingFromEnum(value).value(); break; case AL_UNPACK_AMBISONIC_ORDER_SOFT: @@ -1386,11 +1426,11 @@ START_API_FUNC break; case AL_AMBISONIC_LAYOUT_SOFT: - *value = static_cast<int>(albuf->mBuffer.mAmbiLayout); + *value = EnumFromAmbiLayout(albuf->mBuffer.mAmbiLayout); break; case AL_AMBISONIC_SCALING_SOFT: - *value = static_cast<int>(albuf->mBuffer.mAmbiScaling); + *value = EnumFromAmbiScaling(albuf->mBuffer.mAmbiScaling); break; case AL_UNPACK_AMBISONIC_ORDER_SOFT: diff --git a/alc/buffer_storage.cpp b/alc/buffer_storage.cpp index 727cb281..7d3adddd 100644 --- a/alc/buffer_storage.cpp +++ b/alc/buffer_storage.cpp @@ -6,7 +6,7 @@ #include <cstdint> -ALuint BytesFromFmt(FmtType type) noexcept +uint BytesFromFmt(FmtType type) noexcept { switch(type) { @@ -19,7 +19,8 @@ ALuint BytesFromFmt(FmtType type) noexcept } return 0; } -ALuint ChannelsFromFmt(FmtChannels chans, ALuint ambiorder) noexcept + +uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept { switch(chans) { diff --git a/alc/buffer_storage.h b/alc/buffer_storage.h index 434d5ed0..60770184 100644 --- a/alc/buffer_storage.h +++ b/alc/buffer_storage.h @@ -3,15 +3,13 @@ #include <atomic> -#include "AL/al.h" -#include "AL/alext.h" - #include "albyte.h" #include "almalloc.h" -#include "inprogext.h" #include "vector.h" +using uint = unsigned int; + /* Storable formats */ enum FmtType : unsigned char { FmtUByte, @@ -34,43 +32,45 @@ enum FmtChannels : unsigned char { }; enum class AmbiLayout : unsigned char { - FuMa = AL_FUMA_SOFT, - ACN = AL_ACN_SOFT, + FuMa, + ACN, }; enum class AmbiScaling : unsigned char { - FuMa = AL_FUMA_SOFT, - SN3D = AL_SN3D_SOFT, - N3D = AL_N3D_SOFT, + FuMa, + SN3D, + N3D, }; -ALuint BytesFromFmt(FmtType type) noexcept; -ALuint ChannelsFromFmt(FmtChannels chans, ALuint ambiorder) noexcept; -inline ALuint FrameSizeFromFmt(FmtChannels chans, FmtType type, ALuint ambiorder) noexcept +uint BytesFromFmt(FmtType type) noexcept; +uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept; +inline uint FrameSizeFromFmt(FmtChannels chans, FmtType type, uint ambiorder) noexcept { return ChannelsFromFmt(chans, ambiorder) * BytesFromFmt(type); } +using CallbackType = int(*)(void*, void*, int); + struct BufferStorage { al::vector<al::byte,16> mData; - LPALBUFFERCALLBACKTYPESOFT mCallback{nullptr}; + CallbackType mCallback{nullptr}; void *mUserData{nullptr}; - ALuint mSampleRate{0u}; + uint mSampleRate{0u}; FmtChannels mChannels{}; FmtType mType{}; - ALuint mSampleLen{0u}; + uint mSampleLen{0u}; AmbiLayout mAmbiLayout{AmbiLayout::FuMa}; AmbiScaling mAmbiScaling{AmbiScaling::FuMa}; - ALuint mAmbiOrder{0u}; + uint mAmbiOrder{0u}; - ALuint mLoopStart{0u}; - ALuint mLoopEnd{0u}; + uint mLoopStart{0u}; + uint mLoopEnd{0u}; - inline ALuint bytesFromFmt() const noexcept { return BytesFromFmt(mType); } - inline ALuint channelsFromFmt() const noexcept + inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); } + inline uint channelsFromFmt() const noexcept { return ChannelsFromFmt(mChannels, mAmbiOrder); } - inline ALuint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); } + inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); } inline bool isBFormat() const noexcept { return mChannels == FmtBFormat2D || mChannels == FmtBFormat3D; } @@ -79,7 +79,7 @@ struct BufferStorage { struct BufferlistItem { std::atomic<BufferlistItem*> mNext{nullptr}; - ALuint mSampleLen{0u}; + uint mSampleLen{0u}; BufferStorage *mBuffer{nullptr}; DEF_NEWDEL(BufferlistItem) |