Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/faudio/src/FACT3D.c
4389 views
1
/* FAudio - XAudio Reimplementation for FNA
2
*
3
* Copyright (c) 2011-2024 Ethan Lee, Luigi Auriemma, and the MonoGame Team
4
*
5
* This software is provided 'as-is', without any express or implied warranty.
6
* In no event will the authors be held liable for any damages arising from
7
* the use of this software.
8
*
9
* Permission is granted to anyone to use this software for any purpose,
10
* including commercial applications, and to alter it and redistribute it
11
* freely, subject to the following restrictions:
12
*
13
* 1. The origin of this software must not be misrepresented; you must not
14
* claim that you wrote the original software. If you use this software in a
15
* product, an acknowledgment in the product documentation would be
16
* appreciated but is not required.
17
*
18
* 2. Altered source versions must be plainly marked as such, and must not be
19
* misrepresented as being the original software.
20
*
21
* 3. This notice may not be removed or altered from any source distribution.
22
*
23
* Ethan "flibitijibibo" Lee <[email protected]>
24
*
25
*/
26
27
#include "FACT3D.h"
28
29
uint32_t FACT3DInitialize(
30
FACTAudioEngine *pEngine,
31
F3DAUDIO_HANDLE F3DInstance
32
) {
33
float nSpeedOfSound;
34
FAudioWaveFormatExtensible wfxFinalMixFormat;
35
36
if (pEngine == NULL)
37
{
38
return 0;
39
}
40
41
FACTAudioEngine_GetGlobalVariable(
42
pEngine,
43
FACTAudioEngine_GetGlobalVariableIndex(
44
pEngine,
45
"SpeedOfSound"
46
),
47
&nSpeedOfSound
48
);
49
FACTAudioEngine_GetFinalMixFormat(
50
pEngine,
51
&wfxFinalMixFormat
52
);
53
F3DAudioInitialize(
54
wfxFinalMixFormat.dwChannelMask,
55
nSpeedOfSound,
56
F3DInstance
57
);
58
return 0;
59
}
60
61
uint32_t FACT3DCalculate(
62
F3DAUDIO_HANDLE F3DInstance,
63
const F3DAUDIO_LISTENER *pListener,
64
F3DAUDIO_EMITTER *pEmitter,
65
F3DAUDIO_DSP_SETTINGS *pDSPSettings
66
) {
67
static F3DAUDIO_DISTANCE_CURVE_POINT DefaultCurvePoints[2] =
68
{
69
{ 0.0f, 1.0f },
70
{ 1.0f, 1.0f }
71
};
72
static F3DAUDIO_DISTANCE_CURVE DefaultCurve =
73
{
74
(F3DAUDIO_DISTANCE_CURVE_POINT*) &DefaultCurvePoints[0], 2
75
};
76
77
if (pListener == NULL || pEmitter == NULL || pDSPSettings == NULL)
78
{
79
return 0;
80
}
81
82
if (pEmitter->ChannelCount > 1 && pEmitter->pChannelAzimuths == NULL)
83
{
84
pEmitter->ChannelRadius = 1.0f;
85
86
if (pEmitter->ChannelCount == 2)
87
{
88
pEmitter->pChannelAzimuths = (float*) &aStereoLayout[0];
89
}
90
else if (pEmitter->ChannelCount == 3)
91
{
92
pEmitter->pChannelAzimuths = (float*) &a2Point1Layout[0];
93
}
94
else if (pEmitter->ChannelCount == 4)
95
{
96
pEmitter->pChannelAzimuths = (float*) &aQuadLayout[0];
97
}
98
else if (pEmitter->ChannelCount == 5)
99
{
100
pEmitter->pChannelAzimuths = (float*) &a4Point1Layout[0];
101
}
102
else if (pEmitter->ChannelCount == 6)
103
{
104
pEmitter->pChannelAzimuths = (float*) &a5Point1Layout[0];
105
}
106
else if (pEmitter->ChannelCount == 8)
107
{
108
pEmitter->pChannelAzimuths = (float*) &a7Point1Layout[0];
109
}
110
else
111
{
112
return 0;
113
}
114
}
115
116
if (pEmitter->pVolumeCurve == NULL)
117
{
118
pEmitter->pVolumeCurve = &DefaultCurve;
119
}
120
if (pEmitter->pLFECurve == NULL)
121
{
122
pEmitter->pLFECurve = &DefaultCurve;
123
}
124
125
F3DAudioCalculate(
126
F3DInstance,
127
pListener,
128
pEmitter,
129
(
130
F3DAUDIO_CALCULATE_MATRIX |
131
F3DAUDIO_CALCULATE_DOPPLER |
132
F3DAUDIO_CALCULATE_EMITTER_ANGLE
133
),
134
pDSPSettings
135
);
136
return 0;
137
}
138
139
uint32_t FACT3DApply(
140
F3DAUDIO_DSP_SETTINGS *pDSPSettings,
141
FACTCue *pCue
142
) {
143
if (pDSPSettings == NULL || pCue == NULL)
144
{
145
return 0;
146
}
147
148
FACTCue_SetMatrixCoefficients(
149
pCue,
150
pDSPSettings->SrcChannelCount,
151
pDSPSettings->DstChannelCount,
152
pDSPSettings->pMatrixCoefficients
153
);
154
FACTCue_SetVariable(
155
pCue,
156
FACTCue_GetVariableIndex(pCue, "Distance"),
157
pDSPSettings->EmitterToListenerDistance
158
);
159
FACTCue_SetVariable(
160
pCue,
161
FACTCue_GetVariableIndex(pCue, "DopplerPitchScalar"),
162
pDSPSettings->DopplerFactor
163
);
164
FACTCue_SetVariable(
165
pCue,
166
FACTCue_GetVariableIndex(pCue, "OrientationAngle"),
167
pDSPSettings->EmitterToListenerAngle * (180.0f / F3DAUDIO_PI)
168
);
169
return 0;
170
}
171
172
/* vim: set noexpandtab shiftwidth=8 tabstop=8: */
173
174