SDL_mixer out, Audiere in
This commit is contained in:
parent
3f311298df
commit
72ad36108e
@ -19,6 +19,6 @@
|
||||
|
||||
#define USE_SDL_TTF
|
||||
#define USE_SDL_IMAGE
|
||||
#define USE_SDL_MIXER
|
||||
#define USE_AUDIERE
|
||||
|
||||
#endif //__ze_defines_h__
|
||||
|
@ -23,8 +23,8 @@
|
||||
#ifdef USE_SDL_TTF
|
||||
#include "SDL_ttf.h"
|
||||
#endif
|
||||
#ifdef USE_SDL_MIXER
|
||||
#include "SDL_mixer.h"
|
||||
#ifdef USE_AUDIERE
|
||||
#include "audiere.h"
|
||||
#endif
|
||||
|
||||
#include "zlib/unzip.h"
|
||||
|
@ -27,11 +27,6 @@ GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord);
|
||||
|
||||
void FreeImage(SDL_Surface *&image);
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
void FreeSound(Mix_Chunk *&chunk);
|
||||
void FreeMusic(Mix_Music *&music);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL_TTF
|
||||
void FreeFont(TTF_Font *&font);
|
||||
#endif
|
||||
|
@ -24,12 +24,12 @@ class ZRect;
|
||||
|
||||
enum ZErrorSeverity
|
||||
{
|
||||
ZERR_NOTE,
|
||||
ZERR_VERBOSE,
|
||||
ZERR_DEPRECIATED,
|
||||
ZERR_WARNING,
|
||||
ZERR_ERROR,
|
||||
ZERR_CRITICAL
|
||||
ZERR_CRITICAL,
|
||||
ZERR_NOTE
|
||||
};
|
||||
|
||||
enum ZErrorLogStyle
|
||||
@ -44,7 +44,7 @@ class ZEngine
|
||||
public:
|
||||
static VersionInfo Version;
|
||||
|
||||
private:
|
||||
private:
|
||||
static ZEngine *sInstance;
|
||||
SDL_Surface *mScreen;
|
||||
bool mFullscreen;
|
||||
@ -64,17 +64,15 @@ class ZEngine
|
||||
int mMouseX;
|
||||
int mMouseY;
|
||||
Uint8 mMouseB;
|
||||
ZErrorLogStyle mLogStyle;
|
||||
std::FILE *mErrlog;
|
||||
SDL_EventFilter mEventFilter;
|
||||
ZErrorLogStyle mLogStyle;
|
||||
ZErrorSeverity mMinSeverity;
|
||||
std::FILE *mErrlog;
|
||||
ZRandGen mRandGen;
|
||||
TiXmlDocument rZRF;
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
bool mSoundInitialized;
|
||||
int mSoundRate;
|
||||
bool mStereo;
|
||||
#endif
|
||||
#ifdef USE_AUDIERE
|
||||
audiere::AudioDevicePtr mAudiereDevice;
|
||||
#endif //USE_AUDIERE
|
||||
|
||||
ZEngine();
|
||||
|
||||
@ -84,14 +82,14 @@ class ZEngine
|
||||
static ZEngine* GetInstance();
|
||||
static void ReleaseInstance();
|
||||
|
||||
bool CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title="ZEngine Application",
|
||||
int soundRate=22050, bool stereo=false, std::string icon="");
|
||||
void InitErrorLog(ZErrorLogStyle logStyle=ZLOG_HTML, std::string logFile="errlog.html", ZErrorSeverity severityFilter=ZERR_VERBOSE);
|
||||
bool InitSound();
|
||||
bool CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title="ZEngine Application", std::string icon="");
|
||||
void CloseDisplay();
|
||||
void ToggleFullscreen();
|
||||
|
||||
SDL_Surface* Display();
|
||||
void Update();
|
||||
void Clear(Uint8 red=0, Uint8 green=0, Uint8 blue=0, Uint8 alpha=255);
|
||||
void ClearDisplay(Uint8 red=0, Uint8 green=0, Uint8 blue=0);
|
||||
|
||||
#if (GFX_BACKEND == ZE_OGL)
|
||||
void SetGL2D();
|
||||
@ -103,14 +101,14 @@ class ZEngine
|
||||
void UnpauseTimer();
|
||||
bool TimerIsPaused();
|
||||
|
||||
double GetFrameTime();
|
||||
double GetFrameSpeed();
|
||||
double GetFramerate();
|
||||
|
||||
bool IsActive();
|
||||
|
||||
void RequestQuit();
|
||||
bool QuitRequested();
|
||||
|
||||
|
||||
void SetReloadNeed(bool state);
|
||||
bool ImagesNeedReload();
|
||||
|
||||
@ -129,7 +127,6 @@ class ZEngine
|
||||
void CheckEvents();
|
||||
void SetEventFilter(SDL_EventFilter filter);
|
||||
|
||||
void SetErrorLog(ZErrorLogStyle logStyle, std::string logFile);
|
||||
void ReportError(ZErrorSeverity type, std::string desc, ...);
|
||||
void WriteLog(std::string str, ...);
|
||||
|
||||
@ -147,6 +144,10 @@ class ZEngine
|
||||
int GetIntResource(std::string type, std::string id, std::string element);
|
||||
double GetDoubleResource(std::string type, std::string id, std::string element);
|
||||
|
||||
#ifdef USE_AUDIERE
|
||||
audiere::AudioDevicePtr GetSoundDevice();
|
||||
#endif //USE_AUDIERE
|
||||
SDL_Surface* GetDisplayPointer();
|
||||
bool DisplayCreated();
|
||||
int DisplayWidth();
|
||||
int DisplayHeight();
|
||||
|
@ -12,42 +12,23 @@
|
||||
#define __ze_zmusic_h__
|
||||
|
||||
#include "ZE_ZEngine.h"
|
||||
#include "ZE_ZSoundBase.h"
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
#ifdef USE_AUDIERE
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
class ZMusic
|
||||
|
||||
class ZMusic : public ZSoundBase
|
||||
{
|
||||
protected:
|
||||
ZEngine* rEngine;
|
||||
Mix_Music *rMusic;
|
||||
public:
|
||||
static const int LoopInfinite;
|
||||
|
||||
ZMusic();
|
||||
ZMusic(std::string filename);
|
||||
virtual ~ZMusic();
|
||||
|
||||
void Open(std::string filename);
|
||||
void OpenFromZRF(std::string resourceId);
|
||||
|
||||
void Release();
|
||||
void Play(int loopNum=0, int fadeTime=0) const;
|
||||
void Pause() const;
|
||||
void Unpause() const;
|
||||
void Rewind() const;
|
||||
void Stop(int fadeTime=0) const;
|
||||
void SetVolume(int volume);
|
||||
|
||||
bool IsLoaded() const;
|
||||
bool IsPlaying() const;
|
||||
bool IsPaused() const;
|
||||
int GetVolume() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //USE_SDL_MIXER
|
||||
#endif //USE_AUDIERE
|
||||
|
||||
#endif //__ze_zmusic_h__
|
||||
|
@ -2,7 +2,7 @@
|
||||
This file is Part of the ZEngine Library for 2D game development.
|
||||
Copyright (C) 2002-2004 James Turk
|
||||
|
||||
Licensed under a BSD-style license.
|
||||
Licensed under a BSD-style license.
|
||||
|
||||
The maintainer of this library is James Turk (james@conceptofzero.net)
|
||||
and the home of this Library is http://www.zengine.sourceforge.net
|
||||
@ -12,45 +12,23 @@
|
||||
#define __ze_zsound_h__
|
||||
|
||||
#include "ZE_ZEngine.h"
|
||||
#include "ZE_ZSoundBase.h"
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
#ifdef USE_AUDIERE
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
|
||||
class ZSound
|
||||
class ZSound : public ZSoundBase
|
||||
{
|
||||
protected:
|
||||
ZEngine* rEngine;
|
||||
Mix_Chunk* rSound;
|
||||
int rChannelID;
|
||||
|
||||
public:
|
||||
static const int LoopInfinite;
|
||||
|
||||
ZSound();
|
||||
ZSound(std::string filename);
|
||||
virtual ~ZSound();
|
||||
|
||||
void Open(std::string filename);
|
||||
void OpenFromZip(std::string zipname, std::string filename);
|
||||
void OpenFromZRF(std::string resourceId);
|
||||
void Release();
|
||||
|
||||
void Play(int loopNum=0, int fadeTime=0);
|
||||
void Pause() const;
|
||||
void Unpause() const;
|
||||
void Stop(int fadeTime=0) const;
|
||||
void SetVolume(int volume);
|
||||
|
||||
bool IsLoaded() const;
|
||||
bool IsPlaying() const;
|
||||
bool IsPaused() const;
|
||||
int GetVolume() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //USE_SDL_MIXER
|
||||
#endif //USE_AUDIERE
|
||||
|
||||
#endif //__ze_zsound_h__
|
||||
#endif //__ze_zsound_h__
|
57
include/ZE_ZSoundBase.h
Normal file
57
include/ZE_ZSoundBase.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
This file is Part of the ZEngine Library for 2D game development.
|
||||
Copyright (C) 2002-2004 James Turk
|
||||
|
||||
Licensed under a BSD-style license.
|
||||
|
||||
The maintainer of this library is James Turk (james@conceptofzero.net)
|
||||
and the home of this Library is http://www.zengine.sourceforge.net
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ze_zsoundbase_h__
|
||||
#define __ze_zsoundbase_h__
|
||||
|
||||
#include "ZE_ZEngine.h"
|
||||
|
||||
#ifdef USE_AUDIERE
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
|
||||
class ZSoundBase
|
||||
{
|
||||
protected:
|
||||
//ZEngine* rEngine;
|
||||
audiere::AudioDevicePtr rDevice;
|
||||
audiere::OutputStreamPtr rStream;
|
||||
|
||||
public:
|
||||
ZSoundBase();
|
||||
virtual ~ZSoundBase();
|
||||
|
||||
virtual void Open(std::string filename)=0;
|
||||
|
||||
void Play(bool loop=false);
|
||||
void Stop();
|
||||
|
||||
void SetVolume(float volume);
|
||||
void SetPan(float pan);
|
||||
void SetPitch(float pitch);
|
||||
void SetPosition(int position);
|
||||
void SetPosition(float posPercent);
|
||||
|
||||
bool IsLoaded() const;
|
||||
bool IsPlaying() const;
|
||||
bool IsSeekable() const;
|
||||
float GetVolume() const;
|
||||
float GetPan() const;
|
||||
float GetPitch() const;
|
||||
int GetPosition() const;
|
||||
int GetLength() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //USE_AUDIERE
|
||||
|
||||
#endif //__ze_zsound_h__
|
@ -15,7 +15,7 @@
|
||||
#ifdef USE_SDL_TTF
|
||||
#include "ZE_ZFont.h"
|
||||
#endif
|
||||
#ifdef USE_SDL_MIXER
|
||||
#ifdef USE_AUDIERE
|
||||
#include "ZE_ZSound.h"
|
||||
#include "ZE_ZMusic.h"
|
||||
#endif
|
||||
|
@ -157,28 +157,6 @@ void FreeImage(SDL_Surface *&image)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
|
||||
void FreeSound(Mix_Chunk *&chunk)
|
||||
{
|
||||
if(chunk)
|
||||
{
|
||||
Mix_FreeChunk(chunk);
|
||||
chunk = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void FreeMusic(Mix_Music *&music)
|
||||
{
|
||||
if(music)
|
||||
{
|
||||
Mix_FreeMusic(music);
|
||||
music = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL_TTF
|
||||
|
||||
void FreeFont(TTF_Font *&font)
|
||||
|
@ -24,7 +24,8 @@ ZEngine::ZEngine() :
|
||||
mSecPerFrame(0.0),
|
||||
mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL),
|
||||
mMouseX(0), mMouseY(0), mMouseB(0),
|
||||
mLogStyle(ZLOG_TEXT), mErrlog(stderr), mEventFilter(NULL)
|
||||
mEventFilter(NULL),
|
||||
mLogStyle(ZLOG_NONE), mMinSeverity(ZERR_NOTE), mErrlog(NULL)
|
||||
{
|
||||
for(int k = 0; k < SDLK_LAST; ++k)
|
||||
mKeyPress[k] = false;
|
||||
@ -83,10 +84,50 @@ void ZEngine::ReleaseInstance()
|
||||
sInstance = NULL;
|
||||
}
|
||||
|
||||
bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title,
|
||||
int soundRate, bool stereo, std::string icon)
|
||||
void ZEngine::InitErrorLog(ZErrorLogStyle logStyle, std::string logFile, ZErrorSeverity minSeverity)
|
||||
{
|
||||
mMinSeverity = minSeverity;
|
||||
mLogStyle = logStyle;
|
||||
|
||||
if(logStyle != ZLOG_NONE && logFile.length())
|
||||
{
|
||||
//stderr & stdout directed to their appropriate streams
|
||||
if(logFile == "stderr")
|
||||
mErrlog = stderr;
|
||||
else if(logFile == "stdout")
|
||||
mErrlog = stdout;
|
||||
else
|
||||
mErrlog = std::fopen(logFile.c_str(),"w");
|
||||
|
||||
if(logStyle == ZLOG_HTML)
|
||||
{
|
||||
fprintf(mErrlog,
|
||||
"<html><head><title>ZEngine Error Log</title>\n<style type=\"text/css\">\n<!--\n"
|
||||
"p { margin: 0 }\n"
|
||||
".note { font-style:italic color:gray }\n"
|
||||
".verbose { font-style:italic; background:yellow; font-size:small }\n"
|
||||
".depr { font-weight:bold; background:blue; color:white }\n"
|
||||
".warning { font-weight:bold; background:yellow }\n"
|
||||
".error { font-weight:bold; background:orange }\n"
|
||||
".critical { font-weight:bold; background:red; color:white }\n"
|
||||
"-->\n</style>\n</head>\n<body>\n");
|
||||
fflush(mErrlog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ZEngine::InitSound()
|
||||
{
|
||||
mAudiereDevice = audiere::OpenDevice();
|
||||
if(!mAudiereDevice)
|
||||
{
|
||||
ReportError(ZERR_CRITICAL,"Failed to initialize sound, AudiereDevice creation failed.");
|
||||
}
|
||||
return (mAudiereDevice != NULL);
|
||||
}
|
||||
|
||||
bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title, std::string icon)
|
||||
{
|
||||
Uint32 sdlFlags=SDL_INIT_VIDEO|SDL_INIT_TIMER;
|
||||
Uint32 vidFlags=0;
|
||||
SDL_Surface *iconImg;
|
||||
bool status=true; //status of setup, only true if everything went flawlessly
|
||||
@ -99,26 +140,12 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
|
||||
|
||||
if(!mInitialized)
|
||||
{
|
||||
//audio only initialized if soundRate != 0
|
||||
if(soundRate)
|
||||
sdlFlags |= SDL_INIT_AUDIO;
|
||||
if(SDL_Init(sdlFlags) < 0)
|
||||
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0)
|
||||
{
|
||||
ReportError(ZERR_CRITICAL,"Error initializing SDL: %s",SDL_GetError());
|
||||
return false; //return now, nothing else should be called
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
if(!mInitialized)
|
||||
{
|
||||
if(Mix_OpenAudio(soundRate, AUDIO_S16SYS, stereo?2:1, 4096) < 0) //Open Audio (Stereo?2:1 is conditional for number of channels)
|
||||
{
|
||||
ReportError(ZERR_ERROR,"Error initializing SDL_mixer: %s",SDL_GetError());
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
#endif //USE_SDL_MIXER
|
||||
|
||||
//set vidFlags and bpp//
|
||||
if(mFullscreen)
|
||||
@ -204,9 +231,6 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
|
||||
{
|
||||
ReportError(ZERR_CRITICAL,"Error creating display: Unknown Error. %dx%d %dBPP (%s)", width, height, bpp, SDL_GetError());
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
Mix_CloseAudio();
|
||||
#endif
|
||||
SDL_Quit();
|
||||
|
||||
return false; //bail if display fails
|
||||
@ -246,10 +270,6 @@ void ZEngine::CloseDisplay()
|
||||
TTF_Quit();
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
Mix_CloseAudio();
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
if(mErrlog && mErrlog != stderr && mErrlog != stdin)
|
||||
@ -269,11 +289,6 @@ void ZEngine::ToggleFullscreen()
|
||||
SetReloadNeed(true); //images need to be reloaded on fullscreen swap
|
||||
}
|
||||
|
||||
SDL_Surface *ZEngine::Display()
|
||||
{
|
||||
return mScreen;
|
||||
}
|
||||
|
||||
void ZEngine::Update()
|
||||
{
|
||||
#if (GFX_BACKEND == ZE_OGL)
|
||||
@ -289,10 +304,9 @@ void ZEngine::Update()
|
||||
|
||||
#if (GFX_BACKEND == ZE_OGL)
|
||||
|
||||
void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
|
||||
void ZEngine::ClearDisplay(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
GLclampf r = red/255.0f, g = green/255.0f, b = blue/255.0f, a = alpha/255.0f;
|
||||
glClearColor(r,g,b,a);
|
||||
glClearColor(red/255.0f,green/255.0f,blue/255.0f,1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
}
|
||||
@ -369,7 +383,7 @@ bool ZEngine::TimerIsPaused()
|
||||
return mPaused;
|
||||
}
|
||||
|
||||
double ZEngine::GetFrameTime()
|
||||
double ZEngine::GetFrameSpeed()
|
||||
{
|
||||
return mSecPerFrame;
|
||||
}
|
||||
@ -537,55 +551,24 @@ void ZEngine::SetEventFilter(SDL_EventFilter filter)
|
||||
mEventFilter = filter;
|
||||
}
|
||||
|
||||
void ZEngine::SetErrorLog(ZErrorLogStyle logStyle, std::string logFile)
|
||||
{
|
||||
mLogStyle = logStyle;
|
||||
|
||||
if(logStyle != ZLOG_NONE && logFile.length())
|
||||
{
|
||||
//stderr & stdout directed to their appropriate streams
|
||||
if(logFile == "stderr")
|
||||
mErrlog = stderr;
|
||||
else if(logFile == "stdout")
|
||||
mErrlog = stdout;
|
||||
else
|
||||
mErrlog = std::fopen(logFile.c_str(),"w");
|
||||
|
||||
if(logStyle == ZLOG_HTML)
|
||||
{
|
||||
fprintf(mErrlog,
|
||||
"<html><head><title>ZEngine Error Log</title>\n<style type=\"text/css\">\n<!--\n"
|
||||
"p { margin: 0 }\n"
|
||||
".note { font-style:italic color:gray }\n"
|
||||
".verbose { font-style:italic; background:yellow; font-size:small }\n"
|
||||
".depr { font-weight:bold; background:blue; color:white }\n"
|
||||
".warning { font-weight:bold; background:yellow }\n"
|
||||
".error { font-weight:bold; background:orange }\n"
|
||||
".critical { font-weight:bold; background:red; color:white }\n"
|
||||
"-->\n</style>\n</head>\n<body>\n");
|
||||
fflush(mErrlog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZEngine::ReportError(ZErrorSeverity severity, std::string desc, ...)
|
||||
{
|
||||
static std::string prefix[] = {
|
||||
" ",
|
||||
"VERBOSE: ",
|
||||
"DEPRECIATED: ",
|
||||
"WARNING: ",
|
||||
"ERROR: ",
|
||||
"CRITICAL: "
|
||||
" ",
|
||||
};
|
||||
|
||||
static std::string style[] = {
|
||||
"note",
|
||||
"verbose",
|
||||
"depr",
|
||||
"warning",
|
||||
"error",
|
||||
"critical"
|
||||
"critical",
|
||||
"note"
|
||||
};
|
||||
|
||||
if(mLogStyle != ZLOG_NONE)
|
||||
@ -715,6 +698,16 @@ double ZEngine::GetDoubleResource(std::string type, std::string id, std::string
|
||||
return ret;
|
||||
}
|
||||
|
||||
audiere::AudioDevicePtr ZEngine::GetSoundDevice()
|
||||
{
|
||||
return mAudiereDevice;
|
||||
}
|
||||
|
||||
SDL_Surface *ZEngine::GetDisplayPointer()
|
||||
{
|
||||
return mScreen;
|
||||
}
|
||||
|
||||
bool ZEngine::DisplayCreated()
|
||||
{
|
||||
return mInitialized;
|
||||
|
@ -10,156 +10,25 @@
|
||||
|
||||
#include "ZE_ZMusic.h"
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
#ifdef USE_AUDIERE
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
|
||||
//ZMusic is a very simple class, each call basically wraps a self-explanatory function of SDL_Mixer
|
||||
const int ZMusic::LoopInfinite = -1; //constant for infinite, as used by SDL_Mixer
|
||||
|
||||
ZMusic::ZMusic() :
|
||||
rEngine(ZEngine::GetInstance()),
|
||||
rMusic(NULL)
|
||||
ZMusic::ZMusic()
|
||||
{
|
||||
}
|
||||
|
||||
ZMusic::ZMusic(std::string filename) :
|
||||
rEngine(ZEngine::GetInstance()),
|
||||
rMusic(NULL)
|
||||
ZMusic::ZMusic(std::string filename) : ZSoundBase()
|
||||
{
|
||||
Open(filename);
|
||||
}
|
||||
|
||||
ZMusic::~ZMusic()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
void ZMusic::Open(std::string filename)
|
||||
{
|
||||
Release();
|
||||
|
||||
rMusic = Mix_LoadMUS(filename.c_str());
|
||||
|
||||
if(!rMusic)
|
||||
rEngine->ReportError(ZERR_WARNING,"Could not load %s",filename.c_str());
|
||||
}
|
||||
|
||||
void ZMusic::OpenFromZRF(std::string resourceId)
|
||||
{
|
||||
std::string filename = rEngine->GetStringResource("music",resourceId,"filename");
|
||||
if(filename.length())
|
||||
Open(filename);
|
||||
else
|
||||
rEngine->ReportError(ZERR_WARNING,"Failed to load music resource '%s'",resourceId.c_str());
|
||||
}
|
||||
|
||||
void ZMusic::Release()
|
||||
{
|
||||
Mix_HaltMusic();
|
||||
FreeMusic(rMusic);
|
||||
}
|
||||
|
||||
void ZMusic::Play(int loopNum, int fadeTime) const
|
||||
{
|
||||
if(Mix_PlayingMusic()) //stop currently playing music
|
||||
Mix_HaltMusic();
|
||||
|
||||
if(rMusic)
|
||||
{
|
||||
if(fadeTime)
|
||||
Mix_FadeInMusic(rMusic, loopNum, fadeTime);
|
||||
else
|
||||
Mix_PlayMusic(rMusic, loopNum);
|
||||
}
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Play with no music loaded.");
|
||||
}
|
||||
|
||||
void ZMusic::Pause() const
|
||||
{
|
||||
if(rMusic)
|
||||
Mix_PauseMusic();
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Pause with no music loaded.");
|
||||
}
|
||||
|
||||
void ZMusic::Unpause() const
|
||||
{
|
||||
if(rMusic)
|
||||
Mix_ResumeMusic();
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Unpause with no music loaded.");
|
||||
}
|
||||
|
||||
void ZMusic::Rewind() const
|
||||
{
|
||||
if(rMusic)
|
||||
Mix_RewindMusic();
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Rewind with no music loaded.");
|
||||
}
|
||||
|
||||
void ZMusic::Stop(int fadeTime) const
|
||||
{
|
||||
if(rMusic)
|
||||
{
|
||||
if(fadeTime)
|
||||
Mix_FadeOutMusic(fadeTime);
|
||||
else
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Stop with no music loaded.");
|
||||
}
|
||||
|
||||
void ZMusic::SetVolume(int volume)
|
||||
{
|
||||
if(rMusic)
|
||||
Mix_VolumeMusic(volume);
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::SetVolume with no music loaded.");
|
||||
}
|
||||
|
||||
bool ZMusic::IsLoaded() const
|
||||
{
|
||||
return rMusic != NULL;
|
||||
}
|
||||
|
||||
bool ZMusic::IsPlaying() const
|
||||
{
|
||||
if(rMusic)
|
||||
return Mix_PlayingMusic() > 0;
|
||||
else
|
||||
{
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::IsPlaying with no music loaded.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ZMusic::IsPaused() const
|
||||
{
|
||||
if(rMusic)
|
||||
return Mix_PausedMusic() > 0;
|
||||
else
|
||||
{
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::IsPaused with no music loaded.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int ZMusic::GetVolume() const
|
||||
{
|
||||
if(rMusic)
|
||||
return Mix_VolumeMusic(-1);
|
||||
else
|
||||
{
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::GetVolume with no music loaded.");
|
||||
return false;
|
||||
}
|
||||
rStream = audiere::OpenSound(rDevice, filename.c_str(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -9,167 +9,25 @@
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ZE_ZSound.h"
|
||||
#include "ZE_ZSoundBase.h"
|
||||
|
||||
#ifdef USE_SDL_MIXER
|
||||
#ifdef USE_AUDIERE
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
|
||||
//ZSound is almost exactly like ZMusic, when making changes check if that change should
|
||||
//be applied to ZMusic as well, roughly 90% of the time it should be.
|
||||
|
||||
const int ZSound::LoopInfinite = -1;
|
||||
|
||||
ZSound::ZSound() :
|
||||
rEngine(ZEngine::GetInstance()),
|
||||
rSound(NULL),
|
||||
rChannelID(-1) //request channel ID
|
||||
ZSound::ZSound()
|
||||
{
|
||||
}
|
||||
|
||||
ZSound::ZSound(std::string filename) :
|
||||
rEngine(ZEngine::GetInstance()),
|
||||
rSound(NULL),
|
||||
rChannelID(-1) //request channel ID
|
||||
ZSound::ZSound(std::string filename) : ZSoundBase()
|
||||
{
|
||||
Open(filename);
|
||||
}
|
||||
|
||||
ZSound::~ZSound()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
void ZSound::Open(std::string filename)
|
||||
{
|
||||
Release();
|
||||
rSound = Mix_LoadWAV(filename.c_str());
|
||||
|
||||
if(!rSound)
|
||||
rEngine->ReportError(ZERR_ERROR,"Could not load %s",filename.c_str());
|
||||
}
|
||||
|
||||
void ZSound::OpenFromZip(std::string zipname, std::string filename)
|
||||
{
|
||||
SDL_RWops *rw = RWFromZip(zipname,filename);
|
||||
if(rw)
|
||||
{
|
||||
rSound = Mix_LoadWAV_RW(rw,0);
|
||||
delete []rw->hidden.mem.base; //must free buffer
|
||||
SDL_FreeRW(rw);
|
||||
}
|
||||
|
||||
if(!rSound)
|
||||
rEngine->ReportError(ZERR_WARNING,"Could not load %s from %s",filename.c_str(),zipname.c_str());
|
||||
}
|
||||
|
||||
void ZSound::OpenFromZRF(std::string resourceId)
|
||||
{
|
||||
std::string filename = rEngine->GetStringResource("sound",resourceId,"filename");
|
||||
if(filename.length())
|
||||
Open(filename);
|
||||
else
|
||||
rEngine->ReportError(ZERR_WARNING,"Failed to load sound resource '%s'",resourceId.c_str());
|
||||
}
|
||||
|
||||
void ZSound::Release()
|
||||
{
|
||||
if(rChannelID >= 0)
|
||||
Mix_HaltChannel(rChannelID);
|
||||
FreeSound(rSound);
|
||||
}
|
||||
|
||||
void ZSound::Play(int loopNum, int fadeTime)
|
||||
{
|
||||
if(rChannelID >= 0 && Mix_Playing(rChannelID)) //stop currently playing sound
|
||||
Mix_HaltChannel(rChannelID);
|
||||
|
||||
if(rSound)
|
||||
{
|
||||
if(fadeTime)
|
||||
rChannelID = Mix_FadeInChannel(rChannelID, rSound, loopNum, fadeTime);
|
||||
else
|
||||
rChannelID = Mix_PlayChannel(rChannelID, rSound, loopNum);
|
||||
}
|
||||
else if(!rSound)
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Play with no sound effect loaded.");
|
||||
}
|
||||
|
||||
void ZSound::Pause() const
|
||||
{
|
||||
if(rSound && rChannelID >= 0)
|
||||
Mix_Pause(rChannelID);
|
||||
else if(!rSound)
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Pause with no sound effect loaded.");
|
||||
}
|
||||
|
||||
void ZSound::Unpause() const
|
||||
{
|
||||
if(rSound && rChannelID >= 0)
|
||||
Mix_Resume(rChannelID);
|
||||
else if(!rSound)
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Unpause with no sound effect loaded.");
|
||||
|
||||
}
|
||||
|
||||
void ZSound::Stop(int fadeTime) const
|
||||
{
|
||||
if(rSound && rChannelID >= 0)
|
||||
{
|
||||
if(fadeTime)
|
||||
Mix_FadeOutChannel(rChannelID,fadeTime);
|
||||
else
|
||||
Mix_HaltChannel(rChannelID);
|
||||
}
|
||||
else if(!rSound)
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Stop with no sound effect loaded.");
|
||||
}
|
||||
|
||||
void ZSound::SetVolume(int volume)
|
||||
{
|
||||
if(rSound)
|
||||
Mix_VolumeChunk(rSound,volume);
|
||||
else
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::SetVolume with no sound effect loaded.");
|
||||
}
|
||||
|
||||
bool ZSound::IsLoaded() const
|
||||
{
|
||||
return rSound != NULL;
|
||||
}
|
||||
|
||||
bool ZSound::IsPlaying() const
|
||||
{
|
||||
if(rSound && rChannelID >= 0)
|
||||
return Mix_Playing(rChannelID) > 0;
|
||||
else
|
||||
{
|
||||
if(rChannelID >= 0)
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::IsPlaying with no sound effect loaded.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ZSound::IsPaused() const
|
||||
{
|
||||
if(rSound && rChannelID >= 0)
|
||||
return Mix_Paused(rChannelID) > 0;
|
||||
else
|
||||
{
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::IsPaused with no sound effect loaded.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int ZSound::GetVolume() const
|
||||
{
|
||||
if(rSound)
|
||||
return Mix_VolumeChunk(rSound,-1);
|
||||
else
|
||||
{
|
||||
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::GetVolume with no sound effect loaded.");
|
||||
return -1;
|
||||
}
|
||||
rStream = audiere::OpenSound(rDevice, filename.c_str(), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
106
src/ZE_ZSoundBase.cpp
Normal file
106
src/ZE_ZSoundBase.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/*******************************************************************************
|
||||
This file is Part of the ZEngine Library for 2D game development.
|
||||
Copyright (C) 2002-2004 James Turk
|
||||
|
||||
Licensed under a BSD-style license.
|
||||
|
||||
The maintainer of this library is James Turk (james@conceptofzero.net)
|
||||
and the home of this Library is http://www.zengine.sourceforge.net
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ZE_ZSoundBase.h"
|
||||
|
||||
#ifdef USE_AUDIERE
|
||||
|
||||
namespace ZE
|
||||
{
|
||||
|
||||
ZSoundBase::ZSoundBase()
|
||||
{
|
||||
rDevice = ZEngine::GetInstance()->GetSoundDevice();
|
||||
}
|
||||
|
||||
ZSoundBase::~ZSoundBase()
|
||||
{
|
||||
}
|
||||
|
||||
void ZSoundBase::Play(bool loop)
|
||||
{
|
||||
rStream->play();
|
||||
rStream->setRepeat(true);
|
||||
}
|
||||
|
||||
void ZSoundBase::Stop()
|
||||
{
|
||||
rStream->stop();
|
||||
}
|
||||
|
||||
void ZSoundBase::SetVolume(float volume)
|
||||
{
|
||||
rStream->setVolume(volume);
|
||||
}
|
||||
|
||||
void ZSoundBase::SetPan(float pan)
|
||||
{
|
||||
rStream->setPan(pan);
|
||||
}
|
||||
|
||||
void ZSoundBase::SetPitch(float pitch)
|
||||
{
|
||||
rStream->setPitchShift(pitch);
|
||||
}
|
||||
|
||||
void ZSoundBase::SetPosition(int position)
|
||||
{
|
||||
rStream->setPosition(position);
|
||||
}
|
||||
|
||||
void ZSoundBase::SetPosition(float posPercent)
|
||||
{
|
||||
rStream->setPosition(static_cast<int>(posPercent*rStream->getLength()));
|
||||
}
|
||||
|
||||
bool ZSoundBase::IsLoaded() const
|
||||
{
|
||||
return (rStream != NULL);
|
||||
}
|
||||
|
||||
bool ZSoundBase::IsPlaying() const
|
||||
{
|
||||
return rStream->isPlaying();
|
||||
}
|
||||
|
||||
bool ZSoundBase::IsSeekable() const
|
||||
{
|
||||
return rStream->isSeekable();
|
||||
}
|
||||
|
||||
float ZSoundBase::GetVolume() const
|
||||
{
|
||||
return rStream->getVolume();
|
||||
}
|
||||
|
||||
float ZSoundBase::GetPan() const
|
||||
{
|
||||
return rStream->getPan();
|
||||
}
|
||||
|
||||
float ZSoundBase::GetPitch() const
|
||||
{
|
||||
return rStream->getPitchShift();
|
||||
}
|
||||
|
||||
int ZSoundBase::GetPosition() const
|
||||
{
|
||||
return rStream->getPosition();
|
||||
}
|
||||
|
||||
int ZSoundBase::GetLength() const
|
||||
{
|
||||
return rStream->getLength();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user