Mach1 Spatial SDK
Loading...
Searching...
No Matches
Mach1EncodeCore.h
1// Mach1 Spatial SDK
2// Copyright © 2017 Mach1. All rights reserved.
3
4/*
5Internal Orientation Implementation:
6 - Azimuth[+] = rotate right 0-1 [Range: 0->360 | -180->180]
7 - Azimuth[-] = rotate left 0-1 [Range: 0->360 | -180->180]
8 - Elevation[+] = rotate up 0-1 [Range: -90->90]
9 - Elevation[-] = rotate down 0-1 [Range: -90->90]
10 - OrbitRotation[+] = rotate right 0-1 [Range: 0->360 | -180->180]
11 - OrbitRotation[-] = rotate left 0-1 [Range: 0->360 | -180->180]
12
13M1EncodeCore normalizes all input ranges to an unsigned "0 to 1" range for Azimuth, Elevation and OrbitRotation.
14 */
15
16#pragma once
17
18#ifdef M1ENCODE_INLINE_DECODE
19# include "Mach1DecodeCAPI.h"
20#endif
21#include "Mach1Point3D.h"
22
23#include <chrono>
24#include <string>
25#include <vector>
26
27#ifndef SWIG
28using namespace std::chrono;
29#endif
30
31#ifndef PI
32# define PI 3.14159265358979323846f
33#endif
34
35#ifndef DEG_TO_RAD
36# define DEG_TO_RAD (PI / 180)
37#endif
38
39#ifndef MAX_CHANNELS_COUNT
40# define MAX_CHANNELS_COUNT 64
41#endif
42
43#ifndef MAX_POINTS_COUNT
44# define MAX_POINTS_COUNT 16
45#endif
46
48 Mach1Point3D ppoints[MAX_POINTS_COUNT];
49 int pointsCount;
50 std::string pointsNames[MAX_POINTS_COUNT];
51 std::vector< std::vector<float> > gains;
52
53 friend class M1EncodeCore;
54
55 public:
58
59 std::vector<Mach1Point3D> getChannelPoints();
60 std::vector< std::vector<float> > getGains();
61 std::vector<std::string> getChannelPointsNames();
62 std::vector<float> getGainsForInputChannelByName(std::string pointName);
63 int getPointsCount();
64};
65
67 public:
68 enum InputMode {
69 INPUT_MONO = (int)0,
70 INPUT_STEREO,
71 INPUT_LCR,
72 INPUT_QUAD,
73 INPUT_LCRS,
74 INPUT_AFORMAT,
75 INPUT_FIVE_ZERO,
80 INPUT_1OAFUMA,
81 INPUT_2OAACN,
82 INPUT_2OAFUMA,
83 INPUT_3OAACN,
84 INPUT_3OAFUMA
85 };
86 enum OutputMode {
87 OUTPUT_SPATIAL_4CH = (int)0,
88 OUTPUT_SPATIAL_8CH,
89 OUTPUT_SPATIAL_14CH
90 };
91
92 enum PannerMode {
93 MODE_ISOTROPICLINEAR = (int)0,
94 MODE_ISOTROPICEQUALPOWER,
95 MODE_PERIPHONICLINEAR
96 };
97
99 InputMode mode;
100 std::string name;
101 };
102 std::vector<InputModeName> inputModeNames = {
103 {INPUT_MONO, "1.0"},
104 {INPUT_STEREO, "2.0_C"},
105 {INPUT_LCR, "3.0_LCR"},
106 {INPUT_QUAD, "4.0_Quad"},
107 {INPUT_LCRS, "4.0_LCRS"},
108 {INPUT_AFORMAT, "4.0_AFormat"},
109 {INPUT_FIVE_ZERO, "5.0_C"},
110 {INPUT_FIVE_ONE_FILM, "5.1_C"},
111 {INPUT_FIVE_ONE_DTS, "5.1_C_Dts"},
112 {INPUT_FIVE_ONE_SMPTE, "5.1_C_SMPTE"},
113 {INPUT_1OAACN, "ACNSN3D"},
114 {INPUT_1OAFUMA, "FuMa"},
115 {INPUT_2OAACN, "ACNSN3DO2A"},
116 {INPUT_2OAFUMA, "FuMaO2A"},
117 {INPUT_3OAACN, "FuMaO3A"},
118 {INPUT_3OAFUMA, "ACNSN3DO3A"},
119 };
120
122 OutputMode mode;
123 std::string name;
124 };
125 std::vector<OutputModeName> outputModeNames = {
126 {OUTPUT_SPATIAL_4CH, "M1Spatial-4"},
127 {OUTPUT_SPATIAL_8CH, "M1Spatial-8"},
128 {OUTPUT_SPATIAL_14CH, "M1Spatial-14"},
129 };
130
131 // arrays for CAPI
132 Mach1Point3D *arr_Points = nullptr;
133 float **arr_Gains = nullptr;
134 char **arr_PointsNames = nullptr;
135 float *arr_GainsForInputChannelNamed = nullptr;
136 float *arr_ResultingCoeffsDecoded = nullptr;
137
138 private:
139 InputMode inputMode;
140 OutputMode outputMode;
141 PannerMode pannerMode;
142
143 float azimuth, diverge, elevation;
144 float orbitRotation, sSpread;
145 bool autoOrbit;
146 bool frontSurroundPerspective;
147 float outputGainLinearMultipler;
148 bool gainCompensationActive = false;
149 float gainCompensationLinearMultiplier = 1.0f;
150
151 float clamp(float n, float lower, float upper);
152 void assignResultingPointsNamesAndCoordinates(const std::vector<std::string> &names, const std::vector<Mach1Point3D> &pnts);
153 float getCoeffForChannelPoint(float x, float y, float z, Mach1Point3D point, bool ignoreZ);
154 void processGains(float x, float y, float z, std::vector<float> &result);
155
156 milliseconds ms;
157 long timeLastCalculation;
158
159 public:
160 M1EncodeCore();
162
163 M1EncodeCore(const M1EncodeCore &other);
164 M1EncodeCore &operator=(const M1EncodeCore &other);
165
166 void generatePointResults();
167 M1EncodeCorePointResults resultingPoints;
168
169#ifdef M1ENCODE_INLINE_DECODE
170 void getResultingCoeffsDecoded(Mach1DecodeMode decodeMode, float *decodeResult, float *result);
171#endif
172
173 InputMode getInputMode();
174 OutputMode getOutputMode();
175 PannerMode getPannerMode();
176 bool getAutoOrbit();
177 int getInputChannelsCount();
178 int getOutputChannelsCount();
179
180 int getInputModeFromString(std::string name);
181 int getOutputModeFromString(std::string name);
182
183 void setInputMode(InputMode inputMode);
184 void setOutputMode(OutputMode outputMode);
185 void setAzimuth(float azimuthFromMinus1To1);
186 void setAzimuthDegrees(float azimuthDegrees);
187 void setAzimuthRadians(float azimuthRadians);
188 void setDiverge(float divergeFromMinus1To1);
189 void setElevation(float elevationFromMinus1to1);
190 void setElevationDegrees(float elevationFromMinus90to90);
191 void setElevationRadians(float elevationFromMinusHalfPItoHalfPI);
192 void setIsotropicEncode(bool isotropicEncode);
193 void setPannerMode(PannerMode pannerMode);
194 void setFrontSurroundPerspective(bool frontSurroundPerspective);
195
196 float getOutputGain(bool isDecibel);
197 void setOutputGain(float outputGainMultipler, bool isDecibel);
198
199 void setAutoOrbit(bool autoOrbit);
200 void setOrbitRotation(float orbitRotationFromMinusOnetoOne);
201 void setOrbitRotationDegrees(float orbitRotationDegrees);
202 void setOrbitRotationRadians(float orbitRotationRadians);
203 void setStereoSpread(float sSpreadFrom0to1);
204
205 long getCurrentTime();
206 long getLastCalculationTime();
207
208 float getGainCompensation(bool isDecibel);
209 bool getGainCompensationActive();
210 void setGainCompensationActive(bool active);
211};
Definition Mach1EncodeCore.h:47
Definition Mach1EncodeCore.h:66
InputMode
Definition Mach1EncodeCore.h:68
@ INPUT_1OAACN
(Using Mach1Transcode is recommended instead)
Definition Mach1EncodeCore.h:79
@ INPUT_FIVE_ONE_FILM
(Using Mach1Transcode is recommended instead)
Definition Mach1EncodeCore.h:76
@ INPUT_FIVE_ONE_DTS
(Using Mach1Transcode is recommended instead)
Definition Mach1EncodeCore.h:77
@ INPUT_FIVE_ONE_SMPTE
(Using Mach1Transcode is recommended instead)
Definition Mach1EncodeCore.h:78
Definition Mach1EncodeCore.h:98
Definition Mach1EncodeCore.h:121
Definition Mach1Point3D.h:17