-
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.
- Loading branch information
1 parent
c7d15fb
commit f7a2941
Showing
9 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
Empty file.
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
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,75 @@ | ||
#include"SoundEffect.h" | ||
#include<SDL2/SDL.h> | ||
#include<SDL2/SDL_mixer.h> | ||
#include<string> | ||
#include<iostream> | ||
#include<memory> | ||
|
||
SoundEffect::SoundEffect () | ||
{ | ||
// initialize variables | ||
mMusic = NULL ; | ||
} | ||
|
||
SoundEffect :: SoundEffect( std :: string filename ) | ||
{ | ||
// initialize variables | ||
mMusic = NULL ; | ||
loadMusic( filename ) ; | ||
|
||
} | ||
|
||
SoundEffect::~SoundEffect() | ||
{ | ||
// Deallocate | ||
free(); | ||
} | ||
|
||
// SoundEffect::SoundEffect(const std::string &path, int volume) | ||
// : chunk(Mix_LoadWAV(path.c_str()), Mix_FreeChunk) { | ||
// if (!chunk.get()) { | ||
// // LOG("Couldn't load audio sample: ", path); | ||
// } | ||
|
||
// Mix_VolumeChunk(chunk.get(), volume); | ||
// } | ||
|
||
bool SoundEffect::loadMusic( std :: string filename ) | ||
{ | ||
// get rid of pre-existing music | ||
free() ; | ||
std::cout << "loading music...\n" ; | ||
mMusic = Mix_LoadWAV( filename.c_str() ) ; | ||
if( mMusic == NULL ) { | ||
printf( "Failed to load music!\n" ); | ||
std::cout << Mix_GetError() << "\n" ; | ||
return false ; | ||
} | ||
std::cout << "loaded music...\n" ; | ||
return true ; | ||
|
||
} | ||
|
||
void SoundEffect::free() | ||
{ | ||
// Free music if it exists | ||
if (mMusic != NULL) | ||
{ | ||
//Free the sound effects | ||
Mix_FreeChunk( mMusic ) ; | ||
mMusic = NULL ; | ||
|
||
} | ||
} | ||
|
||
void SoundEffect::play() | ||
{ | ||
int channel = Mix_PlayChannel( -1, mMusic , 0 ) ; | ||
if( channel == -1 ){ | ||
printf("Mix_PlayChannel: %s\n",Mix_GetError()); | ||
}else{ | ||
std::cout << "playing on channel " << channel << "\n" ; | ||
} | ||
SDL_Delay(1000) ; | ||
// Mix_PlayChannel(-1, chunk.get(), 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,20 @@ | ||
#include<SDL2/SDL.h> | ||
#include<SDL2/SDL_mixer.h> | ||
#include<string> | ||
#include<memory> | ||
|
||
class SoundEffect | ||
{ | ||
public: | ||
SoundEffect() ; | ||
SoundEffect( std :: string filename ) ; | ||
// SoundEffect( const std::string &path, int volume ) ; | ||
~SoundEffect() ; | ||
bool loadMusic( std :: string filename ) ; | ||
void free(); | ||
void play() ; | ||
private: | ||
Mix_Chunk *mMusic ; | ||
// std::unique_ptr<Mix_Chunk, void (*)(Mix_Chunk *)> chunk; | ||
|
||
} ; |
Binary file not shown.