🛠️🐜 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.

71 lines
2.3 KiB

  1. #ifndef CORE_BFORMATDEC_H
  2. #define CORE_BFORMATDEC_H
  3. #include <array>
  4. #include <cstddef>
  5. #include <memory>
  6. #include "almalloc.h"
  7. #include "alspan.h"
  8. #include "ambidefs.h"
  9. #include "bufferline.h"
  10. #include "devformat.h"
  11. #include "filters/splitter.h"
  12. #include "vector.h"
  13. struct FrontStablizer;
  14. using ChannelDec = std::array<float,MaxAmbiChannels>;
  15. class BFormatDec {
  16. static constexpr size_t sHFBand{0};
  17. static constexpr size_t sLFBand{1};
  18. static constexpr size_t sNumBands{2};
  19. struct ChannelDecoder {
  20. union MatrixU {
  21. float Dual[sNumBands][MAX_OUTPUT_CHANNELS];
  22. float Single[MAX_OUTPUT_CHANNELS];
  23. } mGains{};
  24. /* NOTE: BandSplitter filter is unused with single-band decoding. */
  25. BandSplitter mXOver;
  26. };
  27. alignas(16) std::array<FloatBufferLine,2> mSamples;
  28. const std::unique_ptr<FrontStablizer> mStablizer;
  29. const bool mDualBand{false};
  30. /* TODO: This should ideally be a FlexArray, since ChannelDecoder is rather
  31. * small and only a few are needed (3, 4, 5, 7, typically). But that can
  32. * only be used in a standard layout struct, and a std::unique_ptr member
  33. * (mStablizer) causes GCC and Clang to warn it's not.
  34. */
  35. al::vector<ChannelDecoder> mChannelDec;
  36. public:
  37. BFormatDec(const size_t inchans, const al::span<const ChannelDec> coeffs,
  38. const al::span<const ChannelDec> coeffslf, const float xover_f0norm,
  39. std::unique_ptr<FrontStablizer> stablizer);
  40. bool hasStablizer() const noexcept { return mStablizer != nullptr; }
  41. /* Decodes the ambisonic input to the given output channels. */
  42. void process(const al::span<FloatBufferLine> OutBuffer, const FloatBufferLine *InSamples,
  43. const size_t SamplesToDo);
  44. /* Decodes the ambisonic input to the given output channels with stablization. */
  45. void processStablize(const al::span<FloatBufferLine> OutBuffer,
  46. const FloatBufferLine *InSamples, const size_t lidx, const size_t ridx, const size_t cidx,
  47. const size_t SamplesToDo);
  48. static std::unique_ptr<BFormatDec> Create(const size_t inchans,
  49. const al::span<const ChannelDec> coeffs, const al::span<const ChannelDec> coeffslf,
  50. const float xover_f0norm, std::unique_ptr<FrontStablizer> stablizer);
  51. DEF_NEWDEL(BFormatDec)
  52. };
  53. #endif /* CORE_BFORMATDEC_H */