From 47cd6c3c5e2cc7b98a2a15e9c0a91d5c374fb754 Mon Sep 17 00:00:00 2001 From: James Lambert Date: Tue, 14 Feb 2023 08:54:34 -0700 Subject: [PATCH] Work on ball sound effects --- README.md | 2 +- .../weapons/physcannon/energy_sing_loop4.ins | 16 ++++++++++++++++ src/audio/clips.c | 4 +++- src/audio/clips.h | 2 ++ src/main.c | 2 +- src/scene/ball.c | 12 ++++++++++++ src/scene/ball.h | 1 + 7 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 assets/sound/weapons/physcannon/energy_sing_loop4.ins diff --git a/README.md b/README.md index b6f623c..e39e77d 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where Blender ## Current TODO list - [ ] fix chell animation problem (fixed itself, investigate) -- [ ] sound effects for ball +- [ ] sound effects for ball (portal_pak_dir/scripts/npc_sounds_energy_ball.txt) -------------------------------------------------------- - [ ] Skips audio sometimes - [ ] Portal not rending recursively sometimes diff --git a/assets/sound/weapons/physcannon/energy_sing_loop4.ins b/assets/sound/weapons/physcannon/energy_sing_loop4.ins new file mode 100644 index 0000000..fb499b8 --- /dev/null +++ b/assets/sound/weapons/physcannon/energy_sing_loop4.ins @@ -0,0 +1,16 @@ + +envelope Envelope { + attackTime = 0 + attackVolume = 127 + decayTime = -1 + decayVolume = 127 + releaseTime = 0 +} + +sound Sound { + use("../../../../portal_pak_dir/sound/weapons/physcannon/energy_sing_loop4.wav") + loopCount = -1 + loopEnd = -1 + pan=64 + envelope = Envelope +} \ No newline at end of file diff --git a/src/audio/clips.c b/src/audio/clips.c index 3bb86a1..3f11451 100644 --- a/src/audio/clips.c +++ b/src/audio/clips.c @@ -23,4 +23,6 @@ unsigned short soundsPortalOpen2 = SOUNDS_PORTAL_OPEN2; unsigned short soundsPortalFizzle = SOUNDS_PORTAL_FIZZLE2; -unsigned short soundsElevatorDoor = SOUNDS_DOORMOVE1; \ No newline at end of file +unsigned short soundsElevatorDoor = SOUNDS_DOORMOVE1; + +unsigned short soundsBallLoop = SOUNDS_ENERGY_SING_LOOP4; \ No newline at end of file diff --git a/src/audio/clips.h b/src/audio/clips.h index 88da2b4..010a181 100644 --- a/src/audio/clips.h +++ b/src/audio/clips.h @@ -12,4 +12,6 @@ extern unsigned short soundsPortalFizzle; extern unsigned short soundsElevatorDoor; +extern unsigned short soundsBallLoop; + #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index fd257ad..85913df 100644 --- a/src/main.c +++ b/src/main.c @@ -161,7 +161,7 @@ static void gameProc(void* arg) { contactSolverInit(&gContactSolver); portalSurfaceCleanupQueueInit(); savefileNew(); - levelLoad(0); + levelLoad(4); cutsceneRunnerReset(); controllersInit(); initAudio(fps); diff --git a/src/scene/ball.c b/src/scene/ball.c index e1c3fac..32871a4 100644 --- a/src/scene/ball.c +++ b/src/scene/ball.c @@ -13,6 +13,9 @@ #include "../build/assets/models/cube/cube.h" #include "../build/assets/materials/static.h" +#include "../audio/soundplayer.h" +#include "../audio/clips.h" + #define BALL_RADIUS 0.1f struct CollisionBox gBallCollisionBox = { @@ -83,6 +86,7 @@ void ballBurnRender(void* data, struct DynamicRenderDataList* renderList, struct void ballInitInactive(struct Ball* ball) { ball->targetSpeed = 0.0f; ball->flags = 0; + ball->soundLoopId = SOUND_ID_NONE; } void ballInit(struct Ball* ball, struct Vector3* position, struct Vector3* velocity, short startingRoom, float ballLifetime) { @@ -104,6 +108,8 @@ void ballInit(struct Ball* ball, struct Vector3* position, struct Vector3* veloc ball->dynamicId = dynamicSceneAddViewDependant(ball, ballRender, &ball->rigidBody.transform.position, BALL_RADIUS); dynamicSceneSetRoomFlags(ball->dynamicId, ROOM_FLAG_FROM_INDEX(startingRoom)); + + ball->soundLoopId = soundPlayerPlay(soundsBallLoop, 4.0f, 1.0f, &ball->rigidBody.transform.position, &ball->rigidBody.velocity); } void ballTurnOnCollision(struct Ball* ball) { @@ -163,6 +169,8 @@ void ballUpdate(struct Ball* ball) { vector3Scale(&ball->rigidBody.velocity, &ball->rigidBody.velocity, ball->targetSpeed / currentSpeed); } + soundPlayerUpdatePosition(ball->soundLoopId, &ball->rigidBody.transform.position, &ball->rigidBody.velocity); + ball->rigidBody.angularVelocity = gOneVec; dynamicSceneSetRoomFlags(ball->dynamicId, ROOM_FLAG_FROM_INDEX(ball->rigidBody.currentRoom)); @@ -174,6 +182,8 @@ void ballUpdate(struct Ball* ball) { ball->targetSpeed = 0.0f; collisionSceneRemoveDynamicObject(&ball->collisionObject); dynamicSceneRemove(ball->dynamicId); + soundPlayerStop(ball->soundLoopId); + ball->soundLoopId = SOUND_ID_NONE; } } @@ -197,6 +207,8 @@ void ballMarkCaught(struct Ball* ball) { ball->flags |= BallFlagsCaught; collisionSceneRemoveDynamicObject(&ball->collisionObject); rigidBodyMarkKinematic(&ball->rigidBody); + soundPlayerStop(ball->soundLoopId); + ball->soundLoopId = SOUND_ID_NONE; } int isColliderForBall(struct CollisionObject* collisionObject) { diff --git a/src/scene/ball.h b/src/scene/ball.h index 3dd346c..71b4ca1 100644 --- a/src/scene/ball.h +++ b/src/scene/ball.h @@ -28,6 +28,7 @@ struct Ball { float lifetime; short dynamicId; short flags; + short soundLoopId; }; void ballBurnMarkInit();