Simplify void_t
[openal-soft.git] / core / buffer_storage.h
blobec934681408698d664173d8943985b6f6869b07a
1 #ifndef CORE_BUFFER_STORAGE_H
2 #define CORE_BUFFER_STORAGE_H
4 #include <atomic>
6 #include "albyte.h"
7 #include "alnumeric.h"
8 #include "ambidefs.h"
11 using uint = unsigned int;
13 /* Storable formats */
14 enum FmtType : unsigned char {
15 FmtUByte,
16 FmtShort,
17 FmtFloat,
18 FmtDouble,
19 FmtMulaw,
20 FmtAlaw,
22 enum FmtChannels : unsigned char {
23 FmtMono,
24 FmtStereo,
25 FmtRear,
26 FmtQuad,
27 FmtX51, /* (WFX order) */
28 FmtX61, /* (WFX order) */
29 FmtX71, /* (WFX order) */
30 FmtBFormat2D,
31 FmtBFormat3D,
32 FmtUHJ2, /* 2-channel UHJ, aka "BHJ", stereo-compatible */
33 FmtUHJ3, /* 3-channel UHJ, aka "THJ" */
34 FmtUHJ4, /* 4-channel UHJ, aka "PHJ" */
35 FmtSuperStereo, /* Stereo processed with Super Stereo. */
38 enum class AmbiLayout : unsigned char {
39 FuMa,
40 ACN,
42 enum class AmbiScaling : unsigned char {
43 FuMa,
44 SN3D,
45 N3D,
46 UHJ,
49 uint BytesFromFmt(FmtType type) noexcept;
50 uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept;
51 inline uint FrameSizeFromFmt(FmtChannels chans, FmtType type, uint ambiorder) noexcept
52 { return ChannelsFromFmt(chans, ambiorder) * BytesFromFmt(type); }
54 constexpr bool IsBFormat(FmtChannels chans) noexcept
55 { return chans == FmtBFormat2D || chans == FmtBFormat3D; }
57 /* Super Stereo is considered part of the UHJ family here, since it goes
58 * through similar processing as UHJ, both result in a B-Format signal, and
59 * needs the same consideration as BHJ (three channel result with only two
60 * channel input).
62 constexpr bool IsUHJ(FmtChannels chans) noexcept
63 { return chans == FmtUHJ2 || chans == FmtUHJ3 || chans == FmtUHJ4 || chans == FmtSuperStereo; }
65 /** Ambisonic formats are either B-Format or UHJ formats. */
66 constexpr bool IsAmbisonic(FmtChannels chans) noexcept
67 { return IsBFormat(chans) || IsUHJ(chans); }
69 constexpr bool Is2DAmbisonic(FmtChannels chans) noexcept
71 return chans == FmtBFormat2D || chans == FmtUHJ2 || chans == FmtUHJ3
72 || chans == FmtSuperStereo;
76 using CallbackType = int(*)(void*, void*, int);
78 struct BufferStorage {
79 CallbackType mCallback{nullptr};
80 void *mUserData{nullptr};
82 uint mSampleRate{0u};
83 FmtChannels mChannels{FmtMono};
84 FmtType mType{FmtShort};
85 uint mSampleLen{0u};
87 AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
88 AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
89 uint mAmbiOrder{0u};
91 inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); }
92 inline uint channelsFromFmt() const noexcept
93 { return ChannelsFromFmt(mChannels, mAmbiOrder); }
94 inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); }
96 inline bool isBFormat() const noexcept { return IsBFormat(mChannels); }
99 #endif /* CORE_BUFFER_STORAGE_H */