]> git.tdb.fi Git - ext/openal.git/blob - core/filters/nfc.h
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / core / filters / nfc.h
1 #ifndef CORE_FILTERS_NFC_H
2 #define CORE_FILTERS_NFC_H
3
4 #include <cstddef>
5
6 #include "alspan.h"
7
8
9 struct NfcFilter1 {
10     float base_gain, gain;
11     float b1, a1;
12     float z[1];
13 };
14 struct NfcFilter2 {
15     float base_gain, gain;
16     float b1, b2, a1, a2;
17     float z[2];
18 };
19 struct NfcFilter3 {
20     float base_gain, gain;
21     float b1, b2, b3, a1, a2, a3;
22     float z[3];
23 };
24 struct NfcFilter4 {
25     float base_gain, gain;
26     float b1, b2, b3, b4, a1, a2, a3, a4;
27     float z[4];
28 };
29
30 class NfcFilter {
31     NfcFilter1 first;
32     NfcFilter2 second;
33     NfcFilter3 third;
34     NfcFilter4 fourth;
35
36 public:
37     /* NOTE:
38      * w0 = speed_of_sound / (source_distance * sample_rate);
39      * w1 = speed_of_sound / (control_distance * sample_rate);
40      *
41      * Generally speaking, the control distance should be approximately the
42      * average speaker distance, or based on the reference delay if outputing
43      * NFC-HOA. It must not be negative, 0, or infinite. The source distance
44      * should not be too small relative to the control distance.
45      */
46
47     void init(const float w1) noexcept;
48     void adjust(const float w0) noexcept;
49
50     /* Near-field control filter for first-order ambisonic channels (1-3). */
51     void process1(const al::span<const float> src, float *RESTRICT dst);
52
53     /* Near-field control filter for second-order ambisonic channels (4-8). */
54     void process2(const al::span<const float> src, float *RESTRICT dst);
55
56     /* Near-field control filter for third-order ambisonic channels (9-15). */
57     void process3(const al::span<const float> src, float *RESTRICT dst);
58
59     /* Near-field control filter for fourth-order ambisonic channels (16-24). */
60     void process4(const al::span<const float> src, float *RESTRICT dst);
61 };
62
63 #endif /* CORE_FILTERS_NFC_H */