RavEngine
Loading...
Searching...
No Matches
constants_and_types.h
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_BASE_CONSTANTS_AND_TYPES_H_
18#define RESONANCE_AUDIO_BASE_CONSTANTS_AND_TYPES_H_
19
20#include <cmath>
21#if _WIN32
22#define M_PI 3.14159265358979323846
23#endif
24#include <string> // for size_t
25
26namespace vraudio {
27
28// Sound object / ambisonic source identifier.
29
30typedef int SourceId;
31
32// Invalid source id that can be used to initialize handler variables during
33// class construction.
34static const SourceId kInvalidSourceId = -1;
35
36
37// Defines memory alignment of audio buffers. Note that not only the first
38// element of the |data_| buffer is memory aligned but also the address of the
39// first elements of the |ChannelView|s.
40const size_t kMemoryAlignmentBytes = 64;
41
42// Maximum Ambisonic order currently supported in vr audio, equivalent to High
43// Quality sound object rendering mode. This number is limited by a) number of
44// HRIR data points used in the binaural renderer; b) size of the lookup table
45// controlling the angular spread of a sound source in the Ambisonic Lookup
46// Table class.
47static const int kMaxSupportedAmbisonicOrder = 3;
48
49// Maximum allowed size of internal buffers.
50const size_t kMaxSupportedNumFrames = 16384;
51
52// Number of mono channels.
53static const size_t kNumMonoChannels = 1;
54
55// Number of stereo channels.
56static const size_t kNumStereoChannels = 2;
57
58// Number of surround 5.1 channels.
59static const size_t kNumSurroundFiveDotOneChannels = 6;
60
61// Number of surround 7.1 channels.
62static const size_t kNumSurroundSevenDotOneChannels = 8;
63
64// Number of first-order ambisonic channels.
65static const size_t kNumFirstOrderAmbisonicChannels = 4;
66
67// Number of second-order ambisonic channels.
68static const size_t kNumSecondOrderAmbisonicChannels = 9;
69
70// Number of third-order ambisonic channels.
71static const size_t kNumThirdOrderAmbisonicChannels = 16;
72
73// Number of first-order ambisonic with non-diegetic stereo channels.
74static const size_t kNumFirstOrderAmbisonicWithNonDiegeticStereoChannels = 6;
75
76// Number of second-order ambisonic with non-diegetic stereo channels.
77static const size_t kNumSecondOrderAmbisonicWithNonDiegeticStereoChannels = 11;
78
79// Number of third-order ambisonic with non-diegetic stereo channels.
80static const size_t kNumThirdOrderAmbisonicWithNonDiegeticStereoChannels = 18;
81
82// Negative 60dB in amplitude.
83static const float kNegative60dbInAmplitude = 0.001f;
84
85// Tolerated error margins for floating points.
86static const double kEpsilonDouble = 1e-6;
87static const float kEpsilonFloat = 1e-6f;
88
89// Inverse square root of two (equivalent to -3dB audio signal attenuation).
90static const float kInverseSqrtTwo = 1.0f / std::sqrt(2.0f);
91
92// Square roots.
93static const float kSqrtTwo = std::sqrt(2.0f);
94static const float kSqrtThree = std::sqrt(3.0f);
95
96// Pi in radians.
97static const float kPi = static_cast<float>(M_PI);
98// Half pi in radians.
99static const float kHalfPi = static_cast<float>(M_PI / 2.0);
100// Two pi in radians.
101static const float kTwoPi = static_cast<float>(2.0 * M_PI);
102
103// Defines conversion factor from degrees to radians.
104static const float kRadiansFromDegrees = static_cast<float>(M_PI / 180.0);
105
106// Defines conversion factor from radians to degrees.
107static const float kDegreesFromRadians = static_cast<float>(180.0 / M_PI);
108
109// The negated natural logarithm of 1000.
110static const float kNegativeLog1000 = -std::log(1000.0f);
111
112// The lowest octave band for computing room effects.
113static const float kLowestOctaveBandHz = 31.25f;
114
115// Number of octave bands in which room effects are computed.
116static const size_t kNumReverbOctaveBands = 9;
117
118// Centers of possible frequency bands up 8 kHz.
119// ------------------------------------
120// Band no. Low Center High [Frequencies in Hz]
121// ------------------------------------
122// 0 22 31.25 44.2
123// 1 44.2 62.5 88.4
124// 2 88.4 125 176.8
125// 3 176.8 250 353.6
126// 4 353.6 500 707.1
127// 5 707.1 1000 1414.2
128// 6 1414.2 2000 2828.4
129// 7 2828.4 4000 5656.9
130// 8 5656.9 8000 11313.7
131//--------------------------------------
132const float kOctaveBandCentres[kNumReverbOctaveBands] = {
133 31.25f, 62.5f, 125.0f, 250.0f, 500.0f, 1000.0f, 2000.0f, 4000.0f, 8000.0f};
134
135// Number of surfaces in a shoe-box room.
136static const size_t kNumRoomSurfaces = 6;
137
138// Speed of sound in air at 20 degrees Celsius in meters per second.
139// http://www.sengpielaudio.com/calculator-speedsound.htm
140static const float kSpeedOfSound = 343.0f;
141
142// Locations of the stereo virtual loudspeakers in degrees.
143static const float kStereoLeftDegrees = 90.0f;
144static const float kStereoRightDegrees = -90.0f;
145
146// Conversion factor from seconds to milliseconds.
147static const float kMillisecondsFromSeconds = 1000.0f;
148
149// Conversion factor from milliseconds to seconds.
150static const float kSecondsFromMilliseconds = 0.001f;
151
152// Conversion factor from seconds to milliseconds.
153static const double kMicrosecondsFromSeconds = 1e6;
154
155// Conversion factor from milliseconds to seconds.
156static const double kSecondsFromMicroseconds = 1e-6;
157
158// The distance threshold where the near field effect should fade in.
159static const float kNearFieldThreshold = 1.0f;
160
161// Minimum allowed distance of a near field sound source used to cap the allowed
162// energy boost.
163static const float kMinNearFieldDistance = 0.1f;
164
165// Maximum gain applied by Near Field Effect to the mono source signal.
166static const float kMaxNearFieldEffectGain = 9.0f;
167
168// Number of samples across which the gain value should be interpolated for
169// a unit gain change of 1.0f.
170
171static const size_t kUnitRampLength = 2048;
172
173// Rotation quantization which applies in ambisonic soundfield rotators.
174
175static const float kRotationQuantizationRad = 1.0f * kRadiansFromDegrees;
176
177} // namespace vraudio
178
179#endif // RESONANCE_AUDIO_BASE_CONSTANTS_AND_TYPES_H_