diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c9a48ee --- /dev/null +++ b/.clang-format @@ -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 +... + diff --git a/src/FAudioGMS.c b/src/FAudioGMS.c index 77e0f40..d15ba5f 100644 --- a/src/FAudioGMS.c +++ b/src/FAudioGMS.c @@ -30,18 +30,18 @@ #include "FAudioGMS.h" +#include "F3DAudio.h" #include "FAPOBase.h" #include "FAudioFX.h" -#include "F3DAudio.h" #include "FAudio.h" #define DR_WAV_IMPLEMENTATION -#define DRWAV_MALLOC(sz) SDL_malloc((sz)) -#define DRWAV_REALLOC(p, sz) SDL_realloc((p), (sz)) -#define DRWAV_FREE(p) SDL_free((p)) -#define DRWAV_COPY_MEMORY(dst, src, sz) SDL_memcpy((dst), (src), (sz)) -#define DRWAV_ZERO_MEMORY(p, sz) SDL_memset((p), 0, (sz)) +#define DRWAV_MALLOC(sz) SDL_malloc((sz)) +#define DRWAV_REALLOC(p, sz) SDL_realloc((p), (sz)) +#define DRWAV_FREE(p) SDL_free((p)) +#define DRWAV_COPY_MEMORY(dst, src, sz) SDL_memcpy((dst), (src), (sz)) +#define DRWAV_ZERO_MEMORY(p, sz) SDL_memset((p), 0, (sz)) #include "../lib/dr_wav.h" /* stb vorbis defines. this is kind of a mess but oh well */ @@ -112,7 +112,7 @@ static inline void Log(char *string) typedef struct IdStack { - uint32_t* array; + uint32_t *array; uint32_t count; uint32_t capacity; } IdStack; @@ -136,7 +136,7 @@ static inline void IdStack_Push(IdStack *stack, uint32_t id) stack->count += 1; } -static inline uint32_t IdStack_Pop(IdStack* stack) +static inline uint32_t IdStack_Pop(IdStack *stack) { stack->count -= 1; return stack->array[stack->count]; @@ -151,11 +151,11 @@ typedef enum FAudioGMS_SoundState typedef struct FAudioGMS_Voice { - FAudioVoice* handle; + FAudioVoice *handle; FAudioVoiceSends sends; uint8_t effectChainAttached; - FAudioSubmixVoice* effectVoice; + FAudioSubmixVoice *effectVoice; FAudioVoiceSends effectSends; float effectGain; } FAudioGMS_Voice; @@ -171,12 +171,12 @@ typedef struct FAudioGMS_StaticSound typedef struct FAudioGMS_StreamingSound { - stb_vorbis* fileHandle; + stb_vorbis *fileHandle; stb_vorbis_info info; - float* streamBuffer; + float *streamBuffer; uint32_t streamBufferSize; uint32_t mostRecentBufferOffset; /* used for calculating track position */ - uint8_t isFinalBuffer; /* used to detect end of playback */ + uint8_t isFinalBuffer; /* used to detect end of playback */ } FAudioGMS_StreamingSound; typedef struct FAudioGMS_SoundInstance FAudioGMS_SoundInstance; @@ -205,19 +205,20 @@ struct FAudioGMS_SoundInstance uint8_t destroyOnFinish; uint8_t is3D; - F3DAUDIO_EMITTER* emitter; /* must not be NULL if is3D */ + F3DAUDIO_EMITTER *emitter; /* must not be NULL if is3D */ float stereoAzimuth[2]; - uint8_t isGlobalPaused; + uint8_t isGlobalPaused; - uint32_t playBegin; - uint32_t playLength; + uint32_t playBegin; + uint32_t playLength; - FAudioGMS_SoundInstance *queuedSoundInstance; + FAudioGMS_SoundInstance *queuedSoundInstance; 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; } soundData; }; @@ -236,7 +237,7 @@ typedef struct FAudioGMS_EffectChain { uint32_t id; uint32_t effectCount; - FAudioGMS_EffectType *effectTypes; /* length equal to effectCount */ + FAudioGMS_EffectType *effectTypes; /* length equal to effectCount */ union FAudioGMS_EffectParameters *effectParameters; /* length equal to effectCount */ } FAudioGMS_EffectChain; @@ -245,7 +246,7 @@ static const float DOPPLER_SCALE = 1.0f; typedef struct FAudioGMS_Device { - FAudio* handle; + FAudio *handle; F3DAUDIO_HANDLE handle3D; FAudioDeviceDetails deviceDetails; @@ -266,19 +267,24 @@ typedef struct FAudioGMS_Device uint32_t soundInstanceCount; IdStack soundInstanceIndexStack; - FAudioGMS_EffectChain** effectChains; + FAudioGMS_EffectChain **effectChains; uint32_t effectChainCount; IdStack effectChainIndexStack; double timestep; } 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 */ -#define RETURN_ON_NULL_DEVICE(x) if (device == NULL) { return x; } +/* 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 */ +#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) { if (id >= 0 && id < device->staticSoundCount) { @@ -291,7 +297,7 @@ static inline FAudioGMS_StaticSound* FAudioGMS_INTERNAL_LookupStaticSound(uint32 } } -static inline FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_LookupSoundInstance(uint32_t id) +static inline FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_LookupSoundInstance(uint32_t id) { if (id >= 0 && id < device->soundInstanceCount) { @@ -304,7 +310,7 @@ static inline FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_LookupSoundInstance(ui } } -static inline FAudioGMS_EffectChain* FAudioGMS_INTERNAL_LookupEffectChain(uint32_t id) +static inline FAudioGMS_EffectChain *FAudioGMS_INTERNAL_LookupEffectChain(uint32_t id) { if (id >= 0 && id < device->effectChainCount) { @@ -319,36 +325,38 @@ static inline FAudioGMS_EffectChain* FAudioGMS_INTERNAL_LookupEffectChain(uint32 /* Forward declarations to avoid some annoying BS */ -static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(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_AddBuffer(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_OnBufferEndCallback(FAudioVoiceCallback* callback, FAudioGMS_SoundInstance *instance) +static void FAudioGMS_INTERNAL_OnBufferEndCallback( + FAudioVoiceCallback *callback, + FAudioGMS_SoundInstance *instance) { - if (instance->isStatic) - { - FAudioGMS_INTERNAL_SoundInstance_Stop(instance); - } - else - { - if (instance->soundData.streamingSound.isFinalBuffer) - { - FAudioGMS_INTERNAL_SoundInstance_Stop(instance); - } - else - { - FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); - } - } + if (instance->isStatic) + { + FAudioGMS_INTERNAL_SoundInstance_Stop(instance); + } + else + { + if (instance->soundData.streamingSound.isFinalBuffer) + { + FAudioGMS_INTERNAL_SoundInstance_Stop(instance); + } + else + { + FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); + } + } - if (instance->soundState == SoundState_Stopped) - { - if (instance->queuedSoundInstance != NULL) - { - FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance); - instance->queuedSoundInstance = NULL; - } - } + if (instance->soundState == SoundState_Stopped) + { + if (instance->queuedSoundInstance != NULL) + { + FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance); + instance->queuedSoundInstance = NULL; + } + } } void FAudioGMS_Init(double spatialDistanceScale, double timestep) @@ -384,10 +392,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep) uint32_t i = 0; for (i = 0; i < deviceCount; i += 1) { - FAudio_GetDeviceDetails( - device->handle, - i, - &deviceDetails); + FAudio_GetDeviceDetails(device->handle, i, &deviceDetails); if ((deviceDetails.Role & FAudioDefaultGameDevice) == FAudioDefaultGameDevice) { @@ -399,23 +404,19 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep) if (i == deviceCount) { i = 0; /* whatever we'll just use the first one i guess */ - FAudio_GetDeviceDetails( - device->handle, - i, - &deviceDetails); + FAudio_GetDeviceDetails(device->handle, i, &deviceDetails); device->deviceDetails = deviceDetails; } if (FAudio_CreateMasteringVoice( - device->handle, - &device->masteringVoice, - FAUDIO_DEFAULT_CHANNELS, - FAUDIO_DEFAULT_SAMPLERATE, - 0, - i, - NULL - ) != 0) + device->handle, + &device->masteringVoice, + FAUDIO_DEFAULT_CHANNELS, + FAUDIO_DEFAULT_SAMPLERATE, + 0, + i, + NULL) != 0) { Log("No mastering voice found! Bailing!"); FAudio_Release(device->handle); @@ -430,15 +431,14 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep) device->fauxMasteringVoice.sends.pSends[0].pOutputVoice = device->masteringVoice; if (FAudio_CreateSubmixVoice( - device->handle, - &device->fauxMasteringVoice.handle, - device->deviceDetails.OutputFormat.Format.nChannels, - device->deviceDetails.OutputFormat.Format.nSamplesPerSec, - 0, - 0, - &device->fauxMasteringVoice.sends, - NULL - ) != 0) + device->handle, + &device->fauxMasteringVoice.handle, + device->deviceDetails.OutputFormat.Format.nChannels, + device->deviceDetails.OutputFormat.Format.nSamplesPerSec, + 0, + 0, + &device->fauxMasteringVoice.sends, + NULL) != 0) { Log("Failed to create faux mastering voice! Bailing!"); FAudioVoice_DestroyVoice(device->masteringVoice); @@ -459,8 +459,7 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep) F3DAudioInitialize( device->deviceDetails.OutputFormat.dwChannelMask, SPEED_OF_SOUND, - device->handle3D - ); + device->handle3D); device->listener.OrientFront.x = 0; device->listener.OrientFront.y = 0; @@ -503,18 +502,20 @@ void FAudioGMS_Init(double spatialDistanceScale, double timestep) 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) { /* Two major things to notice: - * 1. The spec assumes any speaker count >= 2 has Front Left/Right. - * 2. Stereo panning is WAY more complicated than you think. - * The main thing is that hard panning does NOT eliminate an - * entire channel; the two channels are blended on each side. - * -flibit - */ + * 1. The spec assumes any speaker count >= 2 has Front Left/Right. + * 2. Stereo panning is WAY more complicated than you think. + * The main thing is that hard panning does NOT eliminate an + * entire channel; the two channels are blended on each side. + * -flibit + */ - float* outputMatrix = (float*) instance->dspSettings.pMatrixCoefficients; + float *outputMatrix = (float *)instance->dspSettings.pMatrixCoefficients; if (instance->dspSettings.SrcChannelCount == 1) { if (instance->dspSettings.DstChannelCount == 1) @@ -524,7 +525,7 @@ static void SetPanMatrixCoefficients(FAudioGMS_SoundInstance *instance) else { outputMatrix[0] = (instance->pan > 0.0f) ? (1.0f - instance->pan) : 1.0f; - outputMatrix[1] = (instance->pan < 0.0f) ? (1.0f + instance->pan) : 1.0f; + outputMatrix[1] = (instance->pan < 0.0f) ? (1.0f + instance->pan) : 1.0f; } } else @@ -564,7 +565,12 @@ double FAudioGMS_StaticSound_LoadWAV(char *filePath) drwav_uint64 frameCount; 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) { Log("Error opening WAV file: "); @@ -578,9 +584,9 @@ double FAudioGMS_StaticSound_LoadWAV(char *filePath) sound->buffer.LoopBegin = 0; sound->buffer.LoopCount = 0; sound->buffer.LoopLength = 0; - sound->buffer.PlayBegin = 0; + sound->buffer.PlayBegin = 0; sound->buffer.PlayLength = frameCount; - sound->buffer.pAudioData = (uint8_t*) pSampleData; + sound->buffer.pAudioData = (uint8_t *)pSampleData; sound->buffer.pContext = NULL; sound->lengthInSeconds = frameCount / sound->samplesPerSecond; @@ -593,7 +599,9 @@ double FAudioGMS_StaticSound_LoadWAV(char *filePath) { 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; } @@ -602,7 +610,7 @@ double FAudioGMS_StaticSound_LoadWAV(char *filePath) return (double)sound->id; } -static void FAudioGMS_INTERNAL_SoundInstance_SetPan(FAudioGMS_SoundInstance* instance, float pan) +static void FAudioGMS_INTERNAL_SoundInstance_SetPan(FAudioGMS_SoundInstance *instance, float pan) { pan = SDL_max(-1.0, SDL_min(1.0, pan)); instance->pan = pan; @@ -614,11 +622,10 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetPan(FAudioGMS_SoundInstance* ins instance->dspSettings.SrcChannelCount, instance->dspSettings.DstChannelCount, instance->dspSettings.pMatrixCoefficients, - 0 - ); + 0); } -static void FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(FAudioGMS_SoundInstance *instance) { float doppler = 1.0f; @@ -633,37 +640,43 @@ static void FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(FAudioGMS_SoundInstance FAudioSourceVoice_SetFrequencyRatio( 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 */ - 0 - ); + 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 */ + 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)); instance->pitch = pitch; 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; FAudioVoice_SetVolume(instance->voice.handle, volume, 0); } -static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init( +static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_Init( uint32_t channelCount, uint32_t samplesPerSecond, - uint8_t isStatic -) { - FAudioGMS_SoundInstance* instance = SDL_malloc(sizeof(FAudioGMS_SoundInstance)); + uint8_t isStatic) +{ + FAudioGMS_SoundInstance *instance = SDL_malloc(sizeof(FAudioGMS_SoundInstance)); instance->voice.handle = NULL; instance->isStatic = isStatic; instance->loop = 0; instance->destroyOnFinish = 0; - instance->isGlobalPaused = 0; + instance->isGlobalPaused = 0; instance->format.wFormatTag = FAUDIO_FORMAT_IEEE_FLOAT; instance->format.wBitsPerSample = 32; @@ -698,7 +711,8 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init( instance->dspSettings.SrcChannelCount = channelCount; 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); SDL_memset(instance->dspSettings.pMatrixCoefficients, 0, memsize); @@ -725,10 +739,10 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init( instance->stereoAzimuth[0] = 0.0f; instance->stereoAzimuth[1] = 0.0f; - instance->playBegin = 0; - instance->playLength = 0; + instance->playBegin = 0; + instance->playLength = 0; - instance->queuedSoundInstance = NULL; + instance->queuedSoundInstance = NULL; if (device->soundInstanceIndexStack.count > 0) { @@ -738,7 +752,9 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init( { 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; } @@ -747,14 +763,13 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_Init( return instance; } -static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound( - FAudioGMS_StaticSound* staticSound -) { - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_SoundInstance_Init( +static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound( + FAudioGMS_StaticSound *staticSound) +{ + FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_SoundInstance_Init( staticSound->channels, staticSound->samplesPerSecond, - 1 - ); + 1); instance->isStatic = 1; instance->soundData.staticSound = staticSound; @@ -765,11 +780,13 @@ static FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_SoundInstance_CreateFromStati double FAudioGMS_StaticSound_CreateSoundInstance(double staticSoundID) { 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) { - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound(staticSound); + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_SoundInstance_CreateFromStaticSound(staticSound); return instance->id; } 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; p.Type = FAudioLowPassFilter; @@ -791,9 +811,13 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetLowPassFilter(FAudioGMS_SoundIns 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) { @@ -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; p.Type = FAudioHighPassFilter; @@ -813,9 +840,13 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetHighPassFilter(FAudioGMS_SoundIn 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) { @@ -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; p.Type = FAudioBandPassFilter; @@ -835,9 +869,13 @@ static void FAudioGMS_INTERNAL_SoundInstance_SetBandPassFilter(FAudioGMS_SoundIn 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) { @@ -847,33 +885,36 @@ void FAudioGMS_SoundInstance_SetBandPassFilter(double soundInstanceID, double ba void FAudioGMS_SoundInstance_QueueSoundInstance(double soundInstanceID, double queueSoundInstanceID) { - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); - FAudioGMS_SoundInstance* queueInstance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)queueSoundInstanceID); + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); + FAudioGMS_SoundInstance *queueInstance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)queueSoundInstanceID); if (instance != NULL && queueInstance != NULL) { - instance->queuedSoundInstance = queueInstance; - } - else - { - if (instance == NULL) - { - Log("QueueSoundInstace: Invalid instance ID!"); - } - else - { - Log("QueueSoundInstance: Invalid queue sound instance ID!"); - } - } + instance->queuedSoundInstance = queueInstance; + } + else + { + if (instance == NULL) + { + Log("QueueSoundInstace: Invalid instance ID!"); + } + else + { + Log("QueueSoundInstance: Invalid queue sound instance ID!"); + } + } } -static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance *instance) { - F3DAUDIO_EMITTER* emitter = instance->emitter; + F3DAUDIO_EMITTER *emitter = instance->emitter; 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; } @@ -882,8 +923,7 @@ static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance* instance) &device->listener, emitter, F3DAUDIO_CALCULATE_MATRIX | F3DAUDIO_CALCULATE_DOPPLER, - &instance->dspSettings - ); + &instance->dspSettings); FAudioGMS_INTERNAL_SoundInstance_UpdatePitch(instance); FAudioVoice_SetOutputMatrix( @@ -892,41 +932,44 @@ static void FAudioGMS_INTERNAL_Apply3D(FAudioGMS_SoundInstance* instance) instance->dspSettings.SrcChannelCount, instance->dspSettings.DstChannelCount, instance->dspSettings.pMatrixCoefficients, - 0 - ); + 0); } -static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance *instance) { uint32_t defaultRequestedSampleCount = instance->format.nSamplesPerSec / 4; - uint32_t requestedSampleCount = defaultRequestedSampleCount; + uint32_t requestedSampleCount = defaultRequestedSampleCount; - if (instance->playLength != 0) - { - uint32_t distanceToEndPoint = (instance->playBegin + instance->playLength) - stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle); - requestedSampleCount = SDL_min(requestedSampleCount, distanceToEndPoint); - } - - uint32_t requiredStagingBufferSize = requestedSampleCount * instance->format.nChannels * sizeof(float); - if (instance->soundData.streamingSound.streamBufferSize < requiredStagingBufferSize) + if (instance->playLength != 0) { - instance->soundData.streamingSound.streamBuffer = SDL_realloc(instance->soundData.streamingSound.streamBuffer, requiredStagingBufferSize); - instance->soundData.streamingSound.streamBufferSize = requiredStagingBufferSize; + uint32_t distanceToEndPoint = + (instance->playBegin + instance->playLength) - + stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle); + requestedSampleCount = SDL_min(requestedSampleCount, distanceToEndPoint); } - instance->soundData.streamingSound.mostRecentBufferOffset = stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle); + uint32_t requiredStagingBufferSize = + requestedSampleCount * instance->format.nChannels * sizeof(float); + if (instance->soundData.streamingSound.streamBufferSize < requiredStagingBufferSize) + { + instance->soundData.streamingSound.streamBuffer = + SDL_realloc(instance->soundData.streamingSound.streamBuffer, requiredStagingBufferSize); + instance->soundData.streamingSound.streamBufferSize = requiredStagingBufferSize; + } + + instance->soundData.streamingSound.mostRecentBufferOffset = + stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle); /* NOTE: this function returns samples per channel, not total samples */ uint32_t sampleCount = stb_vorbis_get_samples_float_interleaved( instance->soundData.streamingSound.fileHandle, instance->format.nChannels, instance->soundData.streamingSound.streamBuffer, - requestedSampleCount * instance->format.nChannels - ); + requestedSampleCount * instance->format.nChannels); FAudioBuffer buffer; buffer.AudioBytes = sampleCount * instance->format.nChannels * sizeof(float); - buffer.pAudioData = (uint8_t*) instance->soundData.streamingSound.streamBuffer; + buffer.pAudioData = (uint8_t *)instance->soundData.streamingSound.streamBuffer; buffer.PlayBegin = 0; buffer.PlayLength = sampleCount; @@ -938,22 +981,22 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance* FAudioSourceVoice_SubmitSourceBuffer(instance->voice.handle, &buffer, NULL); - instance->soundData.streamingSound.isFinalBuffer = 0; + instance->soundData.streamingSound.isFinalBuffer = 0; - if (sampleCount < defaultRequestedSampleCount) - { - if (instance->loop) - { - stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin); - } - else - { - instance->soundData.streamingSound.isFinalBuffer = 1; - } - } + if (sampleCount < defaultRequestedSampleCount) + { + if (instance->loop) + { + stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin); + } + else + { + instance->soundData.streamingSound.isFinalBuffer = 1; + } + } } -double FAudioGMS_StreamingSound_LoadOGG(char* filePath) +double FAudioGMS_StreamingSound_LoadOGG(char *filePath) { RETURN_ON_NULL_DEVICE(-1.0) int error = 0; @@ -968,25 +1011,26 @@ double FAudioGMS_StreamingSound_LoadOGG(char* filePath) stb_vorbis_info info = stb_vorbis_get_info(fileHandle); - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_SoundInstance_Init( - info.channels, - info.sample_rate, - 0 - ); + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_SoundInstance_Init(info.channels, info.sample_rate, 0); instance->soundData.streamingSound.fileHandle = fileHandle; instance->soundData.streamingSound.info = info; instance->soundData.streamingSound.streamBuffer = NULL; instance->soundData.streamingSound.streamBufferSize = 0; instance->soundData.streamingSound.mostRecentBufferOffset = 0; - instance->soundData.streamingSound.isFinalBuffer = 0; + instance->soundData.streamingSound.isFinalBuffer = 0; FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); 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; @@ -1027,7 +1071,7 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddEmitter(FAudioGMS_SoundInstance* FAudioGMS_INTERNAL_Apply3D(instance); } -static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance) { if (instance->soundState == SoundState_Playing) { @@ -1036,7 +1080,7 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* insta if (instance->isStatic) { - instance->soundData.staticSound->buffer.pContext = instance; + instance->soundData.staticSound->buffer.pContext = instance; if (instance->loop) { @@ -1051,20 +1095,24 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* insta instance->soundData.staticSound->buffer.LoopLength = 0; } - if (instance->soundState == SoundState_Paused) - { - FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle); + if (instance->soundState == SoundState_Paused) + { + FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle); - instance->soundData.staticSound->buffer.PlayBegin = instance->voice.handle->src.curBufferOffset; - instance->soundData.staticSound->buffer.PlayLength = instance->playLength; - } - else - { - instance->soundData.staticSound->buffer.PlayBegin = instance->playBegin; - instance->soundData.staticSound->buffer.PlayLength = instance->playLength; - } + instance->soundData.staticSound->buffer.PlayBegin = + instance->voice.handle->src.curBufferOffset; + instance->soundData.staticSound->buffer.PlayLength = instance->playLength; + } + else + { + instance->soundData.staticSound->buffer.PlayBegin = instance->playBegin; + 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); @@ -1074,7 +1122,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance* insta void FAudioGMS_SoundInstance_Play(double soundInstanceID) { 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) { @@ -1082,79 +1131,95 @@ void FAudioGMS_SoundInstance_Play(double soundInstanceID) } } -static void FAudioGMS_INTERNAL_SoundInstance_Pause(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_SoundInstance_Pause(FAudioGMS_SoundInstance *instance) { - if (instance != NULL) + if (instance != NULL) { 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; } } 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) { RETURN_ON_NULL_DEVICE() - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); - FAudioGMS_INTERNAL_SoundInstance_Pause(instance); + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); + FAudioGMS_INTERNAL_SoundInstance_Pause(instance); } -static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance *instance) { 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_FlushSourceBuffers(instance->voice.handle); if (!instance->isStatic) { - stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin); /* back to the start */ - FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); /* preload so we dont stutter on play */ + stb_vorbis_seek( + instance->soundData.streamingSound.fileHandle, + instance->playBegin); /* back to the start */ + FAudioGMS_INTERNAL_SoundInstance_AddBuffer( + instance); /* preload so we dont stutter on play */ } } 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) { 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); } void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop) { - RETURN_ON_NULL_DEVICE() - FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); + RETURN_ON_NULL_DEVICE() + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); - if (instance != NULL) - { - instance->loop = (uint8_t)loop; + if (instance != NULL) + { + instance->loop = (uint8_t)loop; - if (instance->isStatic && instance->soundState == SoundState_Playing) - { - /* We need to pause and play so that static buffers get resubmitted */ - FAudioGMS_INTERNAL_SoundInstance_Pause(instance); - FAudioGMS_INTERNAL_SoundInstance_Play(instance); - } - } + if (instance->isStatic && instance->soundState == SoundState_Playing) + { + /* We need to pause and play so that static buffers get resubmitted + */ + FAudioGMS_INTERNAL_SoundInstance_Pause(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance); + } + } } void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan) { 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) { @@ -1165,7 +1230,8 @@ void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan) void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch) { 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) { @@ -1176,7 +1242,8 @@ void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch) void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume) { 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) { @@ -1188,7 +1255,8 @@ void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume) void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z) { 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) { @@ -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() - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); 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 */ -void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, double trackPositionInSeconds) +void FAudioGMS_SoundInstance_SetTrackPositionInSeconds( + double soundInstanceID, + double trackPositionInSeconds) { 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) { - uint32_t sampleFrame = instance->soundData.staticSound->samplesPerSecond * trackPositionInSeconds; + uint32_t sampleFrame = + instance->soundData.staticSound->samplesPerSecond * trackPositionInSeconds; FAudioGMS_SoundState currentState = instance->soundState; if (currentState == SoundState_Playing) @@ -1260,92 +1337,105 @@ 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->isStatic) - { - return instance->voice.handle->src.curBufferOffset / sizeof(float); - } - else - { - return instance->soundData.streamingSound.mostRecentBufferOffset + instance->voice.handle->src.curBufferOffset; - } - } + if (instance != NULL) + { + if (instance->isStatic) + { + return instance->voice.handle->src.curBufferOffset / sizeof(float); + } + else + { + return instance->soundData.streamingSound.mostRecentBufferOffset + + instance->voice.handle->src.curBufferOffset; + } + } - Log("Invalid sound instance!"); - return 0; + Log("Invalid sound instance!"); + return 0; } -void FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startInMilliseconds, double endInMilliseconds) -{ - RETURN_ON_NULL_DEVICE() - FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); - - if (instance != NULL) - { - uint32_t playBeginSampleFrame = instance->format.nSamplesPerSec * (startInMilliseconds / 1000); - uint32_t playEndSampleFrame = instance->format.nSamplesPerSec * (endInMilliseconds / 1000); - uint32_t playLength = playEndSampleFrame - playBeginSampleFrame; - - if (playLength <= 0) - { - Log("Play end is less than or equal to play start! Bailing!"); - return; - } - - instance->playBegin = playBeginSampleFrame; - instance->playLength = playLength; - - uint32_t currentFrame = FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance); - - if ( - currentFrame < instance->playBegin || - (currentFrame > instance->playBegin + instance->playLength) - ) { - /* we are outside the play region */ - if (instance->isStatic && instance->soundState == SoundState_Playing) - { - FAudioGMS_INTERNAL_SoundInstance_Stop(instance); - FAudioGMS_INTERNAL_SoundInstance_Play(instance); - } - else if (!instance->isStatic) - { - FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle); - stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin); - FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); - } - } - else - { - /* we are inside the play region */ - if (instance->isStatic && instance->soundState != SoundState_Stopped) - { - FAudioGMS_INTERNAL_SoundInstance_Pause(instance); - FAudioGMS_INTERNAL_SoundInstance_Play(instance); - } - } - } -} - -void FAudioGMS_SoundInstance_SetVolumeOverTime(double soundInstanceID, double volume, double milliseconds) +void FAudioGMS_SoundInstance_SetPlayRegion( + double soundInstanceID, + double startInMilliseconds, + double endInMilliseconds) { 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) + { + uint32_t playBeginSampleFrame = + instance->format.nSamplesPerSec * (startInMilliseconds / 1000); + uint32_t playEndSampleFrame = instance->format.nSamplesPerSec * (endInMilliseconds / 1000); + uint32_t playLength = playEndSampleFrame - playBeginSampleFrame; + + if (playLength <= 0) + { + Log("Play end is less than or equal to play start! Bailing!"); + return; + } + + instance->playBegin = playBeginSampleFrame; + instance->playLength = playLength; + + uint32_t currentFrame = + FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance); + + if (currentFrame < instance->playBegin || + (currentFrame > instance->playBegin + instance->playLength)) + { + /* we are outside the play region */ + if (instance->isStatic && instance->soundState == SoundState_Playing) + { + FAudioGMS_INTERNAL_SoundInstance_Stop(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance); + } + else if (!instance->isStatic) + { + FAudioSourceVoice_FlushSourceBuffers(instance->voice.handle); + stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, instance->playBegin); + FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance); + } + } + else + { + /* we are inside the play region */ + if (instance->isStatic && instance->soundState != SoundState_Stopped) + { + FAudioGMS_INTERNAL_SoundInstance_Pause(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance); + } + } + } +} + +void FAudioGMS_SoundInstance_SetVolumeOverTime( + double soundInstanceID, + double volume, + double milliseconds) +{ + RETURN_ON_NULL_DEVICE() + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); if (instance != NULL) { instance->adjustingVolumeOverTime = 1; 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) { 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) { @@ -1361,7 +1451,8 @@ double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID) double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID) { 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) { @@ -1377,7 +1468,8 @@ double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID) double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID) { 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) { @@ -1387,7 +1479,8 @@ double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID) } else { - return stb_vorbis_stream_length_in_seconds(instance->soundData.streamingSound.fileHandle); + return stb_vorbis_stream_length_in_seconds( + instance->soundData.streamingSound.fileHandle); } } else @@ -1400,11 +1493,13 @@ double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID) double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID) { 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) { - return (double)FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance) / instance->format.nSamplesPerSec; + return (double)FAudioGMS_INTERNAL_SoundInstance_GetTrackPositionInSampleFrames(instance) / + instance->format.nSamplesPerSec; } else { @@ -1429,7 +1524,7 @@ void FAudioGMS_SetListenerVelocity(double xVelocity, double yVelocity, double zV device->listener.Velocity.z = zVelocity; } -static void FAudioGMS_INTERNAL_SoundInstance_Destroy(FAudioGMS_SoundInstance* instance) +static void FAudioGMS_INTERNAL_SoundInstance_Destroy(FAudioGMS_SoundInstance *instance) { if (instance != NULL) { @@ -1463,7 +1558,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_Destroy(FAudioGMS_SoundInstance* in void FAudioGMS_SoundInstance_Destroy(double soundInstanceID) { 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) { @@ -1474,7 +1570,8 @@ void FAudioGMS_SoundInstance_Destroy(double soundInstanceID) void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID) { 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) { @@ -1483,13 +1580,13 @@ void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID) } /* NOTE: this will die horribly if a sound is playing */ -static void FAudioGMS_INTERNAL_StaticSound_Destroy(FAudioGMS_StaticSound* sound) +static void FAudioGMS_INTERNAL_StaticSound_Destroy(FAudioGMS_StaticSound *sound) { if (sound != NULL) { device->staticSounds[sound->id] = NULL; IdStack_Push(&device->staticSoundIndexStack, sound->id); - SDL_free((void*)sound->buffer.pAudioData); + SDL_free((void *)sound->buffer.pAudioData); SDL_free(sound); } } @@ -1504,7 +1601,7 @@ void FAudioGMS_StaticSound_Destroy(double staticSoundID) double FAudioGMS_EffectChain_Create() { RETURN_ON_NULL_DEVICE(-1.0) - FAudioGMS_EffectChain* effectChain = SDL_malloc(sizeof(FAudioGMS_EffectChain)); + FAudioGMS_EffectChain *effectChain = SDL_malloc(sizeof(FAudioGMS_EffectChain)); effectChain->effectCount = 0; effectChain->effectTypes = NULL; @@ -1518,7 +1615,9 @@ double FAudioGMS_EffectChain_Create() { 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; } @@ -1527,21 +1626,31 @@ double FAudioGMS_EffectChain_Create() 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->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->effectParameters = SDL_realloc(effectChain->effectParameters, effectChain->effectCount * sizeof(FAudioGMS_EffectParameters)); - SDL_memcpy(&effectChain->effectParameters[effectChain->effectCount - 1], reverbParameters, sizeof(FAudioFXReverbParameters)); + effectChain->effectParameters = SDL_realloc( + effectChain->effectParameters, + effectChain->effectCount * sizeof(FAudioGMS_EffectParameters)); + SDL_memcpy( + &effectChain->effectParameters[effectChain->effectCount - 1], + reverbParameters, + sizeof(FAudioFXReverbParameters)); } void FAudioGMS_EffectChain_AddDefaultReverb(double effectChainID) { 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) { @@ -1590,10 +1699,11 @@ void FAudioGMS_EffectChain_AddReverb( double reverbGain, double decayTime, double density, - double roomSize -) { + double roomSize) +{ 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) { @@ -1630,7 +1740,7 @@ static void FAudioGMS_INTERNAL_Voice_SetEffectGain(FAudioGMS_Voice *voice, float { if (voice->effectChainAttached) { - float* outputMatrix = SDL_stack_alloc(float, voice->effectSends.SendCount); + float *outputMatrix = SDL_stack_alloc(float, voice->effectSends.SendCount); outputMatrix[0] = effectGain; if (voice->effectSends.SendCount == 2) @@ -1655,7 +1765,8 @@ static void FAudioGMS_INTERNAL_Voice_SetEffectGain(FAudioGMS_Voice *voice, float void FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effectGain) { 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) { @@ -1663,15 +1774,17 @@ 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; fAudioEffectChain->EffectCount = effectChain->effectCount; - fAudioEffectChain->pEffectDescriptors = SDL_malloc(fAudioEffectChain->EffectCount * sizeof(FAudioEffectDescriptor)); + fAudioEffectChain->pEffectDescriptors = + SDL_malloc(fAudioEffectChain->EffectCount * sizeof(FAudioEffectDescriptor)); - FAPO* reverb; + FAPO *reverb; for (i = 0; i < effectChain->effectCount; i += 1) { @@ -1680,9 +1793,10 @@ static FAudioEffectChain* FAudioGMS_INTERNAL_CreateFAudioEffectChain(FAudioGMS_E case EffectType_Reverb: FAudioCreateReverb(&reverb, 0); - FAudioEffectDescriptor* reverbDescriptor = &fAudioEffectChain->pEffectDescriptors[i]; + FAudioEffectDescriptor *reverbDescriptor = &fAudioEffectChain->pEffectDescriptors[i]; 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; break; @@ -1695,7 +1809,10 @@ static FAudioEffectChain* FAudioGMS_INTERNAL_CreateFAudioEffectChain(FAudioGMS_E 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; @@ -1711,7 +1828,7 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ voice->sends.pSends = SDL_realloc(voice->sends.pSends, 2 * sizeof(FAudioSendDescriptor)); } - FAudioEffectChain* fAudioEffectChain = FAudioGMS_INTERNAL_CreateFAudioEffectChain(effectChain); + FAudioEffectChain *fAudioEffectChain = FAudioGMS_INTERNAL_CreateFAudioEffectChain(effectChain); voice->effectSends.SendCount = 1; voice->effectSends.pSends = SDL_malloc(sizeof(FAudioSendDescriptor)); @@ -1741,7 +1858,7 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ for (i = 0; i < effectChain->effectCount; i += 1) { uint32_t parametersSize; - void* parameters; + void *parameters; switch (effectChain->effectTypes[i]) { @@ -1754,15 +1871,11 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ Log("Unknown effect type! Something is very wrong!"); } - FAudioVoice_SetEffectParameters( - voice->effectVoice, - i, - parameters, - parametersSize, - 0); + FAudioVoice_SetEffectParameters(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; if (voice == &device->fauxMasteringVoice) { @@ -1777,26 +1890,29 @@ static void FAudioGMS_INTERNAL_SetEffectChain(FAudioGMS_Voice* voice, FAudioGMS_ voice->effectChainAttached = 1; - FAudioVoice_SetOutputVoices( - voice->handle, - &voice->sends); + FAudioVoice_SetOutputVoices(voice->handle, &voice->sends); FAudioGMS_INTERNAL_Voice_SetEffectGain(voice, effectGain); /* All the effect parameters are copied to the voice so we free here */ for (i = 0; i < effectChain->effectCount; i += 1) { - FAPOBase_Release((FAPOBase*)fAudioEffectChain->pEffectDescriptors[i].pEffect); + FAPOBase_Release((FAPOBase *)fAudioEffectChain->pEffectDescriptors[i].pEffect); } SDL_free(fAudioEffectChain->pEffectDescriptors); 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() - FAudioGMS_SoundInstance *instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); - FAudioGMS_EffectChain *effectChain = FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); + FAudioGMS_EffectChain *effectChain = + FAudioGMS_INTERNAL_LookupEffectChain((uint32_t)effectChainID); if (instance != NULL && effectChain != NULL) { @@ -1807,7 +1923,8 @@ void FAudioGMS_SoundInstance_SetEffectChain(double soundInstanceID, double effec void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain) { 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) { @@ -1840,7 +1957,8 @@ static void FAudioGMS_INTERNAL_EffectChain_Destroy(FAudioGMS_EffectChain *effect void FAudioGMS_EffectChain_Destroy(double effectChainID) { 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) { @@ -1855,7 +1973,7 @@ void FAudioGMS_Update() for (i = 0; i < device->soundInstanceCount; i += 1) { - FAudioGMS_SoundInstance* instance = device->soundInstances[i]; + FAudioGMS_SoundInstance *instance = device->soundInstances[i]; if (instance != NULL) { @@ -1894,7 +2012,10 @@ void FAudioGMS_Update() if (instance->destroyOnFinish) { FAudioVoiceState state; - FAudioSourceVoice_GetState(instance->voice.handle, &state, FAUDIO_VOICE_NOSAMPLESPLAYED); + FAudioSourceVoice_GetState( + instance->voice.handle, + &state, + FAUDIO_VOICE_NOSAMPLESPLAYED); if (state.BuffersQueued == 0) { @@ -1907,34 +2028,34 @@ void FAudioGMS_Update() void FAudioGMS_PauseAll() { - RETURN_ON_NULL_DEVICE() - uint32_t i; + RETURN_ON_NULL_DEVICE() + uint32_t i; - for (i = 0; i < device->soundInstanceCount; i += 1) - { - FAudioGMS_SoundInstance *instance = device->soundInstances[i]; - if (instance != NULL) - { - instance->isGlobalPaused = 1; - FAudioGMS_INTERNAL_SoundInstance_Pause(instance); - } - } + for (i = 0; i < device->soundInstanceCount; i += 1) + { + FAudioGMS_SoundInstance *instance = device->soundInstances[i]; + if (instance != NULL) + { + instance->isGlobalPaused = 1; + FAudioGMS_INTERNAL_SoundInstance_Pause(instance); + } + } } void FAudioGMS_ResumeAll() { - RETURN_ON_NULL_DEVICE() - uint32_t i; + RETURN_ON_NULL_DEVICE() + uint32_t i; - for (i = 0; i < device->soundInstanceCount; i += 1) - { - FAudioGMS_SoundInstance *instance = device->soundInstances[i]; - if (instance != NULL && instance->isGlobalPaused) - { - instance->isGlobalPaused = 0; - FAudioGMS_INTERNAL_SoundInstance_Play(instance); - } - } + for (i = 0; i < device->soundInstanceCount; i += 1) + { + FAudioGMS_SoundInstance *instance = device->soundInstances[i]; + if (instance != NULL && instance->isGlobalPaused) + { + instance->isGlobalPaused = 0; + FAudioGMS_INTERNAL_SoundInstance_Play(instance); + } + } } void FAudioGMS_StopAll() diff --git a/src/FAudioGMS.h b/src/FAudioGMS.h index 627c211..7b1d385 100644 --- a/src/FAudioGMS.h +++ b/src/FAudioGMS.h @@ -36,84 +36,124 @@ #endif #ifdef __cplusplus -extern "C" { +extern "C" +{ #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_CreateSoundInstance(double staticSoundID); /* returns a sound instance ID */ -FAUDIOGMSAPI void FAudioGMS_StaticSound_Destroy(double staticSoundID); + FAUDIOGMSAPI double FAudioGMS_StaticSound_LoadWAV( + 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 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_Pause(double soundInstanceID); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_Stop(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_Play(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_Pause(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_Stop(double soundInstanceID); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPlayRegion(double soundInstanceID, double startInMilliseconds, double endInMilliseconds); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch); -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_Set3DVelocity(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_SetPlayRegion( + double soundInstanceID, + double startInMilliseconds, + double endInMilliseconds); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double pan); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch); + 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_Set3DVelocity( + 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_GetVolume(double soundInstanceID); -FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID); -FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID); + FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID); + FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID); + FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID); + FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_Destroy(double soundInstanceID); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_Destroy(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID); -FAUDIOGMSAPI double FAudioGMS_EffectChain_Create(); -FAUDIOGMSAPI void FAudioGMS_EffectChain_AddDefaultReverb(double effectChainID); -FAUDIOGMSAPI void FAudioGMS_EffectChain_AddReverb( - double effectChainID, - double wetDryMix, - double reflectionsDelay, - double reverbDelay, - double earlyDiffusion, - double lateDiffusion, - double lowEQGain, - double lowEQCutoff, - double highEQGain, - double highEQCutoff, - double reflectionsGain, - double reverbGain, - double decayTime, - double density, - double roomSize -); -FAUDIOGMSAPI void FAudioGMS_EffectChain_Destroy(double effectChainID); + FAUDIOGMSAPI double FAudioGMS_EffectChain_Create(); + FAUDIOGMSAPI void FAudioGMS_EffectChain_AddDefaultReverb(double effectChainID); + FAUDIOGMSAPI void FAudioGMS_EffectChain_AddReverb( + double effectChainID, + double wetDryMix, + double reflectionsDelay, + double reverbDelay, + double earlyDiffusion, + double lateDiffusion, + double lowEQGain, + double lowEQCutoff, + double highEQGain, + double highEQCutoff, + double reflectionsGain, + double reverbGain, + double decayTime, + double density, + double roomSize); + FAUDIOGMSAPI void FAudioGMS_EffectChain_Destroy(double effectChainID); -/* - * 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! - */ -FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectChain(double soundInstanceID, double effectChainID, double effectGain); -FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectGain(double soundInstanceID, double effectGain); + /* + * 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! + */ + FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetEffectChain( + 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_SetMasteringEffectGain(double effectGain); + FAUDIOGMSAPI void FAudioGMS_SetMasteringEffectChain(double effectChainID, double effectGain); + FAUDIOGMSAPI void FAudioGMS_SetMasteringEffectGain(double effectGain); -FAUDIOGMSAPI void FAudioGMS_SetListenerPosition(double x, double y, double z); -FAUDIOGMSAPI void FAudioGMS_SetListenerVelocity(double xVelocity, double yVelocity, double zVelocity); + FAUDIOGMSAPI void FAudioGMS_SetListenerPosition(double x, double y, double z); + FAUDIOGMSAPI void FAudioGMS_SetListenerVelocity( + double xVelocity, + double yVelocity, + double zVelocity); -FAUDIOGMSAPI void FAudioGMS_PauseAll(); /* useful for mobile platforms, etc */ -FAUDIOGMSAPI void FAudioGMS_ResumeAll(); /* same as above */ -FAUDIOGMSAPI void FAudioGMS_StopAll(); + FAUDIOGMSAPI void FAudioGMS_PauseAll(); /* useful for mobile platforms, etc + */ + FAUDIOGMSAPI void FAudioGMS_ResumeAll(); /* same as above */ + FAUDIOGMSAPI void FAudioGMS_StopAll(); -FAUDIOGMSAPI void FAudioGMS_Update(); -FAUDIOGMSAPI void FAudioGMS_Destroy(); + FAUDIOGMSAPI void FAudioGMS_Update(); + FAUDIOGMSAPI void FAudioGMS_Destroy(); #ifdef __cplusplus }