Limit convolution processing to the output ambisonic order
[openal-soft.git] / alc / bformatdec.h
blob03249c55dca1eec270f39ed5d565041a8d601b29
1 #ifndef BFORMATDEC_H
2 #define BFORMATDEC_H
4 #include <array>
5 #include <cstddef>
6 #include <memory>
8 #include "AL/al.h"
10 #include "alcmain.h"
11 #include "almalloc.h"
12 #include "alspan.h"
13 #include "ambidefs.h"
14 #include "devformat.h"
15 #include "filters/splitter.h"
17 struct AmbDecConf;
18 struct FrontStablizer;
21 using ChannelDec = std::array<float,MAX_AMBI_CHANNELS>;
23 class BFormatDec {
24 static constexpr size_t sHFBand{0};
25 static constexpr size_t sLFBand{1};
26 static constexpr size_t sNumBands{2};
28 struct ChannelDecoder {
29 union MatrixU {
30 float Dual[sNumBands][MAX_OUTPUT_CHANNELS];
31 float Single[MAX_OUTPUT_CHANNELS];
32 } mGains{};
34 /* NOTE: BandSplitter filter is unused with single-band decoding. */
35 BandSplitter mXOver;
38 alignas(16) std::array<FloatBufferLine,2> mSamples;
40 const std::unique_ptr<FrontStablizer> mStablizer;
41 const bool mDualBand{false};
43 al::FlexArray<ChannelDecoder> mChannelDec;
45 public:
46 BFormatDec(const AmbDecConf *conf, const bool allow_2band, const size_t inchans,
47 const ALuint srate, const ALuint (&chanmap)[MAX_OUTPUT_CHANNELS],
48 std::unique_ptr<FrontStablizer> stablizer);
49 BFormatDec(const size_t inchans, const al::span<const ChannelDec> coeffs,
50 const al::span<const ChannelDec> coeffslf, std::unique_ptr<FrontStablizer> stablizer);
52 bool hasStablizer() const noexcept { return mStablizer != nullptr; };
54 /* Decodes the ambisonic input to the given output channels. */
55 void process(const al::span<FloatBufferLine> OutBuffer, const FloatBufferLine *InSamples,
56 const size_t SamplesToDo);
58 /* Decodes the ambisonic input to the given output channels with stablization. */
59 void processStablize(const al::span<FloatBufferLine> OutBuffer,
60 const FloatBufferLine *InSamples, const size_t lidx, const size_t ridx, const size_t cidx,
61 const size_t SamplesToDo);
63 /* Retrieves per-order HF scaling factors for "upsampling" ambisonic data. */
64 static std::array<float,MAX_AMBI_ORDER+1> GetHFOrderScales(const ALuint in_order,
65 const ALuint out_order) noexcept;
67 static std::unique_ptr<BFormatDec> Create(const AmbDecConf *conf, const bool allow_2band,
68 const size_t inchans, const ALuint srate, const ALuint (&chanmap)[MAX_OUTPUT_CHANNELS],
69 std::unique_ptr<FrontStablizer> stablizer);
70 static std::unique_ptr<BFormatDec> Create(const size_t inchans,
71 const al::span<const ChannelDec> coeffs, const al::span<const ChannelDec> coeffslf,
72 std::unique_ptr<FrontStablizer> stablizer);
74 DEF_FAM_NEWDEL(BFormatDec, mChannelDec)
77 #endif /* BFORMATDEC_H */