buffer_storage.h 1.7 KB

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