1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_AMBISONICS_ASSOCIATED_LEGENDRE_POLYNOMIALS_GENERATOR_H_
18#define RESONANCE_AUDIO_AMBISONICS_ASSOCIATED_LEGENDRE_POLYNOMIALS_GENERATOR_H_
19
20#include <stddef.h>
21#include <vector>
22
23namespace vraudio {
24
25// Generates associated Legendre polynomials.
26class AssociatedLegendrePolynomialsGenerator {
27 public:
28 // Constructs a generator for associated Legendre polynomials (ALP).
29 //
30 // @param max_degree The maximum ALP degree supported by this generator.
31 // @param condon_shortley_phase Whether the Condon-Shortley phase, (-1)^order,
32 // should be included in the polynomials generated.
33 // @param compute_negative_order Whether this generator should compute
34 // negative-ordered polynomials.
35 AssociatedLegendrePolynomialsGenerator(int max_degree,
36 bool condon_shortley_phase,
37 bool compute_negative_order);
38
39 // Generates the associated Legendre polynomials for the given |x|, returning
40 // the computed sequence.
41 //
42 // @param x The abscissa (the polynomials' variable).
43 // @return Output vector of computed values.
44 std::vector<float> Generate(float x) const;
45
46 // Gets the number of associated Legendre polynomials this generator produces.
47 //
48 // @return The number of associated Legendre polynomials this generator
49 // produces.
50 size_t GetNumValues() const;
51
52 // Gets the index into the output vector for the given |degree| and |order|.
53 //
54 // @param degree The polynomial's degree.
55 // @param order The polynomial's order.
56 // @return The index into the vector of computed values corresponding to the
57 // specified ALP.
58 size_t GetIndex(int degree, int order) const;
59
60 private:
61 // Computes the ALP for (degree, order) the given |x| using recurrence
62 // relations. It is assumed that the ALPs necessary for each computation are
63 // already computed and stored in |values|.
64 //
65 // @param degree The degree of the polynomial being computed.
66 // @param degree The order of the polynomial being computed.
67 // @param values The previously computed values.
68 // @return The computed polynomial.
69 inline float ComputeValue(int degree, int order, float x,
70 const std::vector<float>& values) const;
71
72 // Checks the validity of the given index.
73 //
74 // @param degree The polynomial's degree.
75 // @param order The polynomial's order.
76 inline void CheckIndexValidity(int degree, int order) const;
77
78 // The maximum polynomial degree that can be computed; must be >= 0.
79 int max_degree_ = 0;
80 // Whether the Condon-Shortley phase, (-1)^order, should be included in the
81 // polynomials generated.
82 bool condon_shortley_phase_ = false;
83 // Whether this generator should compute negative-ordered polynomials.
84 bool compute_negative_order_ = false;
85};
86
87} // namespace vraudio
88
89#endif // RESONANCE_AUDIO_AMBISONICS_ASSOCIATED_LEGENDRE_POLYNOMIALS_GENERATOR_H_
90

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/ambisonics/associated_legendre_polynomials_generator.h