Mach1 Spatial SDK
Loading...
Searching...
No Matches
Mach1DecodeCore.h
1// Mach1 Spatial SDK
2// Copyright © 2017 Mach1. All rights reserved.
3
4/*
5DISCLAIMER:
6This header file is not an example of use but an decoder that will require periodic
7updates and should not be integrated in sections but remain as an update-able factored file.
8*/
9
10/*
11Internal Orientation Implementation:
12 - Yaw [0]+ = rotate right 0-1 [Range: 0->360 | -180->180]
13 - Yaw [0]- = rotate left 0-1 [Range: 0->360 | -180->180]
14 - Pitch [1]+ = rotate up 0-1 [Range: -90->90]
15 - Pitch [1]- = rotate down 0-1 [Range: -90->90]
16 - Roll [2]+ = rotate up 0-1 [Range: -90->90]
17 - Roll [2]- = rotate down 0-1 [Range: -90->90]
18
19M1DecodeCore normalizes all input ranges to an unsigned "0 to 1" range for Yaw, Pitch and Roll.
20 */
21
22#pragma once
23
24#include <chrono>
25#include <string>
26#include <vector>
27
28#include "Mach1DecodeCAPI.h"
29#include "Mach1Point3D.h"
30#include "Mach1Point4D.h"
31
32#ifndef SWIG
33using namespace std::chrono;
34#endif
35
36#ifndef PI
37# define PI 3.14159265358979323846f
38#endif
39
41
43
44 public:
45 static float mDegToRad(float degrees);
46 static float mmap(float value, float inputMin, float inputMax, float outputMin, float outputMax, bool clamp = false);
47 static float clamp(float a, float min, float max);
48
49 private:
50 // TODO: Why do we use typedef? Can we remove it?
51 typedef std::vector<float> (M1DecodeCore::*processSampleForMultichannel)(float Yaw, float Pitch, float Roll);
52 typedef void (M1DecodeCore::*processSampleForMultichannelPtr)(float Yaw, float Pitch, float Roll, float *result);
53
54 std::vector<float> processSample(processSampleForMultichannel _processSampleForMultichannel, float Yaw, float Pitch, float Roll, int bufferSize = 0, int sampleIndex = 0);
55 void processSample(processSampleForMultichannelPtr _processSampleForMultichannelPtr, float Yaw, float Pitch, float Roll, float *result, int bufferSize = 0, int sampleIndex = 0);
56
57 // Math utilities
58 static float alignAngle(float a, float min = -180, float max = 180);
59 static float lerp(float x1, float x2, float t);
60 float radialDistance(float angle1, float angle2);
61 float targetDirectionMultiplier(float angleCurrent, float angleTarget);
62 inline float _dot(const Mach1Point3D &p1, const Mach1Point3D &p2) const;
63 bool linePlaneIntersection(Mach1Point3D &contact, Mach1Point3D ray, Mach1Point3D rayOrigin, Mach1Point3D normal, Mach1Point3D coord);
64
65 // Filter features
66 // Envelope follower feature is defined here, in updateAngles()
67 void updateAngles();
68 float currentYaw, currentPitch, currentRoll;
69 float targetYaw, targetPitch, targetRoll;
70 float previousYaw, previousPitch, previousRoll;
71
72 milliseconds ms;
73 long timeLastUpdate;
74 long timeLastCalculation;
75
76 Mach1PlatformType platformType;
77 Mach1DecodeMode decodeMode;
78
79 void spatialMultichannelAlgo(Mach1Point3D *channelPoints, int numChannelPoints, float Yaw, float Pitch, float Roll, float *result);
80
81 void spatialAlgo_4(float Yaw, float Pitch, float Roll, float *result);
82 std::vector<float> spatialAlgo_4(float Yaw, float Pitch, float Roll);
83
84 void spatialAlgo_8(float Yaw, float Pitch, float Roll, float *result);
85 std::vector<float> spatialAlgo_8(float Yaw, float Pitch, float Roll);
86
87 void spatialAlgo_14(float Yaw, float Pitch, float Roll, float *result);
88 std::vector<float> spatialAlgo_14(float Yaw, float Pitch, float Roll);
89
90 // log
91 std::vector<std::string> strLog;
92 void addToLog(std::string str, int maxCount = 100);
93
94 Mach1Point3D rotation;
95
96 public:
97 char *getLog();
98 float filterSpeed;
99
100 // Angular settings functions
101 static void convertAnglesToMach1(Mach1PlatformType platformType, float *Y, float *P, float *R);
102 static void convertAnglesToPlatform(Mach1PlatformType platformType, float *Y, float *P, float *R);
103 // static void convertQuaternionToMach1(Mach1PlatformType platformType, float* X, float* Y, float* Z, float* W);
104 // static void convertQuaternionToPlatform(Mach1PlatformType platformType, float* Y, float* P, float* R);
105
106 Mach1Point3D getCurrentAngle();
107
108 M1DecodeCore();
109
110 void setPlatformType(Mach1PlatformType type);
111 Mach1PlatformType getPlatformType();
112
113 int getFormatChannelCount();
114 int getFormatCoeffCount();
115
116 void setRotation(Mach1Point3D newRotationFromMinusOnetoOne);
117 void setRotationDegrees(Mach1Point3D newRotationDegrees);
118 void setRotationRadians(Mach1Point3D newRotationRadians);
119 void setRotationQuat(Mach1Point4D newRotationQuat);
120
121 void setFilterSpeed(float filterSpeed);
122
123 long getCurrentTime();
124 long getLastCalculationTime();
125
126 // Set the algorithm type to use when decoding
127
128 void setDecodeMode(Mach1DecodeMode mode);
129 Mach1DecodeMode getDecodeMode();
130
131 // Decode using the current algorithm type
132
133 // Order of input angles:
134 // Y = Yaw in degrees
135 // P = Pitch in degrees
136 // R = Roll in degrees
137
138 std::vector<float> decode(float Yaw, float Pitch, float Roll, int bufferSize = 0, int sampleIndex = 0);
139 std::vector<float> decodeCoeffs(int bufferSize = 0, int sampleIndex = 0);
140 std::vector<float> decodePannedCoeffs(int bufferSize = 0, int sampleIndex = 0, bool applyPanLaw = true);
141
142 // Decode using the current algorithm type in a more efficient way
143
144 void decode(float Yaw, float Pitch, float Roll, float *result, int bufferSize = 0, int sampleIndex = 0);
145 void decodeCoeffs(float *result, int bufferSize = 0, int sampleIndex = 0);
146 void decodePannedCoeffs(float *result, int bufferSize = 0, int sampleIndex = 0, bool applyPanLaw = true);
147 void decodeCoeffsUsingTranscodeMatrix(void *M1obj, float *matrix, int channels, float *result, int bufferSize = 0, int sampleIndex = 0);
148
149};
Definition Mach1DecodeCore.h:42
Definition Mach1Point3D.h:17
Definition Mach1Point4D.h:15