bformatdec.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef CORE_BFORMATDEC_H
  2. #define CORE_BFORMATDEC_H
  3. #include <array>
  4. #include <cstddef>
  5. #include <memory>
  6. #include <variant>
  7. #include <vector>
  8. #include "alspan.h"
  9. #include "ambidefs.h"
  10. #include "bufferline.h"
  11. #include "devformat.h"
  12. #include "filters/splitter.h"
  13. #include "front_stablizer.h"
  14. #include "opthelpers.h"
  15. using ChannelDec = std::array<float,MaxAmbiChannels>;
  16. class SIMDALIGN BFormatDec {
  17. static constexpr size_t sHFBand{0};
  18. static constexpr size_t sLFBand{1};
  19. static constexpr size_t sNumBands{2};
  20. struct ChannelDecoderSingle {
  21. std::array<float,MaxOutputChannels> mGains{};
  22. };
  23. struct ChannelDecoderDual {
  24. BandSplitter mXOver;
  25. std::array<std::array<float,MaxOutputChannels>,sNumBands> mGains{};
  26. };
  27. alignas(16) std::array<FloatBufferLine,2> mSamples{};
  28. const std::unique_ptr<FrontStablizer> mStablizer;
  29. std::variant<std::vector<ChannelDecoderSingle>,std::vector<ChannelDecoderDual>> mChannelDec;
  30. public:
  31. BFormatDec(const size_t inchans, const al::span<const ChannelDec> coeffs,
  32. const al::span<const ChannelDec> coeffslf, const float xover_f0norm,
  33. std::unique_ptr<FrontStablizer> stablizer);
  34. [[nodiscard]] auto hasStablizer() const noexcept -> bool { return mStablizer != nullptr; }
  35. /* Decodes the ambisonic input to the given output channels. */
  36. void process(const al::span<FloatBufferLine> OutBuffer,
  37. const al::span<const FloatBufferLine> InSamples, const size_t SamplesToDo);
  38. /* Decodes the ambisonic input to the given output channels with stablization. */
  39. void processStablize(const al::span<FloatBufferLine> OutBuffer,
  40. const al::span<const FloatBufferLine> InSamples, const size_t lidx, const size_t ridx,
  41. const size_t cidx, const size_t SamplesToDo);
  42. static std::unique_ptr<BFormatDec> Create(const size_t inchans,
  43. const al::span<const ChannelDec> coeffs, const al::span<const ChannelDec> coeffslf,
  44. const float xover_f0norm, std::unique_ptr<FrontStablizer> stablizer);
  45. };
  46. #endif /* CORE_BFORMATDEC_H */