bformatdec.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef BFORMATDEC_H
  2. #define BFORMATDEC_H
  3. #include <array>
  4. #include <cstddef>
  5. #include <memory>
  6. #include "almalloc.h"
  7. #include "alspan.h"
  8. #include "core/ambidefs.h"
  9. #include "core/bufferline.h"
  10. #include "core/devformat.h"
  11. #include "core/filters/splitter.h"
  12. struct AmbDecConf;
  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. al::FlexArray<ChannelDecoder> mChannelDec;
  31. public:
  32. BFormatDec(const AmbDecConf *conf, const bool allow_2band, const size_t inchans,
  33. const uint srate, const uint (&chanmap)[MAX_OUTPUT_CHANNELS],
  34. std::unique_ptr<FrontStablizer> stablizer);
  35. BFormatDec(const size_t inchans, const al::span<const ChannelDec> coeffs,
  36. const al::span<const ChannelDec> coeffslf, std::unique_ptr<FrontStablizer> stablizer);
  37. bool hasStablizer() const noexcept { return mStablizer != nullptr; };
  38. /* Decodes the ambisonic input to the given output channels. */
  39. void process(const al::span<FloatBufferLine> OutBuffer, const FloatBufferLine *InSamples,
  40. const size_t SamplesToDo);
  41. /* Decodes the ambisonic input to the given output channels with stablization. */
  42. void processStablize(const al::span<FloatBufferLine> OutBuffer,
  43. const FloatBufferLine *InSamples, const size_t lidx, const size_t ridx, const size_t cidx,
  44. const size_t SamplesToDo);
  45. /* Retrieves per-order HF scaling factors for "upsampling" ambisonic data. */
  46. static std::array<float,MaxAmbiOrder+1> GetHFOrderScales(const uint in_order,
  47. const uint out_order) noexcept;
  48. static std::unique_ptr<BFormatDec> Create(const AmbDecConf *conf, const bool allow_2band,
  49. const size_t inchans, const uint srate, const uint (&chanmap)[MAX_OUTPUT_CHANNELS],
  50. std::unique_ptr<FrontStablizer> stablizer);
  51. static std::unique_ptr<BFormatDec> Create(const size_t inchans,
  52. const al::span<const ChannelDec> coeffs, const al::span<const ChannelDec> coeffslf,
  53. std::unique_ptr<FrontStablizer> stablizer);
  54. DEF_FAM_NEWDEL(BFormatDec, mChannelDec)
  55. };
  56. #endif /* BFORMATDEC_H */