Avoid duplicating some scale tables
[openal-soft.git] / Alc / bformatdec.h
bloba6ca220963246a15aabdac218e59a01058faf095
1 #ifndef BFORMATDEC_H
2 #define BFORMATDEC_H
4 #include "alMain.h"
7 /* These are the necessary scales for first-order HF responses to play over
8 * higher-order 2D (non-periphonic) decoders.
9 */
10 #define W_SCALE_2H0P 1.224744871f /* sqrt(1.5) */
11 #define XYZ_SCALE_2H0P 1.0f
12 #define W_SCALE_3H0P 1.414213562f /* sqrt(2) */
13 #define XYZ_SCALE_3H0P 1.082392196f
15 /* These are the necessary scales for first-order HF responses to play over
16 * higher-order 3D (periphonic) decoders.
18 #define W_SCALE_2H2P 1.341640787f /* sqrt(1.8) */
19 #define XYZ_SCALE_2H2P 1.0f
20 #define W_SCALE_3H3P 1.695486018f
21 #define XYZ_SCALE_3H3P 1.136697713f
24 /* NOTE: These are scale factors as applied to Ambisonics content. Decoder
25 * coefficients should be divided by these values to get proper N3D scalings.
27 const ALfloat N3D2N3DScale[MAX_AMBI_COEFFS];
28 const ALfloat SN3D2N3DScale[MAX_AMBI_COEFFS];
29 const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS];
32 struct AmbDecConf;
33 struct BFormatDec;
34 struct AmbiUpsampler;
37 struct BFormatDec *bformatdec_alloc();
38 void bformatdec_free(struct BFormatDec **dec);
39 void bformatdec_reset(struct BFormatDec *dec, const struct AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS]);
41 /* Decodes the ambisonic input to the given output channels. */
42 void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
44 /* Up-samples a first-order input to the decoder's configuration. */
45 void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo);
48 /* Stand-alone first-order upsampler. Kept here because it shares some stuff
49 * with bformatdec. Assumes a periphonic (4-channel) input mix!
51 struct AmbiUpsampler *ambiup_alloc();
52 void ambiup_free(struct AmbiUpsampler **ambiup);
53 void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat w_scale, ALfloat xyz_scale);
55 void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
58 /* Band splitter. Splits a signal into two phase-matching frequency bands. */
59 typedef struct BandSplitter {
60 ALfloat coeff;
61 ALfloat lp_z1;
62 ALfloat lp_z2;
63 ALfloat hp_z1;
64 } BandSplitter;
66 void bandsplit_init(BandSplitter *splitter, ALfloat f0norm);
67 void bandsplit_clear(BandSplitter *splitter);
68 void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout,
69 const ALfloat *input, ALsizei count);
71 /* The all-pass portion of the band splitter. Applies the same phase shift
72 * without splitting the signal.
74 typedef struct SplitterAllpass {
75 ALfloat coeff;
76 ALfloat z1;
77 } SplitterAllpass;
79 void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm);
80 void splitterap_clear(SplitterAllpass *splitter);
81 void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count);
84 typedef struct FrontStablizer {
85 SplitterAllpass APFilter[MAX_OUTPUT_CHANNELS];
86 BandSplitter LFilter, RFilter;
87 alignas(16) ALfloat LSplit[2][BUFFERSIZE];
88 alignas(16) ALfloat RSplit[2][BUFFERSIZE];
89 } FrontStablizer;
91 #endif /* BFORMATDEC_H */