faudio: Import upstream release 22.06.
[wine.git] / libs / faudio / src / FACT3D.c
blob0fd7d8e72afc94e2ac35a24031f7dec211e56966
1 /* FAudio - XAudio Reimplementation for FNA
3 * Copyright (c) 2011-2022 Ethan Lee, Luigi Auriemma, and the MonoGame Team
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.
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:
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.
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source distribution.
23 * Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
27 #include "FACT3D.h"
29 uint32_t FACT3DInitialize(
30 FACTAudioEngine *pEngine,
31 F3DAUDIO_HANDLE F3DInstance
32 ) {
33 float nSpeedOfSound;
34 FAudioWaveFormatExtensible wfxFinalMixFormat;
36 if (pEngine == NULL)
38 return 0;
41 FACTAudioEngine_GetGlobalVariable(
42 pEngine,
43 FACTAudioEngine_GetGlobalVariableIndex(
44 pEngine,
45 "SpeedOfSound"
47 &nSpeedOfSound
49 FACTAudioEngine_GetFinalMixFormat(
50 pEngine,
51 &wfxFinalMixFormat
53 F3DAudioInitialize(
54 wfxFinalMixFormat.dwChannelMask,
55 nSpeedOfSound,
56 F3DInstance
58 return 0;
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] =
69 { 0.0f, 1.0f },
70 { 1.0f, 1.0f }
72 static F3DAUDIO_DISTANCE_CURVE DefaultCurve =
74 (F3DAUDIO_DISTANCE_CURVE_POINT*) &DefaultCurvePoints[0], 2
77 if (pListener == NULL || pEmitter == NULL || pDSPSettings == NULL)
79 return 0;
82 if (pEmitter->ChannelCount > 1 && pEmitter->pChannelAzimuths == NULL)
84 pEmitter->ChannelRadius = 1.0f;
86 if (pEmitter->ChannelCount == 2)
88 pEmitter->pChannelAzimuths = (float*) &aStereoLayout[0];
90 else if (pEmitter->ChannelCount == 3)
92 pEmitter->pChannelAzimuths = (float*) &a2Point1Layout[0];
94 else if (pEmitter->ChannelCount == 4)
96 pEmitter->pChannelAzimuths = (float*) &aQuadLayout[0];
98 else if (pEmitter->ChannelCount == 5)
100 pEmitter->pChannelAzimuths = (float*) &a4Point1Layout[0];
102 else if (pEmitter->ChannelCount == 6)
104 pEmitter->pChannelAzimuths = (float*) &a5Point1Layout[0];
106 else if (pEmitter->ChannelCount == 8)
108 pEmitter->pChannelAzimuths = (float*) &a7Point1Layout[0];
110 else
112 return 0;
116 if (pEmitter->pVolumeCurve == NULL)
118 pEmitter->pVolumeCurve = &DefaultCurve;
120 if (pEmitter->pLFECurve == NULL)
122 pEmitter->pLFECurve = &DefaultCurve;
125 F3DAudioCalculate(
126 F3DInstance,
127 pListener,
128 pEmitter,
130 F3DAUDIO_CALCULATE_MATRIX |
131 F3DAUDIO_CALCULATE_DOPPLER |
132 F3DAUDIO_CALCULATE_EMITTER_ANGLE
134 pDSPSettings
136 return 0;
139 uint32_t FACT3DApply(
140 F3DAUDIO_DSP_SETTINGS *pDSPSettings,
141 FACTCue *pCue
143 if (pDSPSettings == NULL || pCue == NULL)
145 return 0;
148 FACTCue_SetMatrixCoefficients(
149 pCue,
150 pDSPSettings->SrcChannelCount,
151 pDSPSettings->DstChannelCount,
152 pDSPSettings->pMatrixCoefficients
154 FACTCue_SetVariable(
155 pCue,
156 FACTCue_GetVariableIndex(pCue, "Distance"),
157 pDSPSettings->EmitterToListenerDistance
159 FACTCue_SetVariable(
160 pCue,
161 FACTCue_GetVariableIndex(pCue, "DopplerPitchScalar"),
162 pDSPSettings->DopplerFactor
164 FACTCue_SetVariable(
165 pCue,
166 FACTCue_GetVariableIndex(pCue, "OrientationAngle"),
167 pDSPSettings->EmitterToListenerAngle * (180.0f / F3DAUDIO_PI)
169 return 0;
172 /* vim: set noexpandtab shiftwidth=8 tabstop=8: */