add clang formatting

main
cosmonaut 2021-11-08 16:15:12 -08:00 committed by Beau Blyth
parent 2fd95ea452
commit 4d834b3567
3 changed files with 767 additions and 440 deletions

166
.clang-format Normal file
View File

@ -0,0 +1,166 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: NoIndent
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000000
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

View File

@ -30,9 +30,9 @@
#include "FAudioGMS.h" #include "FAudioGMS.h"
#include "F3DAudio.h"
#include "FAPOBase.h" #include "FAPOBase.h"
#include "FAudioFX.h" #include "FAudioFX.h"
#include "F3DAudio.h"
#include "FAudio.h" #include "FAudio.h"
@ -217,7 +217,8 @@ struct FAudioGMS_SoundInstance
union union
{ {
FAudioGMS_StaticSound *staticSound; /* static sounds are loaded separately, so they do not belong to the instance */ FAudioGMS_StaticSound *staticSound; /* static sounds are loaded separately, so they do
not belong to the instance */
FAudioGMS_StreamingSound streamingSound; FAudioGMS_StreamingSound streamingSound;
} soundData; } soundData;
}; };
@ -275,8 +276,13 @@ typedef struct FAudioGMS_Device
static FAudioGMS_Device *device = NULL; static FAudioGMS_Device *device = NULL;
/* Game Maker doesn't let us control execution order on clean up so we have this stupid macro to help us not crash on exit */ /* Game Maker doesn't let us control execution order on clean up so we have this
#define RETURN_ON_NULL_DEVICE(x) if (device == NULL) { return x; } * stupid macro to help us not crash on exit */
#define RETURN_ON_NULL_DEVICE(x) \
if (device == NULL) \
{ \
return x; \
}
static inline FAudioGMS_StaticSound *FAudioGMS_INTERNAL_LookupStaticSound(uint32_t id) static inline FAudioGMS_StaticSound *FAudioGMS_INTERNAL_LookupStaticSound(uint32_t id)
{ {
@ -323,7 +329,9 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance*
static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance); static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance);
static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance *instance); static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance *instance);
static void FAudioGMS_INTERNAL_OnBufferEndCallback(FAudioVoiceCallback* callback, FAudioGMS_SoundInstance *instance) static void FAudioGMS_INTERNAL_OnBufferEndCallback(
FAudioVoiceCallback *callback,
FAudioGMS_SoundInstance *instance)
{ {
if (instance->isStatic) if (instance->isStatic)
{ {
@ -384,10 +392,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep)
uint32_t i = 0; uint32_t i = 0;
for (i = 0; i < deviceCount; i += 1) for (i = 0; i < deviceCount; i += 1)
{ {
FAudio_GetDeviceDetails( FAudio_GetDeviceDetails(device->handle, i, &deviceDetails);
device->handle,
i,
&deviceDetails);
if ((deviceDetails.Role & FAudioDefaultGameDevice) == FAudioDefaultGameDevice) if ((deviceDetails.Role & FAudioDefaultGameDevice) == FAudioDefaultGameDevice)
{ {
@ -399,10 +404,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep)
if (i == deviceCount) if (i == deviceCount)
{ {
i = 0; /* whatever we'll just use the first one i guess */ i = 0; /* whatever we'll just use the first one i guess */
FAudio_GetDeviceDetails( FAudio_GetDeviceDetails(device->handle, i, &deviceDetails);
device->handle,
i,
&deviceDetails);
device->deviceDetails = deviceDetails; device->deviceDetails = deviceDetails;
} }
@ -414,8 +416,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep)
FAUDIO_DEFAULT_SAMPLERATE, FAUDIO_DEFAULT_SAMPLERATE,
0, 0,
i, i,
NULL NULL) != 0)
) != 0)
{ {
Log("No mastering voice found! Bailing!"); Log("No mastering voice found! Bailing!");
FAudio_Release(device->handle); FAudio_Release(device->handle);
@ -437,8 +438,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep)
0, 0,
0, 0,
&device->fauxMasteringVoice.sends, &device->fauxMasteringVoice.sends,
NULL NULL) != 0)
) != 0)
{ {
Log("Failed to create faux mastering voice! Bailing!"); Log("Failed to create faux mastering voice! Bailing!");
FAudioVoice_DestroyVoice(device->masteringVoice); FAudioVoice_DestroyVoice(device->masteringVoice);
@ -459,8 +459,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep)
F3DAudioInitialize( F3DAudioInitialize(
device->deviceDetails.OutputFormat.dwChannelMask, device->deviceDetails.OutputFormat.dwChannelMask,
SPEED_OF_SOUND, SPEED_OF_SOUND,
device->handle3D device->handle3D);
);
device->listener.OrientFront.x = 0; device->listener.OrientFront.x = 0;
device->listener.OrientFront.y = 0; device->listener.OrientFront.y = 0;
@ -503,7 +502,9 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep)
fflush(stdout); fflush(stdout);
} }
/* Taken from https://github.com/FNA-XNA/FNA/blob/master/src/Audio/SoundEffectInstance.cs */ /* Taken from
* https://github.com/FNA-XNA/FNA/blob/master/src/Audio/SoundEffectInstance.cs
*/
static void SetPanMatrixCoefficients(FAudioGMS_SoundInstance *instance) static void SetPanMatrixCoefficients(FAudioGMS_SoundInstance *instance)
{ {
/* Two major things to notice: /* Two major things to notice:
@ -564,7 +565,12 @@ double FAudioGMS_StaticSound_LoadWAV(char *filePath)
drwav_uint64 frameCount; drwav_uint64 frameCount;
FAudioGMS_StaticSound *sound = SDL_malloc(sizeof(FAudioGMS_StaticSound)); FAudioGMS_StaticSound *sound = SDL_malloc(sizeof(FAudioGMS_StaticSound));
float *pSampleData = drwav_open_file_and_read_pcm_frames_f32(filePath, &sound->channels, &sound->samplesPerSecond, &frameCount, NULL); float *pSampleData = drwav_open_file_and_read_pcm_frames_f32(
filePath,
&sound->channels,
&sound->samplesPerSecond,
&frameCount,
NULL);
if (pSampleData == NULL) if (pSampleData == NULL)
{ {
Log("Error opening WAV file: "); Log("Error opening WAV file: ");
@ -593,7 +599,9 @@ double FAudioGMS_StaticSound_LoadWAV(char *filePath)
{ {
sound->id = device->staticSoundCount; sound->id = device->staticSoundCount;
device->staticSounds = SDL_realloc(device->staticSounds, (device->staticSoundCount + 1) * sizeof(FAudioGMS_StaticSound*)); device->staticSounds = SDL_realloc(
device->staticSounds,
(device->staticSoundCount + 1) * sizeof(FAudioGMS_StaticSound *));
device->staticSoundCount += 1; device->staticSoundCount += 1;
} }
@ -614,8 +622,7 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetPan(FAudioGMS_SoundInstance* ins
instance->dspSettings.SrcChannelCount, instance->dspSettings.SrcChannelCount,
instance->dspSettings.DstChannelCount, instance->dspSettings.DstChannelCount,
instance->dspSettings.pMatrixCoefficients, instance->dspSettings.pMatrixCoefficients,
0 0);
);
} }
static void FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(FAudioGMS_SoundInstance *instance) static void FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(FAudioGMS_SoundInstance *instance)
@ -633,19 +640,25 @@ static void FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(FAudioGMS_SoundInstance
FAudioSourceVoice_SetFrequencyRatio( FAudioSourceVoice_SetFrequencyRatio(
instance->voice.handle, instance->voice.handle,
SDL_powf(2.0f, instance->pitch - 1) * doppler, /* FAudio expects pitch range to be -1.0 to 1.0 while GM uses 0.0 to 2.0 so we adjust here */ SDL_powf(2.0f, instance->pitch - 1) *
0 doppler, /* FAudio expects pitch range to be -1.0 to 1.0 while GM
); uses 0.0 to 2.0 so
we adjust here */
0);
} }
static void FAudioGMS_INTERNAL_SoundInstance_SetPitch(FAudioGMS_SoundInstance* instance, float pitch) static void FAudioGMS_INTERNAL_SoundInstance_SetPitch(
FAudioGMS_SoundInstance *instance,
float pitch)
{ {
pitch = SDL_max(0.0, SDL_min(2.0, pitch)); pitch = SDL_max(0.0, SDL_min(2.0, pitch));
instance->pitch = pitch; instance->pitch = pitch;
FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(instance); FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(instance);
} }
static void FAudioGMS_INTERNAL_SoundInstance_SetVolume(FAudioGMS_SoundInstance* instance, float volume) static void FAudioGMS_INTERNAL_SoundInstance_SetVolume(
FAudioGMS_SoundInstance *instance,
float volume)
{ {
instance->volume = volume; instance->volume = volume;
FAudioVoice_SetVolume(instance->voice.handle, volume, 0); FAudioVoice_SetVolume(instance->voice.handle, volume, 0);
@ -654,8 +667,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetVolume(FAudioGMS_SoundInstance*
static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_Init( static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_Init(
uint32_t channelCount, uint32_t channelCount,
uint32_t samplesPerSecond, uint32_t samplesPerSecond,
uint8_t isStatic uint8_t isStatic)
) { {
FAudioGMS_SoundInstance *instance = SDL_malloc(sizeof(FAudioGMS_SoundInstance)); FAudioGMS_SoundInstance *instance = SDL_malloc(sizeof(FAudioGMS_SoundInstance));
instance->voice.handle = NULL; instance->voice.handle = NULL;
@ -698,7 +711,8 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init(
instance->dspSettings.SrcChannelCount = channelCount; instance->dspSettings.SrcChannelCount = channelCount;
instance->dspSettings.DstChannelCount = device->deviceDetails.OutputFormat.Format.nChannels; instance->dspSettings.DstChannelCount = device->deviceDetails.OutputFormat.Format.nChannels;
uint32_t memsize = 4 * instance->dspSettings.SrcChannelCount * instance->dspSettings.DstChannelCount; uint32_t memsize =
4 * instance->dspSettings.SrcChannelCount * instance->dspSettings.DstChannelCount;
instance->dspSettings.pMatrixCoefficients = SDL_malloc(memsize); instance->dspSettings.pMatrixCoefficients = SDL_malloc(memsize);
SDL_memset(instance->dspSettings.pMatrixCoefficients, 0, memsize); SDL_memset(instance->dspSettings.pMatrixCoefficients, 0, memsize);
@ -738,7 +752,9 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init(
{ {
instance->id = device->soundInstanceCount; instance->id = device->soundInstanceCount;
device->soundInstances = SDL_realloc(device->soundInstances, (device->soundInstanceCount + 1) * sizeof(FAudioGMS_SoundInstance*)); device->soundInstances = SDL_realloc(
device->soundInstances,
(device->soundInstanceCount + 1) * sizeof(FAudioGMS_SoundInstance *));
device->soundInstanceCount += 1; device->soundInstanceCount += 1;
} }
@ -748,13 +764,12 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init(
} }
static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound( static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound(
FAudioGMS_StaticSound* staticSound FAudioGMS_StaticSound *staticSound)
) { {
FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_SoundInstance_Init( FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_SoundInstance_Init(
staticSound->channels, staticSound->channels,
staticSound->samplesPerSecond, staticSound->samplesPerSecond,
1 1);
);
instance->isStatic = 1; instance->isStatic = 1;
instance->soundData.staticSound = staticSound; instance->soundData.staticSound = staticSound;
@ -765,11 +780,13 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_CreateFromStati
double FAudioGMS_StaticSound_CreateSoundInstance(double staticSoundID) double FAudioGMS_StaticSound_CreateSoundInstance(double staticSoundID)
{ {
RETURN_ON_NULL_DEVICE(-1.0) RETURN_ON_NULL_DEVICE(-1.0)
FAudioGMS_StaticSound* staticSound = FAudioGMS_INTERNAL_LookupStaticSound((uint32_t)staticSoundID); FAudioGMS_StaticSound *staticSound =
FAudioGMS_INTERNAL_LookupStaticSound((uint32_t)staticSoundID);
if (staticSound != NULL) if (staticSound != NULL)
{ {
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound(staticSound); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound(staticSound);
return instance->id; return instance->id;
} }
else else
@ -779,7 +796,10 @@ double FAudioGMS_StaticSound_CreateSoundInstance(double staticSoundID)
} }
} }
static void FAudioGMS_INTERNAL_SoundInstance_SetLowPassFilter(FAudioGMS_SoundInstance* instance, float lowPassFilter, float Q) static void FAudioGMS_INTERNAL_SoundInstance_SetLowPassFilter(
FAudioGMS_SoundInstance *instance,
float lowPassFilter,
float Q)
{ {
FAudioFilterParameters p; FAudioFilterParameters p;
p.Type = FAudioLowPassFilter; p.Type = FAudioLowPassFilter;
@ -791,9 +811,13 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetLowPassFilter(FAudioGMS_SoundIns
instance->lowPassFilter = lowPassFilter; instance->lowPassFilter = lowPassFilter;
} }
void FAudioGMS_SoundInstance_SetLowPassFilter(double soundInstanceID, double lowPassFilter, double Q) void FAudioGMS_SoundInstance_SetLowPassFilter(
double soundInstanceID,
double lowPassFilter,
double Q)
{ {
FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -801,7 +825,10 @@ void FAudioGMS_SoundInstance_SetLowPassFilter(double soundInstanceID, double low
} }
} }
static void FAudioGMS_INTERNAL_SoundInstance_SetHighPassFilter(FAudioGMS_SoundInstance* instance, float highPassFilter, float Q) static void FAudioGMS_INTERNAL_SoundInstance_SetHighPassFilter(
FAudioGMS_SoundInstance *instance,
float highPassFilter,
float Q)
{ {
FAudioFilterParameters p; FAudioFilterParameters p;
p.Type = FAudioHighPassFilter; p.Type = FAudioHighPassFilter;
@ -813,9 +840,13 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetHighPassFilter(FAudioGMS_SoundIn
instance->highPassFilter = highPassFilter; instance->highPassFilter = highPassFilter;
} }
void FAudioGMS_SoundInstance_SetHighPassFilter(double soundInstanceID, double highPassFilter, double Q) void FAudioGMS_SoundInstance_SetHighPassFilter(
double soundInstanceID,
double highPassFilter,
double Q)
{ {
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -823,7 +854,10 @@ void FAudioGMS_SoundInstance_SetHighPassFilter(double soundInstanceID, double hi
} }
} }
static void FAudioGMS_INTERNAL_SoundInstance_SetBandPassFilter(FAudioGMS_SoundInstance* instance, float bandPassFilter, float Q) static void FAudioGMS_INTERNAL_SoundInstance_SetBandPassFilter(
FAudioGMS_SoundInstance *instance,
float bandPassFilter,
float Q)
{ {
FAudioFilterParameters p; FAudioFilterParameters p;
p.Type = FAudioBandPassFilter; p.Type = FAudioBandPassFilter;
@ -835,9 +869,13 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetBandPassFilter(FAudioGMS_SoundIn
instance->bandPassFilter = bandPassFilter; instance->bandPassFilter = bandPassFilter;
} }
void FAudioGMS_SoundInstance_SetBandPassFilter(double soundInstanceID, double bandPassFilter, double Q) void FAudioGMS_SoundInstance_SetBandPassFilter(
double soundInstanceID,
double bandPassFilter,
double Q)
{ {
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -847,8 +885,10 @@ void FAudioGMS_SoundInstance_SetBandPassFilter(double soundInstanceID, double ba
void FAudioGMS_SoundInstance_QueueSoundInstance(double soundInstanceID, double queueSoundInstanceID) void FAudioGMS_SoundInstance_QueueSoundInstance(double soundInstanceID, double queueSoundInstanceID)
{ {
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_SoundInstance* queueInstance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)queueSoundInstanceID); FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
FAudioGMS_SoundInstance *queueInstance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)queueSoundInstanceID);
if (instance != NULL && queueInstance != NULL) if (instance != NULL && queueInstance != NULL)
{ {
@ -873,7 +913,8 @@ static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance* instance)
if (emitter == NULL) if (emitter == NULL)
{ {
Log("Sound instance does not have 3D data! Did you forget to initialize?"); Log("Sound instance does not have 3D data! Did you forget to "
"initialize?");
return; return;
} }
@ -882,8 +923,7 @@ static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance* instance)
&device->listener, &device->listener,
emitter, emitter,
F3DAUDIO_CALCULATE_MATRIX | F3DAUDIO_CALCULATE_DOPPLER, F3DAUDIO_CALCULATE_MATRIX | F3DAUDIO_CALCULATE_DOPPLER,
&instance->dspSettings &instance->dspSettings);
);
FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(instance); FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(instance);
FAudioVoice_SetOutputMatrix( FAudioVoice_SetOutputMatrix(
@ -892,8 +932,7 @@ static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance* instance)
instance->dspSettings.SrcChannelCount, instance->dspSettings.SrcChannelCount,
instance->dspSettings.DstChannelCount, instance->dspSettings.DstChannelCount,
instance->dspSettings.pMatrixCoefficients, instance->dspSettings.pMatrixCoefficients,
0 0);
);
} }
static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance *instance) static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance *instance)
@ -903,26 +942,30 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance*
if (instance->playLength != 0) if (instance->playLength != 0)
{ {
uint32_t distanceToEndPoint = (instance->playBegin + instance->playLength) - stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle); uint32_t distanceToEndPoint =
(instance->playBegin + instance->playLength) -
stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle);
requestedSampleCount = SDL_min(requestedSampleCount, distanceToEndPoint); requestedSampleCount = SDL_min(requestedSampleCount, distanceToEndPoint);
} }
uint32_t requiredStagingBufferSize = requestedSampleCount * instance->format.nChannels * sizeof(float); uint32_t requiredStagingBufferSize =
requestedSampleCount * instance->format.nChannels * sizeof(float);
if (instance->soundData.streamingSound.streamBufferSize < requiredStagingBufferSize) if (instance->soundData.streamingSound.streamBufferSize < requiredStagingBufferSize)
{ {
instance->soundData.streamingSound.streamBuffer = SDL_realloc(instance->soundData.streamingSound.streamBuffer, requiredStagingBufferSize); instance->soundData.streamingSound.streamBuffer =
SDL_realloc(instance->soundData.streamingSound.streamBuffer, requiredStagingBufferSize);
instance->soundData.streamingSound.streamBufferSize = requiredStagingBufferSize; instance->soundData.streamingSound.streamBufferSize = requiredStagingBufferSize;
} }
instance->soundData.streamingSound.mostRecentBufferOffset = stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle); instance->soundData.streamingSound.mostRecentBufferOffset =
stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle);
/* NOTE: this function returns samples per channel, not total samples */ /* NOTE: this function returns samples per channel, not total samples */
uint32_t sampleCount = stb_vorbis_get_samples_float_interleaved( uint32_t sampleCount = stb_vorbis_get_samples_float_interleaved(
instance->soundData.streamingSound.fileHandle, instance->soundData.streamingSound.fileHandle,
instance->format.nChannels, instance->format.nChannels,
instance->soundData.streamingSound.streamBuffer, instance->soundData.streamingSound.streamBuffer,
requestedSampleCount * instance->format.nChannels requestedSampleCount * instance->format.nChannels);
);
FAudioBuffer buffer; FAudioBuffer buffer;
buffer.AudioBytes = sampleCount * instance->format.nChannels * sizeof(float); buffer.AudioBytes = sampleCount * instance->format.nChannels * sizeof(float);
@ -968,11 +1011,8 @@ double FAudioGMS_StreamingSound_LoadOGG(char* filePath)
stb_vorbis_info info = stb_vorbis_get_info(fileHandle); stb_vorbis_info info = stb_vorbis_get_info(fileHandle);
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_SoundInstance_Init( FAudioGMS_SoundInstance *instance =
info.channels, FAudioGMS_INTERNAL_SoundInstance_Init(info.channels, info.sample_rate, 0);
info.sample_rate,
0
);
instance->soundData.streamingSound.fileHandle = fileHandle; instance->soundData.streamingSound.fileHandle = fileHandle;
instance->soundData.streamingSound.info = info; instance->soundData.streamingSound.info = info;
@ -986,7 +1026,11 @@ double FAudioGMS_StreamingSound_LoadOGG(char* filePath)
return instance->id; return instance->id;
} }
static void FAudioGMS_INTERNAL_SoundInstance_AddEmitter(FAudioGMS_SoundInstance* instance, float x, float y, float z) static void FAudioGMS_INTERNAL_SoundInstance_AddEmitter(
FAudioGMS_SoundInstance *instance,
float x,
float y,
float z)
{ {
instance->is3D = 1; instance->is3D = 1;
@ -1055,7 +1099,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* insta
{ {
FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle); FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle);
instance->soundData.staticSound->buffer.PlayBegin = instance->voice.handle->src.curBufferOffset; instance->soundData.staticSound->buffer.PlayBegin =
instance->voice.handle->src.curBufferOffset;
instance->soundData.staticSound->buffer.PlayLength = instance->playLength; instance->soundData.staticSound->buffer.PlayLength = instance->playLength;
} }
else else
@ -1064,7 +1109,10 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* insta
instance->soundData.staticSound->buffer.PlayLength = instance->playLength; instance->soundData.staticSound->buffer.PlayLength = instance->playLength;
} }
FAudioSourceVoice_SubmitSourceBuffer(instance->voice.handle, &instance->soundData.staticSound->buffer, NULL); FAudioSourceVoice_SubmitSourceBuffer(
instance->voice.handle,
&instance->soundData.staticSound->buffer,
NULL);
} }
FAudioSourceVoice_Start(instance->voice.handle, 0, 0); FAudioSourceVoice_Start(instance->voice.handle, 0, 0);
@ -1074,7 +1122,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* insta
void FAudioGMS_SoundInstance_Play(double soundInstanceID) void FAudioGMS_SoundInstance_Play(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1088,20 +1137,25 @@ static void FAudioGMS_INTERNAL_SoundInstance_Pause(FAudioGMS_SoundInstance* inst
{ {
if (instance->soundState == SoundState_Playing) if (instance->soundState == SoundState_Playing)
{ {
FAudioSourceVoice_Stop(instance->voice.handle, 0, 0); /* this actually just pauses lol */ FAudioSourceVoice_Stop(
instance->voice.handle,
0,
0); /* this actually just pauses lol */
instance->soundState = SoundState_Paused; instance->soundState = SoundState_Paused;
} }
} }
else else
{ {
Log("SoundInstance_Pause: Invalid sound instance ID! Did you destroy this instance?"); Log("SoundInstance_Pause: Invalid sound instance ID! Did you destroy "
"this instance?");
} }
} }
void FAudioGMS_SoundInstance_Pause(double soundInstanceID) void FAudioGMS_SoundInstance_Pause(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
FAudioGMS_INTERNAL_SoundInstance_Pause(instance); FAudioGMS_INTERNAL_SoundInstance_Pause(instance);
} }
@ -1109,34 +1163,43 @@ static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance* insta
{ {
if (instance != NULL) if (instance != NULL)
{ {
instance->soundState = SoundState_Stopped; /* set this before so flush buffers doesn't trigger buffer add callback */ instance->soundState =
SoundState_Stopped; /* set this before so flush
buffers
doesn't trigger buffer add callback */
FAudioSourceVoice_Stop(instance->voice.handle, 0, 0); FAudioSourceVoice_Stop(instance->voice.handle, 0, 0);
FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle); FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle);
if (!instance->isStatic) if (!instance->isStatic)
{ {
stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin); /* back to the start */ stb_vorbis_seek(
FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); /* preload so we dont stutter on play */ instance->soundData.streamingSound.fileHandle,
instance->playBegin); /* back to the start */
FAudioGMS_INTERNAL_SoundInstance_AddBuffer(
instance); /* preload so we dont stutter on play */
} }
} }
else else
{ {
Log("SoundInstance_Stop: Invalid sound instance ID! Did you destroy this instance?"); Log("SoundInstance_Stop: Invalid sound instance ID! Did you destroy "
"this instance?");
} }
} }
void FAudioGMS_SoundInstance_Stop(double soundInstanceID) void FAudioGMS_SoundInstance_Stop(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
FAudioGMS_INTERNAL_SoundInstance_Stop(instance); FAudioGMS_INTERNAL_SoundInstance_Stop(instance);
} }
void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop) void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1144,7 +1207,8 @@ void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop)
if (instance->isStatic && instance->soundState == SoundState_Playing) if (instance->isStatic && instance->soundState == SoundState_Playing)
{ {
/* We need to pause and play so that static buffers get resubmitted */ /* We need to pause and play so that static buffers get resubmitted
*/
FAudioGMS_INTERNAL_SoundInstance_Pause(instance); FAudioGMS_INTERNAL_SoundInstance_Pause(instance);
FAudioGMS_INTERNAL_SoundInstance_Play(instance); FAudioGMS_INTERNAL_SoundInstance_Play(instance);
} }
@ -1154,7 +1218,8 @@ void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop)
void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan) void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL && !instance->is3D) if (instance != NULL && !instance->is3D)
{ {
@ -1165,7 +1230,8 @@ void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan)
void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch) void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1176,7 +1242,8 @@ void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch)
void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume) void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1188,7 +1255,8 @@ void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume)
void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z) void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1207,10 +1275,15 @@ void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, dou
} }
} }
void FAudioGMS_SoundInstance_Set3DVelocity(double soundInstanceID, double xVelocity, double yVelocity, double zVelocity) void FAudioGMS_SoundInstance_Set3DVelocity(
double soundInstanceID,
double xVelocity,
double yVelocity,
double zVelocity)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1227,14 +1300,18 @@ void FAudioGMS_SoundInstance_Set3DVelocity(double soundInstanceID, double xVeloc
} }
/* FIXME: this will die horribly if position is greater than total length */ /* FIXME: this will die horribly if position is greater than total length */
void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, double trackPositionInSeconds) void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(
double soundInstanceID,
double trackPositionInSeconds)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
uint32_t sampleFrame = instance->soundData.staticSound->samplesPerSecond * trackPositionInSeconds; uint32_t sampleFrame =
instance->soundData.staticSound->samplesPerSecond * trackPositionInSeconds;
FAudioGMS_SoundState currentState = instance->soundState; FAudioGMS_SoundState currentState = instance->soundState;
if (currentState == SoundState_Playing) if (currentState == SoundState_Playing)
@ -1260,7 +1337,8 @@ void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, d
} }
} }
static uint32_t FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(FAudioGMS_SoundInstance* instance) static uint32_t FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(
FAudioGMS_SoundInstance *instance)
{ {
if (instance != NULL) if (instance != NULL)
{ {
@ -1270,7 +1348,8 @@ static uint32_t FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(
} }
else else
{ {
return instance->soundData.streamingSound.mostRecentBufferOffset + instance->voice.handle->src.curBufferOffset; return instance->soundData.streamingSound.mostRecentBufferOffset +
instance->voice.handle->src.curBufferOffset;
} }
} }
@ -1278,14 +1357,19 @@ static uint32_t FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(
return 0; return 0;
} }
void FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startInMilliseconds, double endInMilliseconds) void FAudioGMS_SoundInstance_SetPlayRegion(
double soundInstanceID,
double startInMilliseconds,
double endInMilliseconds)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
uint32_t playBeginSampleFrame = instance->format.nSamplesPerSec * (startInMilliseconds / 1000); uint32_t playBeginSampleFrame =
instance->format.nSamplesPerSec * (startInMilliseconds / 1000);
uint32_t playEndSampleFrame = instance->format.nSamplesPerSec * (endInMilliseconds / 1000); uint32_t playEndSampleFrame = instance->format.nSamplesPerSec * (endInMilliseconds / 1000);
uint32_t playLength = playEndSampleFrame - playBeginSampleFrame; uint32_t playLength = playEndSampleFrame - playBeginSampleFrame;
@ -1298,12 +1382,12 @@ void FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startI
instance->playBegin = playBeginSampleFrame; instance->playBegin = playBeginSampleFrame;
instance->playLength = playLength; instance->playLength = playLength;
uint32_t currentFrame = FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance); uint32_t currentFrame =
FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance);
if ( if (currentFrame < instance->playBegin ||
currentFrame < instance->playBegin || (currentFrame > instance->playBegin + instance->playLength))
(currentFrame > instance->playBegin + instance->playLength) {
) {
/* we are outside the play region */ /* we are outside the play region */
if (instance->isStatic && instance->soundState == SoundState_Playing) if (instance->isStatic && instance->soundState == SoundState_Playing)
{ {
@ -1329,23 +1413,29 @@ void FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startI
} }
} }
void FAudioGMS_SoundInstance_SetVolumeOverTime(double soundInstanceID, double volume, double milliseconds) void FAudioGMS_SoundInstance_SetVolumeOverTime(
double soundInstanceID,
double volume,
double milliseconds)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);\ FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
instance->adjustingVolumeOverTime = 1; instance->adjustingVolumeOverTime = 1;
instance->targetVolume = volume; instance->targetVolume = volume;
instance->volumeDelta = (volume - instance->volume) / ((milliseconds / 1000) / device->timestep); instance->volumeDelta =
(volume - instance->volume) / ((milliseconds / 1000) / device->timestep);
} }
} }
double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID) double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE(-1.0) RETURN_ON_NULL_DEVICE(-1.0)
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1361,7 +1451,8 @@ double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID)
double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID) double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE(-1.0) RETURN_ON_NULL_DEVICE(-1.0)
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1377,7 +1468,8 @@ double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID)
double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID) double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE(-1.0) RETURN_ON_NULL_DEVICE(-1.0)
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1387,7 +1479,8 @@ double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID)
} }
else else
{ {
return stb_vorbis_stream_length_in_seconds(instance->soundData.streamingSound.fileHandle); return stb_vorbis_stream_length_in_seconds(
instance->soundData.streamingSound.fileHandle);
} }
} }
else else
@ -1400,11 +1493,13 @@ double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID)
double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID) double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE(-1.0) RETURN_ON_NULL_DEVICE(-1.0)
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
return (double)FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance) / instance->format.nSamplesPerSec; return (double)FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance) /
instance->format.nSamplesPerSec;
} }
else else
{ {
@ -1463,7 +1558,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_Destroy(FAudioGMS_SoundInstance* in
void FAudioGMS_SoundInstance_Destroy(double soundInstanceID) void FAudioGMS_SoundInstance_Destroy(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1474,7 +1570,8 @@ void FAudioGMS_SoundInstance_Destroy(double soundInstanceID)
void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID) void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1518,7 +1615,9 @@ double FAudioGMS_EffectChain_Create()
{ {
effectChain->id = device->effectChainCount; effectChain->id = device->effectChainCount;
device->effectChains = SDL_realloc(device->effectChains, (device->effectChainCount + 1) * sizeof(FAudioGMS_EffectChain*)); device->effectChains = SDL_realloc(
device->effectChains,
(device->effectChainCount + 1) * sizeof(FAudioGMS_EffectChain *));
device->effectChainCount += 1; device->effectChainCount += 1;
} }
@ -1527,21 +1626,31 @@ double FAudioGMS_EffectChain_Create()
return effectChain->id; return effectChain->id;
} }
static void FAudioGMS_INTERNAL_EffectChain_AddReverb(FAudioGMS_EffectChain* effectChain, FAudioFXReverbParameters *reverbParameters) static void FAudioGMS_INTERNAL_EffectChain_AddReverb(
FAudioGMS_EffectChain *effectChain,
FAudioFXReverbParameters *reverbParameters)
{ {
effectChain->effectCount += 1; effectChain->effectCount += 1;
effectChain->effectTypes = SDL_realloc(effectChain->effectTypes, effectChain->effectCount * sizeof(FAudioGMS_EffectType)); effectChain->effectTypes = SDL_realloc(
effectChain->effectTypes,
effectChain->effectCount * sizeof(FAudioGMS_EffectType));
effectChain->effectTypes[effectChain->effectCount - 1] = EffectType_Reverb; effectChain->effectTypes[effectChain->effectCount - 1] = EffectType_Reverb;
effectChain->effectParameters = SDL_realloc(effectChain->effectParameters, effectChain->effectCount * sizeof(FAudioGMS_EffectParameters)); effectChain->effectParameters = SDL_realloc(
SDL_memcpy(&effectChain->effectParameters[effectChain->effectCount - 1], reverbParameters, sizeof(FAudioFXReverbParameters)); effectChain->effectParameters,
effectChain->effectCount * sizeof(FAudioGMS_EffectParameters));
SDL_memcpy(
&effectChain->effectParameters[effectChain->effectCount - 1],
reverbParameters,
sizeof(FAudioFXReverbParameters));
} }
void FAudioGMS_EffectChain_AddDefaultReverb(double effectChainID) void FAudioGMS_EffectChain_AddDefaultReverb(double effectChainID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_EffectChain *effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); FAudioGMS_EffectChain *effectChain =
FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID);
if (effectChain != NULL) if (effectChain != NULL)
{ {
@ -1590,10 +1699,11 @@ void FAudioGMS_EffectChain_AddReverb(
double reverbGain, double reverbGain,
double decayTime, double decayTime,
double density, double density,
double roomSize double roomSize)
) { {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_EffectChain* effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); FAudioGMS_EffectChain *effectChain =
FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID);
if (effectChain != NULL) if (effectChain != NULL)
{ {
@ -1655,7 +1765,8 @@ static void FAudioGMS_INTERNAL_Voice_SetEffectGain(FAudioGMS_Voice *voice, float
void FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effectGain) void FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effectGain)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL) if (instance != NULL)
{ {
@ -1663,13 +1774,15 @@ void FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effect
} }
} }
static FAudioEffectChain* FAudioGMS_INTERNAL_CreateFAudioEffectChain(FAudioGMS_EffectChain* effectChain) static FAudioEffectChain *FAudioGMS_INTERNAL_CreateFAudioEffectChain(
FAudioGMS_EffectChain *effectChain)
{ {
FAudioEffectChain *fAudioEffectChain = SDL_malloc(sizeof(FAudioEffectChain)); FAudioEffectChain *fAudioEffectChain = SDL_malloc(sizeof(FAudioEffectChain));
uint32_t i; uint32_t i;
fAudioEffectChain->EffectCount = effectChain->effectCount; fAudioEffectChain->EffectCount = effectChain->effectCount;
fAudioEffectChain->pEffectDescriptors = SDL_malloc(fAudioEffectChain->EffectCount * sizeof(FAudioEffectDescriptor)); fAudioEffectChain->pEffectDescriptors =
SDL_malloc(fAudioEffectChain->EffectCount * sizeof(FAudioEffectDescriptor));
FAPO *reverb; FAPO *reverb;
@ -1682,7 +1795,8 @@ static FAudioEffectChain* FAudioGMS_INTERNAL_CreateFAudioEffectChain(FAudioGMS_E
FAudioEffectDescriptor *reverbDescriptor = &fAudioEffectChain->pEffectDescriptors[i]; FAudioEffectDescriptor *reverbDescriptor = &fAudioEffectChain->pEffectDescriptors[i];
reverbDescriptor->InitialState = 1; reverbDescriptor->InitialState = 1;
reverbDescriptor->OutputChannels = device->deviceDetails.OutputFormat.Format.nChannels == 6 ? 6 : 1; reverbDescriptor->OutputChannels =
device->deviceDetails.OutputFormat.Format.nChannels == 6 ? 6 : 1;
reverbDescriptor->pEffect = reverb; reverbDescriptor->pEffect = reverb;
break; break;
@ -1695,7 +1809,10 @@ static FAudioEffectChain* FAudioGMS_INTERNAL_CreateFAudioEffectChain(FAudioGMS_E
return fAudioEffectChain; return fAudioEffectChain;
} }
static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_EffectChain* effectChain, float effectGain) static void FAudioGMS_INTERNAL_SetEffectChain(
FAudioGMS_Voice *voice,
FAudioGMS_EffectChain *effectChain,
float effectGain)
{ {
uint32_t i; uint32_t i;
@ -1754,15 +1871,11 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_
Log("Unknown effect type! Something is very wrong!"); Log("Unknown effect type! Something is very wrong!");
} }
FAudioVoice_SetEffectParameters( FAudioVoice_SetEffectParameters(voice->effectVoice, i, parameters, parametersSize, 0);
voice->effectVoice,
i,
parameters,
parametersSize,
0);
} }
/* Set the instance voice to go through both faux mastering and effect voice for wet/dry */ /* Set the instance voice to go through both faux mastering and effect voice
* for wet/dry */
voice->sends.pSends[0].Flags = 0; voice->sends.pSends[0].Flags = 0;
if (voice == &device->fauxMasteringVoice) if (voice == &device->fauxMasteringVoice)
{ {
@ -1777,9 +1890,7 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_
voice->effectChainAttached = 1; voice->effectChainAttached = 1;
FAudioVoice_SetOutputVoices( FAudioVoice_SetOutputVoices(voice->handle, &voice->sends);
voice->handle,
&voice->sends);
FAudioGMS_INTERNAL_Voice_SetEffectGain(voice, effectGain); FAudioGMS_INTERNAL_Voice_SetEffectGain(voice, effectGain);
@ -1792,11 +1903,16 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_
SDL_free(fAudioEffectChain); SDL_free(fAudioEffectChain);
} }
void FAudioGMS_SoundInstance_SetEffectChain(double soundInstanceID, double effectChainID, double effectGain) void FAudioGMS_SoundInstance_SetEffectChain(
double soundInstanceID,
double effectChainID,
double effectGain)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance *instance =
FAudioGMS_EffectChain *effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
FAudioGMS_EffectChain *effectChain =
FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID);
if (instance != NULL && effectChain != NULL) if (instance != NULL && effectChain != NULL)
{ {
@ -1807,7 +1923,8 @@ void FAudioGMS_SoundInstance_SetEffectChain(double soundInstanceID, double effec
void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain) void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_EffectChain* effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); FAudioGMS_EffectChain *effectChain =
FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID);
if (effectChain != NULL) if (effectChain != NULL)
{ {
@ -1840,7 +1957,8 @@ static void FAudioGMS_INTERNAL_EffectChain_Destroy(FAudioGMS_EffectChain *effect
void FAudioGMS_EffectChain_Destroy(double effectChainID) void FAudioGMS_EffectChain_Destroy(double effectChainID)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_EffectChain *effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); FAudioGMS_EffectChain *effectChain =
FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID);
if (effectChain != NULL) if (effectChain != NULL)
{ {
@ -1894,7 +2012,10 @@ void FAudioGMS_Update()
if (instance->destroyOnFinish) if (instance->destroyOnFinish)
{ {
FAudioVoiceState state; FAudioVoiceState state;
FAudioSourceVoice_GetState(instance->voice.handle, &state, FAUDIO_VOICE_NOSAMPLESPLAYED); FAudioSourceVoice_GetState(
instance->voice.handle,
&state,
FAUDIO_VOICE_NOSAMPLESPLAYED);
if (state.BuffersQueued == 0) if (state.BuffersQueued == 0)
{ {

View File

@ -36,35 +36,66 @@
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif /* __cplusplus */ #endif /* __cplusplus */
FAUDIOGMSAPI void FAudioGMS_Init(double spatialDistanceScale, double timestep); FAUDIOGMSAPI void FAudioGMS_Init(double spatialDistanceScale, double timestep);
FAUDIOGMSAPI double FAudioGMS_StaticSound_LoadWAV(char *filePath); /* returns a static sound ID */ FAUDIOGMSAPI double FAudioGMS_StaticSound_LoadWAV(
FAUDIOGMSAPI double FAudioGMS_StaticSound_CreateSoundInstance(double staticSoundID); /* returns a sound instance ID */ char *filePath); /* returns a static sound ID */
FAUDIOGMSAPI double FAudioGMS_StaticSound_CreateSoundInstance(
double staticSoundID); /* returns a sound instance ID */
FAUDIOGMSAPI void FAudioGMS_StaticSound_Destroy(double staticSoundID); FAUDIOGMSAPI void FAudioGMS_StaticSound_Destroy(double staticSoundID);
FAUDIOGMSAPI double FAudioGMS_StreamingSound_LoadOGG(char* filepath); /* returns a sound instance ID */ FAUDIOGMSAPI double FAudioGMS_StreamingSound_LoadOGG(
char *filepath); /* returns a sound instance ID */
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Play(double soundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Play(double soundInstanceID);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Pause(double soundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Pause(double soundInstanceID);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Stop(double soundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Stop(double soundInstanceID);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startInMilliseconds, double endInMilliseconds); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPlayRegion(
double soundInstanceID,
double startInMilliseconds,
double endInMilliseconds);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Set3DPosition(
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Set3DVelocity(double soundInstanceID, double xVelocity, double yVelocity, double zVelocity); double soundInstanceID,
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, double trackPositionInSeconds); double x,
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolumeOverTime(double soundInstanceID, double volume, double milliseconds); double y,
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLowPassFilter(double soundInstanceID, double lowPassFilter, double Q); double z);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetHighPassFilter(double soundInstanceID, double highPassFilter, double Q); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Set3DVelocity(
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetBandPassFilter(double soundInstanceID, double bandPassFilter, double Q); double soundInstanceID,
double xVelocity,
double yVelocity,
double zVelocity);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(
double soundInstanceID,
double trackPositionInSeconds);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolumeOverTime(
double soundInstanceID,
double volume,
double milliseconds);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLowPassFilter(
double soundInstanceID,
double lowPassFilter,
double Q);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetHighPassFilter(
double soundInstanceID,
double highPassFilter,
double Q);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetBandPassFilter(
double soundInstanceID,
double bandPassFilter,
double Q);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_QueueSoundInstance(double soundInstanceID, double queueSoundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_QueueSoundInstance(
double soundInstanceID,
double queueSoundInstanceID);
FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID); FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID);
FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID); FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID);
@ -91,24 +122,33 @@ FAUDIOGMSAPI void FAudioGMS_EffectChain_AddReverb(
double reverbGain, double reverbGain,
double decayTime, double decayTime,
double density, double density,
double roomSize double roomSize);
);
FAUDIOGMSAPI void FAudioGMS_EffectChain_Destroy(double effectChainID); FAUDIOGMSAPI void FAudioGMS_EffectChain_Destroy(double effectChainID);
/* /*
* NOTE: Any changes to the effect chain will NOT apply after this is set! * NOTE: Any changes to the effect chain will NOT apply after this is set!
* You MUST call SetEffectChain again if you make changes to the effect chain parameters! * You MUST call SetEffectChain again if you make changes to the effect
* chain parameters!
*/ */
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectChain(double soundInstanceID, double effectChainID, double effectGain); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectChain(
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effectGain); double soundInstanceID,
double effectChainID,
double effectGain);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectGain(
double soundInstanceID,
double effectGain);
FAUDIOGMSAPI void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain); FAUDIOGMSAPI void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain);
FAUDIOGMSAPI void FAudioGMS_SetMasteringEffectGain(double effectGain); FAUDIOGMSAPI void FAudioGMS_SetMasteringEffectGain(double effectGain);
FAUDIOGMSAPI void FAudioGMS_SetListenerPosition(double x, double y, double z); FAUDIOGMSAPI void FAudioGMS_SetListenerPosition(double x, double y, double z);
FAUDIOGMSAPI void FAudioGMS_SetListenerVelocity(double xVelocity, double yVelocity, double zVelocity); FAUDIOGMSAPI void FAudioGMS_SetListenerVelocity(
double xVelocity,
double yVelocity,
double zVelocity);
FAUDIOGMSAPI void FAudioGMS_PauseAll(); /* useful for mobile platforms, etc */ FAUDIOGMSAPI void FAudioGMS_PauseAll(); /* useful for mobile platforms, etc
*/
FAUDIOGMSAPI void FAudioGMS_ResumeAll(); /* same as above */ FAUDIOGMSAPI void FAudioGMS_ResumeAll(); /* same as above */
FAUDIOGMSAPI void FAudioGMS_StopAll(); FAUDIOGMSAPI void FAudioGMS_StopAll();