aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/bformatdec.h
blob: 069746510128e5595d9811002611d64a91f2b9c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef BFORMATDEC_H
#define BFORMATDEC_H

#include <array>
#include <cstddef>

#include "AL/al.h"

#include "alcmain.h"
#include "almalloc.h"
#include "alspan.h"
#include "ambidefs.h"
#include "filters/splitter.h"
#include "vector.h"

struct AmbDecConf;


using ChannelDec = ALfloat[MAX_AMBI_CHANNELS];

class BFormatDec {
    static constexpr size_t sHFBand{0};
    static constexpr size_t sLFBand{1};
    static constexpr size_t sNumBands{2};

    ALuint mEnabled{0u}; /* Bitfield of enabled channels. */

    union MatrixU {
        ALfloat Dual[MAX_OUTPUT_CHANNELS][sNumBands][MAX_AMBI_CHANNELS];
        ALfloat Single[MAX_OUTPUT_CHANNELS][MAX_AMBI_CHANNELS];
    } mMatrix{};

    /* NOTE: BandSplitter filters are unused with single-band decoding */
    BandSplitter mXOver[MAX_AMBI_CHANNELS];

    al::vector<FloatBufferLine, 16> mSamples;
    /* These two alias into Samples */
    FloatBufferLine *mSamplesHF{nullptr};
    FloatBufferLine *mSamplesLF{nullptr};

    ALuint mNumChannels{0u};
    bool mDualBand{false};

public:
    BFormatDec(const AmbDecConf *conf, const bool allow_2band, const ALuint inchans,
        const ALuint srate, const ALsizei (&chanmap)[MAX_OUTPUT_CHANNELS]);
    BFormatDec(const ALuint inchans, const ALsizei chancount,
        const ChannelDec (&chancoeffs)[MAX_OUTPUT_CHANNELS],
        const ALsizei (&chanmap)[MAX_OUTPUT_CHANNELS]);

    /* Decodes the ambisonic input to the given output channels. */
    void process(const al::span<FloatBufferLine> OutBuffer, const FloatBufferLine *InSamples,
        const ALsizei SamplesToDo);

    /* Retrieves per-order HF scaling factors for "upsampling" ambisonic data. */
    static std::array<ALfloat,MAX_AMBI_ORDER+1> GetHFOrderScales(const ALsizei in_order,
        const ALsizei out_order) noexcept;

    DEF_NEWDEL(BFormatDec)
};

#endif /* BFORMATDEC_H */