Operation Null Mind 0.4.1
A 2D roguelike top down shooter game made with SDL2
 
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1
11#ifndef sound
12#define sound
13
14#include <SDL_mixer.h>
15#include <stdbool.h>
16
17
18#define MAX_MUSIC_QUEUE_SIZE 20
19
20typedef enum {
21 SOUND_SWOOSH, // Swoosh sound (Assets/Audio/SoundEffect/swoosh.wav)
22 SOUND_GUNSHOT, // Gun firing sound (Assets/Audio/SoundEffect/gunshot.wav)
23 SOUND_VINE_BOOM, // Vine boom sound (Assets/Audio/SoundEffect/VineBoom.wav)
24 SOUND_BOOST_UP, // Boost sound (Assets/Audio/SoundEffect/boost up.wav)
25 SOUND_BUFFING, // Buffing sound (Assets/Audio/SoundEffect/buffing.wav)
26 SOUND_CRATE_OPENING, // Crate opening sound (Assets/Audio/SoundEffect/crate opening.wav)
27 SOUND_DASH, // Dash movement sound (Assets/Audio/SoundEffect/dash.wav)
28 SOUND_ELEVATOR_CLOSE, // Elevator closing sound (Assets/Audio/SoundEffect/elevator close.wav)
29 SOUND_ELEVATOR_OPEN, // Elevator opening sound (Assets/Audio/SoundEffect/elevator open.wav)
30 SOUND_ENEMY_HEALING, // Enemy healing sound (Assets/Audio/SoundEffect/enemy healing.wav)
31 SOUND_ENERGY_GUNSHOT, // Energy weapon firing (Assets/Audio/SoundEffect/Energy Gunshot.wav)
32 SOUND_EXPLOSION, // Explosion sound (Assets/Audio/SoundEffect/explosion.wav)
33 SOUND_GRENADE_LAUNCHER, // Grenade launcher sound (Assets/Audio/SoundEffect/grenade launcher.wav)
34 SOUND_GUN_PICKUP, // Gun pickup sound (Assets/Audio/SoundEffect/gun pickup.wav)
35 SOUND_HITMARKER, // Hit confirmation sound (Assets/Audio/SoundEffect/hitmarker.wav)
36 SOUND_KAMIKAZE_BEEP, // Kamikaze enemy beeping (Assets/Audio/SoundEffect/kamikaze beep.wav)
37 SOUND_LAST_STAND, // Last Stand ability depletion (Assets/Audio/SoundEffect/Last Stand Used Up.wav)
38 SOUND_PARRY, // Parry sound effect (Assets/Audio/SoundEffect/parry.wav)
39 SOUND_PASSIVE_OBTAINED, // Passive ability acquired (Assets/Audio/SoundEffect/passive obtained.wav)
40 SOUND_PLAYER_HEALING, // Player healing sound (Assets/Audio/SoundEffect/player healing.wav)
41 SOUND_PLAYER_HURT, // Player damage sound (Assets/Audio/SoundEffect/player hurt.wav)
42 SOUND_RECALL, // Recall ability sound (Assets/Audio/SoundEffect/recall.wav)
43 SOUND_ROCKET_LAUNCH, // Rocket launcher sound (Assets/Audio/SoundEffect/rocket launch.wav)
44 SOUND_SENTRY_LASER, // Sentry weapon firing (Assets/Audio/SoundEffect/Sentry Laser Cannon.wav)
45 SOUND_SPAWN_IN, // Player/enemy spawn sound (Assets/Audio/SoundEffect/spawn in.wav)
46 SOUND_VANTAGE_LASER, // Vantage laser firing (Assets/Audio/SoundEffect/vantage laser gunshot.wav)
47 SOUND_BOOST_DOWN, // Boost down sound (Assets/Audio/SoundEffect/boost down.wav)
48 SOUND_HOVER, // Hover sound (Assets/Audio/SoundEffect/hover.wav)
49 SOUND_ARMOR_PISTOL, // Armor Pistol sound (Assets/Audio/SoundEffect/Armor Pistol.wav)
50 SOUND_ASSAULT_RIFLE, // Assault Rifle sound (Assets/Audio/SoundEffect/Assault Rifle.wav)
51 SOUND_AUTO_SHOTGUN, // Auto Shotgun sound (Assets/Audio/SoundEffect/Auto Shotgun.wav)
52 SOUND_BATTLE_RIFLE, // Battle Rifle sound (Assets/Audio/SoundEffect/Battle Rifle.wav)
53 SOUND_BULLPUP_RIFLE, // Bullpup Rifle sound (Assets/Audio/SoundEffect/Bullpup Rifle.wav)
54 SOUND_BURST_RIFLE, // Burst Rifle sound (Assets/Audio/SoundEffect/Burst Rifle.wav)
55 SOUND_PDW, // PDW sound (Assets/Audio/SoundEffect/PDW.wav)
56 SOUND_PISTOL, // Pistol sound (Assets/Audio/SoundEffect/Pistol.wav)
57 SOUND_RAPID_SMG, // Rapid SMG sound (Assets/Audio/SoundEffect/Rapid SMG.wav)
58 SOUND_REVOLVER, // Revolver sound (Assets/Audio/SoundEffect/Revolver.wav)
59 SOUND_SELECT, // Select sound (Assets/Audio/SoundEffect/select.wav)
60 SOUND_SHOTGUN, // Shotgun sound (Assets/Audio/SoundEffect/Shotgun.wav)
61 SOUND_SMG, // SMG sound (Assets/Audio/SoundEffect/SMG.wav)
62 SOUND_GUN_JAM, // Gun jam sound (Assets/Audio/SoundEffect/gun jamming.wav)
63
64 SOUND_COUNT // Total number of sound effects (automatically updated)
66
67
68typedef struct SimpleQueue {
69 char* currentSongPath; // Path to the currently playing song
70 char* nextSongPath; // Path to the next song (NULL if none queued)
71 bool hasNextSong; // Flag to indicate if there's a next song
73
74// Sound resources structure
75typedef struct SoundResources {
76 Mix_Music* backgroundMusic;
77 Mix_Music* nextMusic; // Pointer to the next music to be played
78 Mix_Chunk* soundEffects[SOUND_COUNT]; // Array to store sound effects, add more if needed.
79 char* soundPaths[SOUND_COUNT]; // Array to store sound paths, add more if needed.
80 SimpleQueue musicQueue; // Queue for music playback
82
83typedef struct Sound {
84 Mix_Chunk* chunk;
85 int channel;
87
89
90// Function declarations
93void Sound_Play_Music(const char* path, int loops);
94void Sound_Play_Effect(int index);
95float Sound_Get_Music_Duration(const char* path);
96void Sound_Stop_Music();
98bool Sound_Queue_Next_Song(const char* path);
101void Sound_Set_Max_Channels(int numChannels);
102
103#endif
void Sound_Play_Music(const char *path, int loops)
[Update] Update Sound_Play_Music to free previous music
Definition sound.c:240
SoundEffect
Definition sound.h:20
@ SOUND_VINE_BOOM
Definition sound.h:23
@ SOUND_GUN_PICKUP
Definition sound.h:34
@ SOUND_GRENADE_LAUNCHER
Definition sound.h:33
@ SOUND_PLAYER_HEALING
Definition sound.h:40
@ SOUND_PDW
Definition sound.h:55
@ SOUND_COUNT
Definition sound.h:64
@ SOUND_ENEMY_HEALING
Definition sound.h:30
@ SOUND_VANTAGE_LASER
Definition sound.h:46
@ SOUND_HITMARKER
Definition sound.h:35
@ SOUND_REVOLVER
Definition sound.h:58
@ SOUND_ENERGY_GUNSHOT
Definition sound.h:31
@ SOUND_PLAYER_HURT
Definition sound.h:41
@ SOUND_GUNSHOT
Definition sound.h:22
@ SOUND_SENTRY_LASER
Definition sound.h:44
@ SOUND_BUFFING
Definition sound.h:25
@ SOUND_HOVER
Definition sound.h:48
@ SOUND_GUN_JAM
Definition sound.h:62
@ SOUND_ARMOR_PISTOL
Definition sound.h:49
@ SOUND_RAPID_SMG
Definition sound.h:57
@ SOUND_DASH
Definition sound.h:27
@ SOUND_BOOST_UP
Definition sound.h:24
@ SOUND_SMG
Definition sound.h:61
@ SOUND_ELEVATOR_OPEN
Definition sound.h:29
@ SOUND_AUTO_SHOTGUN
Definition sound.h:51
@ SOUND_BURST_RIFLE
Definition sound.h:54
@ SOUND_RECALL
Definition sound.h:42
@ SOUND_BATTLE_RIFLE
Definition sound.h:52
@ SOUND_EXPLOSION
Definition sound.h:32
@ SOUND_BOOST_DOWN
Definition sound.h:47
@ SOUND_SHOTGUN
Definition sound.h:60
@ SOUND_ROCKET_LAUNCH
Definition sound.h:43
@ SOUND_KAMIKAZE_BEEP
Definition sound.h:36
@ SOUND_ELEVATOR_CLOSE
Definition sound.h:28
@ SOUND_SWOOSH
Definition sound.h:21
@ SOUND_SPAWN_IN
Definition sound.h:45
@ SOUND_PASSIVE_OBTAINED
Definition sound.h:39
@ SOUND_PISTOL
Definition sound.h:56
@ SOUND_CRATE_OPENING
Definition sound.h:26
@ SOUND_PARRY
Definition sound.h:38
@ SOUND_BULLPUP_RIFLE
Definition sound.h:53
@ SOUND_LAST_STAND
Definition sound.h:37
@ SOUND_SELECT
Definition sound.h:59
@ SOUND_ASSAULT_RIFLE
Definition sound.h:50
void Music_Finished_Callback()
[Callback] Called when music finishes playing Plays the next queued song if available
Definition sound.c:189
void Sound_Play_Effect(int index)
[Utility] Play sound effect
Definition sound.c:131
float Sound_Get_Music_Duration(const char *path)
Definition sound.c:138
void Sound_Stop_Music()
[Utility] Stop background music
Definition sound.c:153
bool Sound_Load_Resources()
Definition sound.c:100
bool Sound_Queue_Next_Song(const char *path)
[Utility] Queue a single song to play next
Definition sound.c:208
SoundResources soundResources
Definition sound.c:31
bool Sound_System_Initialize()
Definition sound.c:85
void Sound_Set_Max_Channels(int numChannels)
Sets the maximum number of sound effect channels.
Definition sound.c:26
void Sound_Clear_Queue()
[Utility] Clear the queued song
Definition sound.c:227
void Sound_System_Cleanup()
[Quit] Clean up sound resources
Definition sound.c:160
Definition sound.h:68
bool hasNextSong
Definition sound.h:71
char * nextSongPath
Definition sound.h:70
char * currentSongPath
Definition sound.h:69
Definition sound.h:75
char * soundPaths[SOUND_COUNT]
Definition sound.h:79
Mix_Music * backgroundMusic
Definition sound.h:76
Mix_Music * nextMusic
Definition sound.h:77
SimpleQueue musicQueue
Definition sound.h:80
Mix_Chunk * soundEffects[SOUND_COUNT]
Definition sound.h:78
Definition sound.h:83
Mix_Chunk * chunk
Sound effect chunk.
Definition sound.h:84
int channel
Channel on which the sound is played.
Definition sound.h:85