buffer_storage.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef CORE_BUFFER_STORAGE_H
  2. #define CORE_BUFFER_STORAGE_H
  3. #include <cstddef>
  4. #include "alspan.h"
  5. #include "ambidefs.h"
  6. #include "storage_formats.h"
  7. using uint = unsigned int;
  8. constexpr bool IsBFormat(FmtChannels chans) noexcept
  9. { return chans == FmtBFormat2D || chans == FmtBFormat3D; }
  10. /* Super Stereo is considered part of the UHJ family here, since it goes
  11. * through similar processing as UHJ, both result in a B-Format signal, and
  12. * needs the same consideration as BHJ (three channel result with only two
  13. * channel input).
  14. */
  15. constexpr bool IsUHJ(FmtChannels chans) noexcept
  16. { return chans == FmtUHJ2 || chans == FmtUHJ3 || chans == FmtUHJ4 || chans == FmtSuperStereo; }
  17. /** Ambisonic formats are either B-Format or UHJ formats. */
  18. constexpr bool IsAmbisonic(FmtChannels chans) noexcept
  19. { return IsBFormat(chans) || IsUHJ(chans); }
  20. constexpr bool Is2DAmbisonic(FmtChannels chans) noexcept
  21. {
  22. return chans == FmtBFormat2D || chans == FmtUHJ2 || chans == FmtUHJ3
  23. || chans == FmtSuperStereo;
  24. }
  25. using CallbackType = int(*)(void*, void*, int) noexcept;
  26. struct BufferStorage {
  27. CallbackType mCallback{nullptr};
  28. void *mUserData{nullptr};
  29. al::span<std::byte> mData;
  30. uint mSampleRate{0u};
  31. FmtChannels mChannels{FmtMono};
  32. FmtType mType{FmtShort};
  33. uint mSampleLen{0u};
  34. uint mBlockAlign{0u};
  35. AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
  36. AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
  37. uint mAmbiOrder{0u};
  38. [[nodiscard]] auto bytesFromFmt() const noexcept -> uint { return BytesFromFmt(mType); }
  39. [[nodiscard]] auto channelsFromFmt() const noexcept -> uint
  40. { return ChannelsFromFmt(mChannels, mAmbiOrder); }
  41. [[nodiscard]] auto frameSizeFromFmt() const noexcept -> uint
  42. { return channelsFromFmt() * bytesFromFmt(); }
  43. [[nodiscard]] auto blockSizeFromFmt() const noexcept -> uint
  44. {
  45. if(mType == FmtIMA4) return ((mBlockAlign-1)/2 + 4) * channelsFromFmt();
  46. if(mType == FmtMSADPCM) return ((mBlockAlign-2)/2 + 7) * channelsFromFmt();
  47. return frameSizeFromFmt();
  48. };
  49. [[nodiscard]] auto isBFormat() const noexcept -> bool { return IsBFormat(mChannels); }
  50. };
  51. #endif /* CORE_BUFFER_STORAGE_H */