-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transparencies are working. Hitting b will turn them on. Need to chan…
…ge this though Sound works. Currently have sound when rotating and moving left and right. Background music also works but is turned off by default
- Loading branch information
Krishna
committed
Mar 20, 2010
1 parent
b4706cc
commit 5879522
Showing
12 changed files
with
856 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* *************************************************************** | ||
* | ||
* File : SoundManager.cpp | ||
* | ||
* Author : Tiberiu Popa | ||
* J. Alexander Clarke | ||
* Date : June 18th, 2002 | ||
* | ||
* Modified: | ||
* | ||
* Purpose: Implementation of the sound manager | ||
* | ||
* ****************************************************************/ | ||
#pragma implementation | ||
#include "SoundManager.hpp" | ||
#include <stdlib.h> | ||
|
||
|
||
SoundManager SM; | ||
|
||
SoundManager::SoundManager(){ | ||
|
||
nSounds = 0; | ||
nMusics = 0; | ||
|
||
// initialize the sound library | ||
SDL_Init(SDL_INIT_AUDIO /*| SDL_INIT_VIDEO */); | ||
|
||
/* sound setup */ | ||
int audio_rate = 44100; | ||
Uint16 audio_format = AUDIO_S16; | ||
int audio_channels = 2; | ||
int audio_buffers = 4096; | ||
|
||
// open the audio stream | ||
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) { | ||
printf("Unable to open audio!\n"); | ||
exit(1); | ||
} | ||
} | ||
|
||
SoundManager::~SoundManager(){ | ||
} | ||
|
||
|
||
/* *************** Manipulate Sound Chunks *******************/ | ||
|
||
int SoundManager::ResetSound(int snd){ | ||
if(snd<0 || snd>=nSounds) return -1; | ||
|
||
Mix_HaltChannel(channel[snd]); | ||
channel[snd] = -1; | ||
|
||
return 0; | ||
} | ||
|
||
int SoundManager::LoadSound(char* file){ | ||
|
||
chunks[nSounds] = Mix_LoadWAV(file); | ||
channel[nSounds] = -1; | ||
|
||
nSounds+=1; | ||
return nSounds - 1; | ||
|
||
} | ||
|
||
int SoundManager::PlaySound(int snd){ | ||
if(snd<0 && snd>=nSounds) return -1; | ||
channel[snd] = Mix_PlayChannel(-1, chunks[snd], 0 /*-1*/); | ||
return 0; | ||
} | ||
|
||
int SoundManager::StopSound(int snd){ | ||
if(snd<0 && snd>=nSounds) return -1; | ||
ResetSound(snd); | ||
return 0; | ||
} | ||
|
||
int SoundManager::PauseSound(int snd){ | ||
if(snd<0 && snd>=nSounds) return -1; | ||
Mix_Pause(channel[snd]); | ||
return 0; | ||
} | ||
|
||
int SoundManager::ResumeSound(int snd){ | ||
if(snd<0 && snd>=nSounds) return -1; | ||
Mix_Resume(channel[snd]); | ||
return 0; | ||
} | ||
|
||
|
||
/* *************** Manipulate Music *******************/ | ||
|
||
int SoundManager::ResetMusic(int snd){ | ||
if(snd<0 || snd>=nMusics) return -1; | ||
|
||
Mix_HaltMusic(); | ||
|
||
return 0; | ||
} | ||
|
||
int SoundManager::LoadMusic(char* file){ | ||
|
||
music[nMusics] = Mix_LoadMUS(file); | ||
if(!music[nMusics]) | ||
{ | ||
printf("Mix_LoadMUS(\"music.mp3\"): %s\n", Mix_GetError()); | ||
// this might be a critical error... | ||
} | ||
nMusics+=1; | ||
return nMusics - 1; | ||
|
||
} | ||
|
||
int SoundManager::PlayMusic(int snd){ | ||
if(snd<0 && snd>=nMusics) return -1; | ||
//Mix_PlayMusic(music[snd], 1 /*-1*/); | ||
|
||
if(Mix_PlayMusic(music[snd], -1)==-1) | ||
{ | ||
printf("Mix_PlayMusic: %s\n", Mix_GetError()); | ||
// well, there's no music, but most games don't break without music... | ||
} | ||
return 0; | ||
} | ||
|
||
int SoundManager::StopMusic(int snd){ | ||
if(snd<0 && snd>=nMusics) return -1; | ||
ResetMusic(snd); | ||
return 0; | ||
} | ||
|
||
int SoundManager::PauseMusic(int snd){ | ||
if(snd<0 && snd>=nMusics) return -1; | ||
Mix_PauseMusic(); | ||
return 0; | ||
} | ||
|
||
int SoundManager::ResumeMusic(int snd){ | ||
if(snd<0 && snd>=nMusics) return -1; | ||
Mix_ResumeMusic(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* *************************************************************** | ||
* | ||
* File : SoundManager.h | ||
* | ||
* Author : Tiberiu Popa | ||
* J. Alexander Clarke | ||
* Date : June 18th, 2002 | ||
* | ||
* Modified: | ||
* | ||
* Purpose: Header file for the sound manager | ||
* | ||
* ****************************************************************/ | ||
#ifndef _SOUND_MANAGER__H | ||
#define _SOUND_MANAGER__H | ||
#pragma interface | ||
|
||
// include SDL header files | ||
#include "SDL.h" | ||
#include "SDL_mixer.h" | ||
|
||
// if you want more than 100 sounds, change the MAX_SOUND | ||
#define MAX_SOUNDS 100 | ||
#define MAX_MUSIC 100 | ||
|
||
// wrapper calss around SDL and SDL_mixer libraries | ||
class SoundManager { | ||
public: | ||
SoundManager(); | ||
~SoundManager(); | ||
|
||
// manipulating sound clips | ||
// sound clips can be played simultaneously | ||
int LoadSound(char* file); | ||
|
||
// snd is the sound ID returned by LoadSound | ||
int PlaySound(int snd); | ||
int StopSound(int snd); | ||
int PauseSound(int snd); | ||
int ResumeSound(int snd); | ||
|
||
// manipulating music clips | ||
// should have only one music clip | ||
|
||
int LoadMusic(char* file); | ||
|
||
int PlayMusic(int); | ||
int StopMusic(int); | ||
int PauseMusic(int); | ||
int ResumeMusic(int); | ||
|
||
private: | ||
|
||
// internal data | ||
|
||
// sound clips | ||
Mix_Chunk * chunks[MAX_SOUNDS]; | ||
Mix_Music *music[MAX_MUSIC]; | ||
|
||
// sound channels for active sounds | ||
int channel[MAX_SOUNDS]; | ||
|
||
// number of sound clips loaded | ||
int nSounds; | ||
int nMusics; | ||
|
||
int ResetSound(int snd); | ||
int ResetMusic(int snd); | ||
}; | ||
|
||
|
||
// the global instance of the sound manager | ||
extern SoundManager SM; | ||
|
||
|
||
#endif // _SOUND_MANAGER__H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.