AME
ame_Ambisonics.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include "ame_AudioBuffer.hpp"
13#include "ame_Math.hpp"
14#include "ame_Util.hpp"
15
16#include <array>
17#include <cassert>
18#include <cstdint>
19
20namespace ame::dsp
21{
25template <typename FloatType>
26struct Polar
27{
28 FloatType azimuth {};
29 FloatType elevation {};
30};
31
35template <typename FloatType>
37{
38 FloatType w {};
39 FloatType y {};
40 FloatType z {};
41 FloatType x {};
42};
43
47template <typename FloatType>
49{
50 FloatType w {};
51 FloatType y {};
52 FloatType x {};
53};
54
61template <typename FloatType>
62constexpr void encodeAmbisonics1st (FloatType in, Ambisonics3D1st<FloatType>& out, const Polar<FloatType>& pos)
63{
64 out.w = in;
65 out.x = in * cos (pos.azimuth) * cos (pos.elevation);
66 out.y = in * sin (pos.azimuth) * cos (pos.elevation);
67 out.z = in * sin (pos.elevation);
68}
69
76template <typename FloatType>
77constexpr void encodeAmbisonics1st (FloatType in, Ambisonics2D1st<FloatType>& out, const FloatType azimuth)
78{
79 out.w = in;
80 out.x = in * cos (azimuth);
81 out.y = in * sin (azimuth);
82}
83
90template <typename FloatType>
91constexpr FloatType decodeAmbisonics1st (const Ambisonics3D1st<FloatType>& in, const Polar<FloatType>& pos)
92{
93 FloatType out = in.w;
94 out += in.x / (cos (pos.azimuth) * cos (pos.azimuth));
95 out += in.y / (sin (pos.azimuth) * cos (pos.azimuth));
96 out += in.z / sin (pos.elevation);
97 return out;
98}
99
106template <typename FloatType>
107constexpr FloatType decodeAmbisonics1st (const Ambisonics2D1st<FloatType>& in, const FloatType azimuth)
108{
109 FloatType out = in.w;
110 out += in.x / cos (azimuth);
111 out += in.y / sin (azimuth);
112 return out;
113}
114
115} // namespace ame::dsp
constexpr void encodeAmbisonics1st(FloatType in, Ambisonics3D1st< FloatType > &out, const Polar< FloatType > &pos)
Mono to Ambisonics 1st encode.
Definition: ame_Ambisonics.hpp:62
constexpr FloatType decodeAmbisonics1st(const Ambisonics3D1st< FloatType > &in, const Polar< FloatType > &pos)
Ambisonics 1st to Mono decode.
Definition: ame_Ambisonics.hpp:91
Audio buffer.
Math functions.
constexpr float cos(float x)
cosf.
Definition: ame_Math.hpp:138
constexpr float sin(float x)
sin for float
Definition: ame_Math.hpp:61
Some utilities functions.
Ambisonics 2D struct.
Definition: ame_Ambisonics.hpp:49
Ambisonics 3D struct.
Definition: ame_Ambisonics.hpp:37
Polar.
Definition: ame_Ambisonics.hpp:27
FloatType azimuth
Azimuth in radian [-π, π].
Definition: ame_Ambisonics.hpp:28
FloatType elevation
Elevation in radian [-π, π].
Definition: ame_Ambisonics.hpp:29