🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.7 KiB

  1. #ifndef CORE_BUFFER_STORAGE_H
  2. #define CORE_BUFFER_STORAGE_H
  3. #include <atomic>
  4. #include "albyte.h"
  5. #include "alnumeric.h"
  6. #include "ambidefs.h"
  7. using uint = unsigned int;
  8. /* Storable formats */
  9. enum FmtType : unsigned char {
  10. FmtUByte,
  11. FmtShort,
  12. FmtFloat,
  13. FmtDouble,
  14. FmtMulaw,
  15. FmtAlaw,
  16. };
  17. enum FmtChannels : unsigned char {
  18. FmtMono,
  19. FmtStereo,
  20. FmtRear,
  21. FmtQuad,
  22. FmtX51, /* (WFX order) */
  23. FmtX61, /* (WFX order) */
  24. FmtX71, /* (WFX order) */
  25. FmtBFormat2D,
  26. FmtBFormat3D,
  27. FmtUHJ2, /* 2-channel UHJ, aka "BHJ", stereo-compatible */
  28. FmtUHJ3, /* 3-channel UHJ, aka "THJ" */
  29. FmtUHJ4, /* 4-channel UHJ, aka "PHJ" */
  30. FmtSuperStereo, /* Stereo processed with Super Stereo. */
  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. UHJ,
  41. };
  42. uint BytesFromFmt(FmtType type) noexcept;
  43. uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept;
  44. inline uint FrameSizeFromFmt(FmtChannels chans, FmtType type, uint ambiorder) noexcept
  45. { return ChannelsFromFmt(chans, ambiorder) * BytesFromFmt(type); }
  46. constexpr bool IsBFormat(FmtChannels chans) noexcept
  47. { return chans == FmtBFormat2D || chans == FmtBFormat3D; }
  48. /* Super Stereo is considered part of the UHJ family here, since it goes
  49. * through similar processing as UHJ, both result in a B-Format signal, and
  50. * needs the same consideration as BHJ (three channel result with only two
  51. * channel input).
  52. */
  53. constexpr bool IsUHJ(FmtChannels chans) noexcept
  54. { return chans == FmtUHJ2 || chans == FmtUHJ3 || chans == FmtUHJ4 || chans == FmtSuperStereo; }
  55. /** Ambisonic formats are either B-Format or UHJ formats. */
  56. constexpr bool IsAmbisonic(FmtChannels chans) noexcept
  57. { return IsBFormat(chans) || IsUHJ(chans); }
  58. constexpr bool Is2DAmbisonic(FmtChannels chans) noexcept
  59. {
  60. return chans == FmtBFormat2D || chans == FmtUHJ2 || chans == FmtUHJ3
  61. || chans == FmtSuperStereo;
  62. }
  63. using CallbackType = int(*)(void*, void*, int);
  64. struct BufferStorage {
  65. CallbackType mCallback{nullptr};
  66. void *mUserData{nullptr};
  67. uint mSampleRate{0u};
  68. FmtChannels mChannels{FmtMono};
  69. FmtType mType{FmtShort};
  70. uint mSampleLen{0u};
  71. AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
  72. AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
  73. uint mAmbiOrder{0u};
  74. inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); }
  75. inline uint channelsFromFmt() const noexcept
  76. { return ChannelsFromFmt(mChannels, mAmbiOrder); }
  77. inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); }
  78. inline bool isBFormat() const noexcept { return IsBFormat(mChannels); }
  79. };
  80. #endif /* CORE_BUFFER_STORAGE_H */