2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-05-01 02:00:39 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
void SoundSource_InitAll(PlayState* play) {
|
|
|
|
SoundSource* sources = &play->soundSources[0];
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
// clang-format off
|
2022-05-21 18:23:43 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(play->soundSources); i++) { sources[i].countdown = 0; }
|
2020-05-01 02:00:39 +00:00
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
void SoundSource_UpdateAll(PlayState* play) {
|
|
|
|
SoundSource* source = &play->soundSources[0];
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 i;
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(play->soundSources); i++) {
|
2020-05-01 02:00:39 +00:00
|
|
|
if (source->countdown != 0) {
|
|
|
|
if (DECR(source->countdown) == 0) {
|
2022-01-11 01:31:53 +00:00
|
|
|
Audio_StopSfxByPos(&source->projectedPos);
|
2020-05-01 02:00:39 +00:00
|
|
|
} else {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkinMatrix_Vec3fMtxFMultXYZ(&play->viewProjectionMtxF, &source->worldPos, &source->projectedPos);
|
2020-05-01 02:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
source++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
void SoundSource_PlaySfxAtFixedWorldPos(PlayState* play, Vec3f* worldPos, s32 duration, u16 sfxId) {
|
2020-05-01 02:00:39 +00:00
|
|
|
s32 countdown;
|
|
|
|
SoundSource* source;
|
2021-02-14 00:49:40 +00:00
|
|
|
s32 smallestCountdown = 0xFFFF;
|
2020-05-01 02:00:39 +00:00
|
|
|
SoundSource* backupSource;
|
|
|
|
s32 i;
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
source = &play->soundSources[0];
|
|
|
|
for (i = 0; i < ARRAY_COUNT(play->soundSources); i++) {
|
2020-05-01 02:00:39 +00:00
|
|
|
if (source->countdown == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-11 01:31:53 +00:00
|
|
|
// Store the sound source with the smallest remaining countdown
|
2020-05-01 02:00:39 +00:00
|
|
|
countdown = source->countdown;
|
|
|
|
if (countdown < smallestCountdown) {
|
|
|
|
smallestCountdown = countdown;
|
|
|
|
backupSource = source;
|
|
|
|
}
|
|
|
|
source++;
|
|
|
|
}
|
|
|
|
|
2022-01-11 01:31:53 +00:00
|
|
|
// If no sound source is available, replace the sound source with the smallest remaining countdown
|
2022-05-21 18:23:43 +00:00
|
|
|
if (i >= ARRAY_COUNT(play->soundSources)) {
|
2020-05-01 02:00:39 +00:00
|
|
|
source = backupSource;
|
2022-01-11 01:31:53 +00:00
|
|
|
Audio_StopSfxByPos(&source->projectedPos);
|
2020-05-01 02:00:39 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 01:31:53 +00:00
|
|
|
source->worldPos = *worldPos;
|
2020-05-01 02:00:39 +00:00
|
|
|
source->countdown = duration;
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
SkinMatrix_Vec3fMtxFMultXYZ(&play->viewProjectionMtxF, &source->worldPos, &source->projectedPos);
|
2022-04-23 14:55:18 +00:00
|
|
|
Audio_PlaySoundGeneral(sfxId, &source->projectedPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale,
|
|
|
|
&gSfxDefaultReverb);
|
2020-05-01 02:00:39 +00:00
|
|
|
}
|