Separate ALCdevice from the implementation
[openal-soft.git] / core / buffer_storage.h
blobab097cf12fad5a65247d2cd4ece31cd9b3f3f296
1 #ifndef CORE_BUFFER_STORAGE_H
2 #define CORE_BUFFER_STORAGE_H
4 #include <atomic>
5 #include <cstddef>
7 #include "alnumeric.h"
8 #include "alspan.h"
9 #include "ambidefs.h"
10 #include "storage_formats.h"
13 using uint = unsigned int;
15 constexpr bool IsBFormat(FmtChannels chans) noexcept
16 { return chans == FmtBFormat2D || chans == FmtBFormat3D; }
18 /* Super Stereo is considered part of the UHJ family here, since it goes
19 * through similar processing as UHJ, both result in a B-Format signal, and
20 * needs the same consideration as BHJ (three channel result with only two
21 * channel input).
23 constexpr bool IsUHJ(FmtChannels chans) noexcept
24 { return chans == FmtUHJ2 || chans == FmtUHJ3 || chans == FmtUHJ4 || chans == FmtSuperStereo; }
26 /** Ambisonic formats are either B-Format or UHJ formats. */
27 constexpr bool IsAmbisonic(FmtChannels chans) noexcept
28 { return IsBFormat(chans) || IsUHJ(chans); }
30 constexpr bool Is2DAmbisonic(FmtChannels chans) noexcept
32 return chans == FmtBFormat2D || chans == FmtUHJ2 || chans == FmtUHJ3
33 || chans == FmtSuperStereo;
37 using CallbackType = int(*)(void*, void*, int);
39 struct BufferStorage {
40 CallbackType mCallback{nullptr};
41 void *mUserData{nullptr};
43 al::span<std::byte> mData;
45 uint mSampleRate{0u};
46 FmtChannels mChannels{FmtMono};
47 FmtType mType{FmtShort};
48 uint mSampleLen{0u};
49 uint mBlockAlign{0u};
51 AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
52 AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
53 uint mAmbiOrder{0u};
55 [[nodiscard]] auto bytesFromFmt() const noexcept -> uint { return BytesFromFmt(mType); }
56 [[nodiscard]] auto channelsFromFmt() const noexcept -> uint
57 { return ChannelsFromFmt(mChannels, mAmbiOrder); }
58 [[nodiscard]] auto frameSizeFromFmt() const noexcept -> uint
59 { return channelsFromFmt() * bytesFromFmt(); }
61 [[nodiscard]] auto blockSizeFromFmt() const noexcept -> uint
63 if(mType == FmtIMA4) return ((mBlockAlign-1)/2 + 4) * channelsFromFmt();
64 if(mType == FmtMSADPCM) return ((mBlockAlign-2)/2 + 7) * channelsFromFmt();
65 return frameSizeFromFmt();
68 [[nodiscard]] auto isBFormat() const noexcept -> bool { return IsBFormat(mChannels); }
71 #endif /* CORE_BUFFER_STORAGE_H */