1 #ifndef CORE_BUFFER_STORAGE_H
2 #define CORE_BUFFER_STORAGE_H
12 using uint = unsigned int;
14 /* Storable formats */
15 enum FmtType : unsigned char {
25 enum FmtChannels : unsigned char {
30 FmtX51, /* (WFX order) */
31 FmtX61, /* (WFX order) */
32 FmtX71, /* (WFX order) */
35 FmtUHJ2, /* 2-channel UHJ, aka "BHJ", stereo-compatible */
36 FmtUHJ3, /* 3-channel UHJ, aka "THJ" */
37 FmtUHJ4, /* 4-channel UHJ, aka "PHJ" */
38 FmtSuperStereo, /* Stereo processed with Super Stereo. */
41 enum class AmbiLayout : unsigned char {
45 enum class AmbiScaling : unsigned char {
52 const char *NameFromFormat(FmtType type) noexcept;
53 const char *NameFromFormat(FmtChannels channels) noexcept;
55 uint BytesFromFmt(FmtType type) noexcept;
56 uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept;
57 inline uint FrameSizeFromFmt(FmtChannels chans, FmtType type, uint ambiorder) noexcept
58 { return ChannelsFromFmt(chans, ambiorder) * BytesFromFmt(type); }
60 constexpr bool IsBFormat(FmtChannels chans) noexcept
61 { return chans == FmtBFormat2D || chans == FmtBFormat3D; }
63 /* Super Stereo is considered part of the UHJ family here, since it goes
64 * through similar processing as UHJ, both result in a B-Format signal, and
65 * needs the same consideration as BHJ (three channel result with only two
68 constexpr bool IsUHJ(FmtChannels chans) noexcept
69 { return chans == FmtUHJ2 || chans == FmtUHJ3 || chans == FmtUHJ4 || chans == FmtSuperStereo; }
71 /** Ambisonic formats are either B-Format or UHJ formats. */
72 constexpr bool IsAmbisonic(FmtChannels chans) noexcept
73 { return IsBFormat(chans) || IsUHJ(chans); }
75 constexpr bool Is2DAmbisonic(FmtChannels chans) noexcept
77 return chans == FmtBFormat2D || chans == FmtUHJ2 || chans == FmtUHJ3
78 || chans == FmtSuperStereo;
82 using CallbackType = int(*)(void*, void*, int);
84 struct BufferStorage {
85 CallbackType mCallback{nullptr};
86 void *mUserData{nullptr};
88 al::span<al::byte> mData;
91 FmtChannels mChannels{FmtMono};
92 FmtType mType{FmtShort};
96 AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
97 AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
100 inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); }
101 inline uint channelsFromFmt() const noexcept
102 { return ChannelsFromFmt(mChannels, mAmbiOrder); }
103 inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); }
105 inline uint blockSizeFromFmt() const noexcept
107 if(mType == FmtIMA4) return ((mBlockAlign-1)/2 + 4) * channelsFromFmt();
108 if(mType == FmtMSADPCM) return ((mBlockAlign-2)/2 + 7) * channelsFromFmt();
109 return frameSizeFromFmt();
112 inline bool isBFormat() const noexcept { return IsBFormat(mChannels); }
115 #endif /* CORE_BUFFER_STORAGE_H */