1 #ifndef ALC_BUFFER_STORAGE_H
2 #define ALC_BUFFER_STORAGE_H
3 
4 #include <atomic>
5 
6 #include "albyte.h"
7 
8 
9 using uint = unsigned int;
10 
11 /* Storable formats */
12 enum FmtType : unsigned char {
13     FmtUByte,
14     FmtShort,
15     FmtFloat,
16     FmtDouble,
17     FmtMulaw,
18     FmtAlaw,
19 };
20 enum FmtChannels : unsigned char {
21     FmtMono,
22     FmtStereo,
23     FmtRear,
24     FmtQuad,
25     FmtX51, /* (WFX order) */
26     FmtX61, /* (WFX order) */
27     FmtX71, /* (WFX order) */
28     FmtBFormat2D,
29     FmtBFormat3D,
30 };
31 
32 enum class AmbiLayout : unsigned char {
33     FuMa,
34     ACN,
35 };
36 enum class AmbiScaling : unsigned char {
37     FuMa,
38     SN3D,
39     N3D,
40 };
41 
42 uint BytesFromFmt(FmtType type) noexcept;
43 uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept;
FrameSizeFromFmt(FmtChannels chans,FmtType type,uint ambiorder)44 inline uint FrameSizeFromFmt(FmtChannels chans, FmtType type, uint ambiorder) noexcept
45 { return ChannelsFromFmt(chans, ambiorder) * BytesFromFmt(type); }
46 
47 
48 using CallbackType = int(*)(void*, void*, int);
49 
50 struct BufferStorage {
51     CallbackType mCallback{nullptr};
52     void *mUserData{nullptr};
53 
54     uint mSampleRate{0u};
55     FmtChannels mChannels{FmtMono};
56     FmtType mType{FmtShort};
57     uint mSampleLen{0u};
58 
59     AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
60     AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
61     uint mAmbiOrder{0u};
62 
bytesFromFmtBufferStorage63     inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); }
channelsFromFmtBufferStorage64     inline uint channelsFromFmt() const noexcept
65     { return ChannelsFromFmt(mChannels, mAmbiOrder); }
frameSizeFromFmtBufferStorage66     inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); }
67 
isBFormatBufferStorage68     inline bool isBFormat() const noexcept
69     { return mChannels == FmtBFormat2D || mChannels == FmtBFormat3D; }
70 };
71 
72 #endif /* ALC_BUFFER_STORAGE_H */
73