Use a unique_ptr for Uhj2Encoder
[openal-soft.git] / Alc / uhjfilter.h
blobc6335af302b5f44897dac47cbb2f22235f525db4
1 #ifndef UHJFILTER_H
2 #define UHJFILTER_H
4 #include "AL/al.h"
6 #include "alMain.h"
7 #include "almalloc.h"
10 struct AllPassState {
11 ALfloat z[2]{0.0f, 0.0f};
14 /* Encoding 2-channel UHJ from B-Format is done as:
16 * S = 0.9396926*W + 0.1855740*X
17 * D = j(-0.3420201*W + 0.5098604*X) + 0.6554516*Y
19 * Left = (S + D)/2.0
20 * Right = (S - D)/2.0
22 * where j is a wide-band +90 degree phase shift.
24 * The phase shift is done using a Hilbert transform, described here:
25 * https://web.archive.org/web/20060708031958/http://www.biochem.oulu.fi/~oniemita/dsp/hilbert/
26 * It works using 2 sets of 4 chained filters. The first filter chain produces
27 * a phase shift of varying magnitude over a wide range of frequencies, while
28 * the second filter chain produces a phase shift 90 degrees ahead of the
29 * first over the same range.
31 * Combining these two stages requires the use of three filter chains. S-
32 * channel output uses a Filter1 chain on the W and X channel mix, while the D-
33 * channel output uses a Filter1 chain on the Y channel plus a Filter2 chain on
34 * the W and X channel mix. This results in the W and X input mix on the D-
35 * channel output having the required +90 degree phase shift relative to the
36 * other inputs.
39 struct Uhj2Encoder {
40 AllPassState Filter1_Y[4];
41 AllPassState Filter2_WX[4];
42 AllPassState Filter1_WX[4];
43 ALfloat LastY{0.0f}, LastWX{0.0f};
45 DEF_NEWDEL(Uhj2Encoder)
48 /* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input
49 * signal. The input must use FuMa channel ordering and scaling.
51 void EncodeUhj2(Uhj2Encoder *enc, ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
53 #endif /* UHJFILTER_H */