aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/uhjfilter.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-02-26 12:57:03 -0800
committerChris Robinson <[email protected]>2016-02-26 14:51:56 -0800
commit67f086d1d4527d1c920d90660124c5592b898354 (patch)
treebf87a5f3be027ef38096a3a29adb84ad9c80c906 /Alc/uhjfilter.h
parent3c127dc422291e438eade78bc656cec88035db4a (diff)
Add a function to encode 2-channel UHJ from B-Format
Diffstat (limited to 'Alc/uhjfilter.h')
-rw-r--r--Alc/uhjfilter.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/Alc/uhjfilter.h b/Alc/uhjfilter.h
new file mode 100644
index 00000000..5238e202
--- /dev/null
+++ b/Alc/uhjfilter.h
@@ -0,0 +1,49 @@
+#ifndef UHJFILTER_H
+#define UHJFILTER_H
+
+#include "AL/al.h"
+
+#include "alMain.h"
+
+typedef struct AllPassState {
+ ALfloat x[2]; /* Last two input samples */
+ ALfloat y[2]; /* Last two output samples */
+} AllPassState;
+
+/* Encoding 2-channel UHJ from B-Format is done as:
+ *
+ * W' = W * sqrt(2)
+ * S = 0.9396926*W' + 0.1855740*X
+ * D = j(-0.3420201*W' + 0.5098604*X) + 0.6554516*Y
+ *
+ * Left = (S + D)/2.0
+ * Right = (S - D)/2.0
+ *
+ * where j is a wide-band +90 degree phase shift.
+ *
+ * The phase shift is done using a Hilbert transform, described here:
+ * https://web.archive.org/web/20060708031958/http://www.biochem.oulu.fi/~oniemita/dsp/hilbert/
+ * It works using 2 sets of 4 chained filters. The first filter chain produces
+ * a phase shift of varying magnitude over a wide range of frequencies, while
+ * the second filter chain produces a phase shift 90 degrees ahead of the
+ * first over the same range.
+ *
+ * Combining these two stages requires the use of three filter chains. S-
+ * channel output uses a Filter1 chain on the W and X channel mix, while the D-
+ * channel output uses a Filter1 chain on the Y channel plus a Filter2 chain on
+ * the W and X channel mix. This results in the W and X input mix on the D-
+ * channel output having the required +90 degree phase shift relative to the
+ * other inputs.
+ */
+
+typedef struct Uhj2Encoder {
+ AllPassState Filter1_WX[4];
+ AllPassState Filter1_Y[4];
+ AllPassState Filter2_WX[4];
+} Uhj2Encoder;
+
+/* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input
+ * signal. */
+void EncodeUhj2(Uhj2Encoder *enc, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat (*restrict InSamples)[BUFFERSIZE], ALuint SamplesToDo);
+
+#endif /* UHJFILTER_H */