blob: 17a01d20e8ce37768d8428a798d2ff7d652c0bb1 (
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
|
#ifndef UHJFILTER_H
#define UHJFILTER_H
#include <array>
#include "alcmain.h"
#include "almalloc.h"
/* Encoding 2-channel UHJ from B-Format is done as:
*
* 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 FIR filter derived from an FFT'd impulse
* with the desired shift.
*/
struct Uhj2Encoder {
/* A particular property of the filter allows it to cover nearly twice its
* length, so the filter size is also the effective delay (despite being
* center-aligned).
*/
constexpr static size_t sFilterSize{128};
/* Delays for the unfiltered signal. */
alignas(16) std::array<float,sFilterSize> mMidDelay{};
alignas(16) std::array<float,sFilterSize> mSideDelay{};
alignas(16) std::array<float,BUFFERSIZE+sFilterSize> mMid{};
alignas(16) std::array<float,BUFFERSIZE+sFilterSize> mSide{};
/* History for the FIR filter. */
alignas(16) std::array<float,sFilterSize*2 - 1> mSideHistory{};
alignas(16) std::array<float,BUFFERSIZE + sFilterSize*2> mTemp{};
/**
* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input
* signal. The input must use FuMa channel ordering and scaling.
*/
void encode(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
const FloatBufferLine *InSamples, const size_t SamplesToDo);
DEF_NEWDEL(Uhj2Encoder)
};
#endif /* UHJFILTER_H */
|