diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 36 |
1 files changed, 22 insertions, 14 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); } |