diff options
author | Chris Robinson <[email protected]> | 2021-04-27 08:26:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-04-27 08:26:42 -0700 |
commit | ff380298e4086490584707b8ffde44c5ad64830f (patch) | |
tree | 313288fbfdc2ea7824508e85d264966db6078368 /core/buffer_storage.h | |
parent | 99157f149f180cfcc2e4be6a3d2a54843411e87a (diff) |
Move BufferStorage and Voice to core
Diffstat (limited to 'core/buffer_storage.h')
-rw-r--r-- | core/buffer_storage.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/core/buffer_storage.h b/core/buffer_storage.h new file mode 100644 index 00000000..59280354 --- /dev/null +++ b/core/buffer_storage.h @@ -0,0 +1,75 @@ +#ifndef CORE_BUFFER_STORAGE_H +#define CORE_BUFFER_STORAGE_H + +#include <atomic> + +#include "albyte.h" + + +using uint = unsigned int; + +/* Storable formats */ +enum FmtType : unsigned char { + FmtUByte, + FmtShort, + FmtFloat, + FmtDouble, + FmtMulaw, + FmtAlaw, +}; +enum FmtChannels : unsigned char { + FmtMono, + FmtStereo, + FmtRear, + FmtQuad, + FmtX51, /* (WFX order) */ + FmtX61, /* (WFX order) */ + FmtX71, /* (WFX order) */ + FmtBFormat2D, + FmtBFormat3D, + FmtUHJ2, /* 2-channel UHJ, aka "BHJ", stereo-compatible */ + FmtUHJ3, /* 3-channel UHJ, aka "THJ" */ + FmtUHJ4, /* 4-channel UHJ, aka "PHJ" */ +}; + +enum class AmbiLayout : unsigned char { + FuMa, + ACN, +}; +enum class AmbiScaling : unsigned char { + FuMa, + SN3D, + N3D, +}; + +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 { + CallbackType mCallback{nullptr}; + void *mUserData{nullptr}; + + uint mSampleRate{0u}; + FmtChannels mChannels{FmtMono}; + FmtType mType{FmtShort}; + uint mSampleLen{0u}; + + AmbiLayout mAmbiLayout{AmbiLayout::FuMa}; + AmbiScaling mAmbiScaling{AmbiScaling::FuMa}; + uint mAmbiOrder{0u}; + + inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); } + inline uint channelsFromFmt() const noexcept + { return ChannelsFromFmt(mChannels, mAmbiOrder); } + inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); } + + inline bool isBFormat() const noexcept + { return mChannels == FmtBFormat2D || mChannels == FmtBFormat3D; } +}; + +#endif /* CORE_BUFFER_STORAGE_H */ |