diff options
author | Charadon <dev@iotib.net> | 2022-06-07 04:10:17 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-06-07 04:10:17 -0400 |
commit | e3daf6b1f38d6934ec85d78a2cad9d58dbe8d3ac (patch) | |
tree | 2e76f9a9fc6c60ee437f46246ec84a5561dc0d60 /src | |
parent | f9448aa3ecbe76d80992982cb84aa42102e7c951 (diff) | |
download | Pong-C-e3daf6b1f38d6934ec85d78a2cad9d58dbe8d3ac.tar.gz |
Beginning migration to SDL for sound
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 36 | ||||
-rw-r--r-- | src/pong.h | 2 | ||||
-rw-r--r-- | src/sounds.h | 15 |
3 files changed, 32 insertions, 21 deletions
diff --git a/src/main.c b/src/main.c index 56fda9d..fcdd3b3 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,8 @@ #include "pong.h" #include "sounds.h" +#include <SDL2/SDL.h> +#include <SDL2/SDL_audio.h> +#include <SDL2/SDL_mixer.h> int Difficulty = 1; @@ -25,13 +28,17 @@ int internal_clock() { int audio() { int i; - InitAudioDevice(); - Sound Bounce = LoadSound("resources/bounce.wav"); - Sound TitleScreen = LoadSound("resources/title.wav"); - Sound Victory = LoadSound("resources/victory.wav"); - Sound Defeat = LoadSound("resources/defeat.wav"); - Sound PlayerScore = LoadSound("resources/score_player.wav"); - Sound EnemyScore = LoadSound("resources/score_enemy.wav"); + SDL_Init(SDL_INIT_AUDIO); + Mix_Init(0); + Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 1024); + Mix_AllocateChannels(64); + Mix_Volume(-1, 128); + Mix_Chunk *Bounce = Mix_LoadWAV("resources/bounce.wav"); + Mix_Chunk *TitleScreen = Mix_LoadWAV("resources/title.wav"); + Mix_Chunk *Victory = Mix_LoadWAV("resources/victory.wav"); + Mix_Chunk *Defeat = Mix_LoadWAV("resources/defeat.wav"); + Mix_Chunk *PlayerScore = Mix_LoadWAV("resources/score_player.wav"); + Mix_Chunk *EnemyScore = Mix_LoadWAV("resources/score_enemy.wav"); const struct timespec Delay = { 0, 20000000 }; @@ -41,25 +48,25 @@ int audio() { if(AudioQueue[i] != -1){ switch(AudioQueue[i]) { case 0: //Play bounce sound. - PlaySoundMulti(Bounce); + Mix_PlayChannel(-1, Bounce, 0); break; case 1: //Play game over - PlaySoundMulti(Defeat); + Mix_PlayChannel(-1, Defeat, 0); break; case 2: //Play win - PlaySoundMulti(Victory); + Mix_PlayChannel(-1, Victory, 0); break; case 3: //Title Screen - PlaySoundMulti(TitleScreen); + Mix_PlayChannel(-1, TitleScreen, 0); break; case 4: //Player Score - PlaySoundMulti(PlayerScore); + Mix_PlayChannel(-1, PlayerScore, 0); break; case 5: //Enemy Score - PlaySoundMulti(EnemyScore); + Mix_PlayChannel(-1, EnemyScore, 0); break; case 99: //Stop All Sounds - StopSoundMulti(); + Mix_HaltChannel(-1); break; default: break; @@ -71,6 +78,7 @@ int audio() { } thrd_sleep(&Delay, &Remaining); } + SDL_Quit(); thrd_exit(0); } diff --git a/src/pong.h b/src/pong.h index a425107..e933f97 100644 --- a/src/pong.h +++ b/src/pong.h @@ -2,6 +2,8 @@ #define PONG_H #define MOUSE_LEFT_BUTTON MOUSE_BUTTON_LEFT #include "raylib.h" +#include "SDL2/SDL.h" +#include "SDL2/SDL_mixer.h" #include <stdatomic.h> #include <stdio.h> #include <time.h> diff --git a/src/sounds.h b/src/sounds.h index 5a87cb1..3f5412c 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -1,12 +1,13 @@ #ifndef SOUNDS_H #define SOUNDS_H #include "pong.h" -const int SOUND_BOUNCE = 0; -const int MUSIC_DEFEAT = 1; -const int MUSIC_VICTORY = 2; -const int MUSIC_TITLE = 3; -const int SOUND_PLAYER_SCORE = 4; -const int SOUND_ENEMY_SCORE = 5; -const int STOP_ALL_SOUNDS = 99; + +#define SOUND_BOUNCE 0 +#define MUSIC_DEFEAT 1 +#define MUSIC_VICTORY 2 +#define MUSIC_TITLE 3 +#define SOUND_PLAYER_SCORE 4 +#define SOUND_ENEMY_SCORE 5 +#define STOP_ALL_SOUNDS 99 #endif |