-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new music file and a short sound clip for testing purposes. A…
…dded the ability to play sounds via a command (Now stores the sound in a command cache with highly-optimised move semantics)
- Loading branch information
Showing
8 changed files
with
132 additions
and
3 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
Binary file not shown.
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,52 @@ | ||
#include "audio.hpp" | ||
|
||
AudioClip::AudioClip(std::string filename): filename(filename) | ||
{ | ||
this->audioHandle = Mix_LoadWAV(this->filename.c_str()); | ||
} | ||
|
||
AudioClip::~AudioClip() | ||
{ | ||
Mix_FreeChunk(this->audioHandle); | ||
} | ||
|
||
void AudioClip::play() | ||
{ | ||
this->channel = Mix_PlayChannel(-1, this->audioHandle, 0); | ||
} | ||
|
||
int AudioClip::getChannel() const | ||
{ | ||
return this->channel; | ||
} | ||
|
||
AudioMusic::AudioMusic(std::string filename): filename(filename), paused(false) | ||
{ | ||
this->audioHandle = Mix_LoadMUS(this->filename.c_str()); | ||
} | ||
|
||
AudioMusic::~AudioMusic() | ||
{ | ||
Mix_FreeMusic(this->audioHandle); | ||
} | ||
|
||
void AudioMusic::play(bool priority) | ||
{ | ||
// if its a priority or we're not playing music, play this. | ||
if(priority || Mix_PlayingMusic() != 0) | ||
Mix_PlayMusic(this->audioHandle, -1); | ||
} | ||
|
||
void AudioMusic::setPaused(bool pause = true) | ||
{ | ||
this->paused = pause; | ||
if(this->paused) | ||
Mix_PauseMusic(); | ||
else | ||
Mix_ResumeMusic(); | ||
} | ||
|
||
void AudioMusic::togglePaused() | ||
{ | ||
this->setPaused(!this->paused); | ||
} |
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,33 @@ | ||
#ifndef AUDIO_HPP | ||
#define AUDIO_HPP | ||
#include <string> | ||
#include "SDL_mixer.h" | ||
|
||
class AudioClip | ||
{ | ||
public: | ||
AudioClip(std::string filename); | ||
~AudioClip(); | ||
void play(); | ||
int getChannel() const; | ||
private: | ||
int channel; | ||
const std::string filename; | ||
Mix_Chunk* audioHandle; | ||
}; | ||
|
||
class AudioMusic | ||
{ | ||
public: | ||
AudioMusic(std::string filename); | ||
~AudioMusic(); | ||
void play(bool priority = true); | ||
void setPaused(bool pause); | ||
void togglePaused(); | ||
private: | ||
bool paused; | ||
const std::string filename; | ||
Mix_Music* audioHandle; | ||
}; | ||
|
||
#endif |
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
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