Clean up some more loops
[openal-soft.git] / Alc / bformatdec.h
blob56737a60db889bdb146884a9ee6f7dbe9ebac3cd
1 #ifndef BFORMATDEC_H
2 #define BFORMATDEC_H
4 #include "alMain.h"
5 #include "filters/splitter.h"
6 #include "almalloc.h"
9 struct AmbDecConf;
12 /* These are the necessary scales for first-order HF responses to play over
13 * higher-order 2D (non-periphonic) decoders.
15 #define W_SCALE_2H0P 1.224744871f /* sqrt(1.5) */
16 #define XYZ_SCALE_2H0P 1.0f
17 #define W_SCALE_3H0P 1.414213562f /* sqrt(2) */
18 #define XYZ_SCALE_3H0P 1.082392196f
20 /* These are the necessary scales for first-order HF responses to play over
21 * higher-order 3D (periphonic) decoders.
23 #define W_SCALE_2H2P 1.341640787f /* sqrt(1.8) */
24 #define XYZ_SCALE_2H2P 1.0f
25 #define W_SCALE_3H3P 1.695486018f
26 #define XYZ_SCALE_3H3P 1.136697713f
29 /* NOTE: These are scale factors as applied to Ambisonics content. Decoder
30 * coefficients should be divided by these values to get proper N3D scalings.
32 extern const ALfloat N3D2N3DScale[MAX_AMBI_COEFFS];
33 extern const ALfloat SN3D2N3DScale[MAX_AMBI_COEFFS];
34 extern const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS];
37 struct BFormatDec {
38 static constexpr size_t NumBands{2};
40 ALuint Enabled; /* Bitfield of enabled channels. */
42 union {
43 alignas(16) ALfloat Dual[MAX_OUTPUT_CHANNELS][NumBands][MAX_AMBI_COEFFS];
44 alignas(16) ALfloat Single[MAX_OUTPUT_CHANNELS][MAX_AMBI_COEFFS];
45 } Matrix;
47 /* NOTE: BandSplitter filters are unused with single-band decoding */
48 BandSplitter XOver[MAX_AMBI_COEFFS];
50 al::vector<std::array<ALfloat,BUFFERSIZE>, 16> Samples;
51 /* These two alias into Samples */
52 std::array<ALfloat,BUFFERSIZE> *SamplesHF;
53 std::array<ALfloat,BUFFERSIZE> *SamplesLF;
55 alignas(16) ALfloat ChannelMix[BUFFERSIZE];
57 struct {
58 BandSplitter XOver;
59 ALfloat Gains[NumBands];
60 } UpSampler[4];
62 ALsizei NumChannels;
63 ALboolean DualBand;
65 DEF_NEWDEL(BFormatDec)
68 void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei (&chanmap)[MAX_OUTPUT_CHANNELS]);
70 /* Decodes the ambisonic input to the given output channels. */
71 void bformatdec_process(BFormatDec *dec, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
73 /* Up-samples a first-order input to the decoder's configuration. */
74 void bformatdec_upSample(BFormatDec *dec, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo);
77 /* Stand-alone first-order upsampler. Kept here because it shares some stuff
78 * with bformatdec. Assumes a periphonic (4-channel) input mix!
80 struct AmbiUpsampler {
81 static constexpr size_t NumBands{2};
83 alignas(16) ALfloat Samples[NumBands][BUFFERSIZE];
85 BandSplitter XOver[4];
87 ALfloat Gains[4][MAX_OUTPUT_CHANNELS][NumBands];
89 DEF_NEWDEL(AmbiUpsampler)
92 void ambiup_reset(AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat w_scale, ALfloat xyz_scale);
93 void ambiup_process(AmbiUpsampler *ambiup, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
95 #endif /* BFORMATDEC_H */