Add project files.

This commit is contained in:
2018-06-25 21:48:45 -04:00
parent b04a25689b
commit 3c1b7d28e8
425 changed files with 35333 additions and 0 deletions
@@ -0,0 +1,126 @@
#include "cAudio.hpp"
/*** Custom Header Files ***/
#include "../UtilityEngine/cUtility.hpp"
using AudioEngine::cAudio;
using UtilityEngine::cUtility;
/*static*/ cAudio* cAudio::sp_inst = nullptr;
cAudio::cAudio()
: m_rate(22050), m_format(AUDIO_S16), m_channels(2), m_buffers(4096)
{}
cAudio::~cAudio()
{
CleanUp();
}
//Functions
/*static*/ cAudio& cAudio::Inst()
{
if (sp_inst == nullptr)
sp_inst = new cAudio();
return *sp_inst;
}
/*static*/ void cAudio::Delete()
{
delete sp_inst;
sp_inst = nullptr;
}
const bool cAudio::Initialize() const
{
bool rtn = IsInit();
if (rtn == false) {
if(SDL_InitSubSystem(SDL_INIT_AUDIO) == 0) {
cUtility::Inst().Message("Audio initialized.");
rtn = true;
} else
cUtility::Inst().Message("Could not initialize Audio. SDL_InitSubSystem(SDL_INIT_AUDIO):", __AT__, cUtility::eTypeSDL::SDL);
}
return rtn;
}
void cAudio::Setup()
{
CleanUp();
if (Mix_OpenAudio(m_rate, Uint16(m_format), m_channels, m_buffers) < 0)
cUtility::Inst().Message("Could not setup mixer. Mix_OpenAudio():", __AT__, cUtility::eTypeSDL::MIXER);
//Mix_AllocateChannels(number_of_mixing_channels);
}
void cAudio::CleanUp()
{
Mix_CloseAudio();
}
void cAudio::SoundPlay()
{
}
void cAudio::MusicPlay()
{
}
///Sets
void cAudio::setRate( const unsigned long int rate /*= 22050*/ )
{
m_rate = rate;
}
void cAudio::setFormat( const unsigned long int format /*= AUDIO_S16*/ )
{
m_format = format;
}
void cAudio::setChannels( const unsigned long int channels /*= 2*/ )
{
m_channels = channels;
}
void cAudio::setBuffers( const unsigned long int buffers /*= 4096*/ )
{
m_buffers = buffers;
}
///Gets
const bool cAudio::IsInit() const
{
bool rtn = false;
if (SDL_WasInit(SDL_INIT_AUDIO) != 0) {
cUtility::Inst().Message("Audio is initialized.");
rtn = true;
} else
cUtility::Inst().Message("Audio is not initialized.");
return rtn;
}
const unsigned long int cAudio::getRate() const
{
return m_rate;
}
const unsigned long int cAudio::getFormat() const
{
return m_format;
}
const unsigned long int cAudio::getChannels() const
{
return m_channels;
}
const unsigned long int cAudio::getBuffers() const
{
return m_buffers;
}
@@ -0,0 +1,72 @@
#ifndef _CAUDIO_HPP_
#define _CAUDIO_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_mixer.h>
/*** DLL Header File ***/
#include "dllExport.h"
namespace AudioEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cAudio
{
private:
cAudio();
~cAudio();
public:
//Functions
static cAudio& Inst();
static void Delete();
const bool Initialize() const;
/* Sets up the audio */
void Setup();
/* Cleans up */
void CleanUp();
/* Plays the sounds */
void SoundPlay();
/* Plays the music */
void MusicPlay();
///Set
/* Sets the rate */
void setRate( const unsigned long int rate = 22050 );
/* Sets the audio format */
void setFormat( const unsigned long int format = AUDIO_S16 );
/* Sets the channels */
void setChannels( const unsigned long int channels = 2 );
/* Sets the buffer */
void setBuffers( const unsigned long int buffers = 4096 );
///Get
/* Gets return true if Audio was initialized */
const bool IsInit() const;
/* Gets the rate */
const unsigned long int getRate() const;
/* Gets the format */
const unsigned long int getFormat() const;
/* Gets the channels */
const unsigned long int getChannels() const;
/* Gets the buffers */
const unsigned long int getBuffers() const;
private:
private:
///Variables
unsigned long int m_rate;// = 22050;
unsigned long int m_format;// = AUDIO_S16;
unsigned long int m_channels;// = 2;
unsigned long int m_buffers;// = 4096;
static cAudio* sp_inst;// = nullptr;
};/// END CLASS DEFINITION cAudio
}/// END NAMESPACE DEFINITION AudioEngine
#endif/// END IFNDEF _CAUDIO_HPP_
@@ -0,0 +1,40 @@
#include "cMusic.hpp"
using AudioEngine::cMusic;
cMusic::cMusic()
{}
/* Copy constructor */
cMusic::cMusic(const cMusic& copy)
{
copy;
}
cMusic::~cMusic()
{}
///Functions
/* Plays the music if loaded */
void cMusic::PlayMusic()
{}
/* Fades in the music for time */
void cMusic::FadeIn(const unsigned int time /*= 1000*/) const
{
time;
}
/* Fades out the music for time */
void cMusic::FideOut(const unsigned int time /*= 1000*/) const
{
time;
}
/* private:*/
///Functions
void cMusic::LoadMusic()
{}
void cMusic::UnloadMusic()
{}
@@ -0,0 +1,47 @@
#ifndef _CMUSIC_HPP_
#define _CMUSIC_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_mixer.h>
/*** Custom Header Files ***/
//#include "cAudio.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
#include "cSound.hpp"
namespace AudioEngine {
class EXPORT_FROM_MYDLL cMusic
{
public:
cMusic();
/* Copy constructor */
cMusic( const cMusic& copy );
~cMusic();
///Functions
/* Plays the music if loaded */
void PlayMusic();
/* Fades in the music for time */
void FadeIn( const unsigned int time = 1000 ) const;
/* Fades out the music for time */
void FideOut( const unsigned int time = 1000 ) const;
private:
///Functions
void LoadMusic();
void UnloadMusic();
private:
///Variables
Mix_Music* mp_music;
unsigned char m_volume;// = 255
};/// END CLASS DEFINITION cMusic
}/// END NAMESPACE DEFINITION AudioEngine
#endif/// END IFNDEF _CMUSIC_HPP_
@@ -0,0 +1,154 @@
#include "cSound.hpp"
/*** Custom Header Files ***/
#include "../UtilityEngine/cUtility.hpp"
using AudioEngine::cSound;
using UtilityEngine::cUtility;
cSound::cSound( const cString& dir /*= ""*/, const cString& filename /*= ""*/, const unsigned char volume /*= 255*/,
const unsigned char distance /*= 100*/, const short int angle /*= 0*/, const long int channel /*= -1*/,
const long int loops /*= -1*/ )
: mp_sound(nullptr), m_dir(dir), m_fileName(filename), m_volume(volume), m_distance(distance),
m_angle(angle), m_channel(channel), m_loops(loops)
{
if (m_fileName != "")
LoadSound();
}
cSound::cSound( const cSound& copy )
: mp_sound(nullptr), m_dir(copy.getDir()), m_fileName(copy.getFileName()), m_volume(copy.getVolume()),
m_distance(copy.getDistance()), m_angle(copy.getAngle()), m_channel(copy.getChannel()),
m_loops(copy.getLoops())
{
if (m_fileName != "")
LoadSound();
}
cSound::~cSound()
{
UnloadSound();
}
void cSound::PlaySound()
{
if (mp_sound != nullptr) {
if (Mix_Volume(m_channel, m_volume) < 0)
cUtility::Inst().Message("Unable to set volume. Mix_Volume():", __AT__, cUtility::eTypeSDL::MIXER);
if (Mix_SetPosition(m_channel, m_angle, m_distance) < 0)
cUtility::Inst().Message("Unable to set position. Mix_SetPosition():", __AT__, cUtility::eTypeSDL::MIXER);
if (Mix_PlayChannel(m_channel, mp_sound, m_loops) < 0)
cUtility::Inst().Message("Unable to set channel. Mix_PlayChannel():", __AT__, cUtility::eTypeSDL::MIXER);
}
}
void cSound::FadeIn( const unsigned int time /*= 1000*/ ) const
{
if (Mix_FadeInChannel(m_channel, mp_sound, m_loops, time) < 0)
cUtility::Inst().Message("Unable to fade in channel. Mix_FadeInChannel():", __AT__, cUtility::eTypeSDL::MIXER);
}
void cSound::FadeOut( const unsigned int time /*= 1000*/ ) const
{
if (Mix_FadeOutChannel(m_channel, time) < 0)
cUtility::Inst().Message("Unable to fade out channel. Mix_FadeOutChannel():", __AT__, cUtility::eTypeSDL::MIXER);
}
///Sets
void cSound::setDir( const cString& dir )
{
m_dir = dir;
}
void cSound::setFileName( const cString& filename )
{
m_fileName = filename;
LoadSound();
}
void cSound::setFileNameandDir( const cString& filename, const cString& dir /*= ""*/ )
{
setDir(dir);
setFileName(filename);
}
void cSound::setVolume( const unsigned char volume /*= 255*/ )
{
m_volume = volume;
}
void cSound::setDistance( const unsigned char distance /*= 100*/ )
{
m_distance = distance;
}
void cSound::setAngle( const short int angle /*= 0*/ )
{
m_angle = angle;
}
void cSound::setChannel( const long int channel /*= -1*/ )
{
m_channel = channel;
}
void cSound::setLoops( const long int loops /*= -1*/ )
{
m_loops = loops;
}
///Gets
const cString cSound::getDir() const
{
return m_dir;
}
const cString cSound::getFileName() const
{
return m_fileName;
}
const unsigned char cSound::getVolume() const
{
return m_volume;
}
const unsigned char cSound::getDistance() const
{
return m_distance;
}
const short int cSound::getAngle() const
{
return m_angle;
}
const long int cSound::getChannel() const
{
return m_channel;
}
const long int cSound::getLoops() const
{
return m_loops;
}
///Private
///Functions
void cSound::LoadSound()
{
UnloadSound();
if (m_fileName != "")
if (mp_sound == nullptr)
if ((mp_sound = Mix_LoadWAV(((cString)(m_dir + m_fileName)).c_str())) == nullptr)
cUtility::Inst().Message("Unable to load file. " + m_dir + m_fileName, "", cUtility::eTypeSDL::MIXER);
}
void cSound::UnloadSound()
{
if (mp_sound != nullptr)
{
Mix_FreeChunk(mp_sound);
mp_sound = nullptr;
}
}
@@ -0,0 +1,91 @@
#ifndef _CSOUND_HPP_
#define _CSOUND_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
#include <SDL_mixer.h>
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
namespace AudioEngine {
class EXPORT_FROM_MYDLL cSound
{
public:
cSound( const cString& dir = "", const cString& filename = "", const unsigned char volume = 255,
const unsigned char distance = 100, const short int angle = 0, const long int channel = -1,
const long int loops = -1 );
/* Copy constructor */
cSound( const cSound& copy );
~cSound();
///Functions
/* Plays the sound if loaded */
void PlaySound();
/* Fades in the sound for time */
void FadeIn( const unsigned int time = 1000 ) const;
/* Fades out the sound for time */
void FadeOut( const unsigned int time = 1000 ) const;
///Sets
/* Sets the directory of the sound */
void setDir( const cString& dir );
/* Sets the file name of the sound */
void setFileName( const cString& filename );
/* Sets the file name and the directory of the sound */
void setFileNameandDir( const cString& filename, const cString& dir = "" );
/* Sets the Volume of the sound */
void setVolume( const unsigned char volume = 255 );
/* Sets the Distance of the sound */
void setDistance( const unsigned char distance = 100 );
/* Sets the Angle of the sound */
void setAngle( const short int angle = 0 );
/* Sets the Channel of the sound */
void setChannel( const long int channel = -1);
/* Sets how many times the sound loops */
void setLoops( const long int loops = -1 );
///Gets
/* Gets the directory of the sound */
const cString getDir() const;
/* Gets the file name of the sound */
const cString getFileName() const;
/* Gets the Volume of the sound */
const unsigned char getVolume() const;
/* Gets the Distance of the sound */
const unsigned char getDistance() const;
/* Gets the Angle of the sound */
const short int getAngle() const;
/* Gets the Channel of the sound */
const long int getChannel() const;
/* Gets how many times the sound loops */
const long int getLoops() const;
private:
///Functions
void LoadSound();
void UnloadSound();
private:
///Variables
Mix_Chunk* mp_sound;// = nullptr
cString m_dir;// = ""
cString m_fileName;// = ""
unsigned char m_volume;// = 255
unsigned char m_distance;// = 100
short int m_angle;// = 0
long int m_channel;// = -1
long int m_loops;// = 0
};/// END CLASS DEFINITION cSound
}/// END NAMESPACE DEFINITION AudioEngine
#endif/// END IFNDEF _CSOUND_HPP_