2010-10-18 15:07:55 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2010 Steve Oldmeadow
|
2010-10-18 15:07:55 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _SIMPLE_AUDIO_ENGINE_H_
|
|
|
|
#define _SIMPLE_AUDIO_ENGINE_H_
|
|
|
|
|
2010-11-18 21:47:14 +08:00
|
|
|
#include "Export.h"
|
2011-01-25 14:26:26 +08:00
|
|
|
#include <stddef.h>
|
2010-10-18 15:07:55 +08:00
|
|
|
|
2010-12-15 18:28:18 +08:00
|
|
|
namespace CocosDenshion {
|
|
|
|
|
2010-11-29 22:17:30 +08:00
|
|
|
/**
|
2010-10-18 15:07:55 +08:00
|
|
|
@class SimpleAudioEngine
|
|
|
|
@brief offer a VERY simple interface to play background music & sound effect
|
2010-11-29 22:17:30 +08:00
|
|
|
*/
|
2010-10-18 15:07:55 +08:00
|
|
|
class EXPORT_DLL SimpleAudioEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SimpleAudioEngine();
|
|
|
|
~SimpleAudioEngine();
|
|
|
|
|
2010-11-12 16:33:50 +08:00
|
|
|
/**
|
|
|
|
@brief Get the shared Engine object,it will new one when first time be called
|
|
|
|
*/
|
2010-11-17 16:31:48 +08:00
|
|
|
static SimpleAudioEngine* sharedEngine();
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Release the shared Engine object
|
2010-11-29 22:17:30 +08:00
|
|
|
@warning It must be called before the application exit, or a memroy leak will be casued.
|
2010-11-12 16:33:50 +08:00
|
|
|
*/
|
2011-01-10 11:47:59 +08:00
|
|
|
static void end();
|
2010-10-18 15:07:55 +08:00
|
|
|
|
2010-12-11 11:08:03 +08:00
|
|
|
/**
|
2011-01-18 18:21:06 +08:00
|
|
|
@brief Set the ResourcePath and(or) the zip file name
|
|
|
|
@param pszResPath The absolute resource path
|
|
|
|
@param pszZipFileName The relative path of the .zip file
|
2010-12-11 11:08:03 +08:00
|
|
|
*/
|
2011-01-25 14:26:26 +08:00
|
|
|
static void setResource(const char* pszZipFileName, const char* pszResPath = NULL);
|
2010-12-11 11:08:03 +08:00
|
|
|
|
2011-01-10 11:39:34 +08:00
|
|
|
/**
|
|
|
|
@brief Preload background music
|
|
|
|
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
|
|
|
|
*/
|
|
|
|
void preloadBackgroundMusic(const char* pszFilePath);
|
|
|
|
|
2010-11-12 16:33:50 +08:00
|
|
|
/**
|
|
|
|
@brief Play background music
|
|
|
|
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
|
|
|
|
@param bLoop Whether the background music loop or not
|
|
|
|
*/
|
2010-10-18 15:07:55 +08:00
|
|
|
void playBackgroundMusic(const char* pszFilePath, bool bLoop = false);
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Stop playing background music
|
2010-11-30 14:37:11 +08:00
|
|
|
@param bReleaseData If release the background music data or not.As default value is false
|
2010-11-12 16:33:50 +08:00
|
|
|
*/
|
2010-11-30 14:37:11 +08:00
|
|
|
void stopBackgroundMusic(bool bReleaseData = false);
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Pause playing background music
|
|
|
|
*/
|
2010-10-18 15:07:55 +08:00
|
|
|
void pauseBackgroundMusic();
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Resume playing background music
|
|
|
|
*/
|
2010-10-18 15:07:55 +08:00
|
|
|
void resumeBackgroundMusic();
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Rewind playing background music
|
|
|
|
*/
|
2010-10-18 15:07:55 +08:00
|
|
|
void rewindBackgroundMusic();
|
|
|
|
|
|
|
|
bool willPlayBackgroundMusic();
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Whether the background music is playing
|
|
|
|
@return If is playing return true,or return false
|
|
|
|
*/
|
2010-10-18 15:07:55 +08:00
|
|
|
bool isBackgroundMusicPlaying();
|
|
|
|
|
|
|
|
// properties
|
2010-10-21 14:44:02 +08:00
|
|
|
/**
|
2011-01-21 15:14:07 +08:00
|
|
|
@brief The volume of the background music max value is 1.0,the min value is 0.0
|
2010-10-21 14:44:02 +08:00
|
|
|
*/
|
2011-01-21 15:14:07 +08:00
|
|
|
float getBackgroundMusicVolume();
|
2010-11-29 22:17:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief set the volume of background music
|
2011-01-21 15:14:07 +08:00
|
|
|
@param volume must be in 0.0~1.0
|
2010-11-29 22:17:30 +08:00
|
|
|
*/
|
2011-01-21 15:14:07 +08:00
|
|
|
void setBackgroundMusicVolume(float volume);
|
2010-10-18 15:07:55 +08:00
|
|
|
|
2010-10-21 14:44:02 +08:00
|
|
|
/**
|
2011-01-21 15:14:07 +08:00
|
|
|
@brief The volume of the effects max value is 1.0,the min value is 0.0
|
2010-10-21 14:44:02 +08:00
|
|
|
*/
|
2011-01-21 15:14:07 +08:00
|
|
|
float getEffectsVolume();
|
2010-11-29 22:17:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief set the volume of sound effecs
|
2011-01-21 15:14:07 +08:00
|
|
|
@param volume must be in 0.0~1.0
|
2010-11-29 22:17:30 +08:00
|
|
|
*/
|
2011-01-21 15:14:07 +08:00
|
|
|
void setEffectsVolume(float volume);
|
2010-10-18 15:07:55 +08:00
|
|
|
|
|
|
|
// for sound effects
|
2010-11-12 16:33:50 +08:00
|
|
|
/**
|
|
|
|
@brief Play sound effect
|
|
|
|
@param pszFilePath The path of the effect file,or the FileName of T_SoundResInfo
|
|
|
|
*/
|
2011-01-11 16:41:06 +08:00
|
|
|
unsigned int playEffect(const char* pszFilePath);
|
2010-11-12 16:33:50 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Stop playing sound effect
|
2011-01-11 16:41:06 +08:00
|
|
|
@param nSoundId The return value of function playEffect
|
2010-11-12 16:33:50 +08:00
|
|
|
*/
|
2011-01-11 16:41:06 +08:00
|
|
|
void stopEffect(unsigned int nSoundId);
|
2010-10-18 15:07:55 +08:00
|
|
|
|
2010-11-29 22:17:30 +08:00
|
|
|
/**
|
2010-10-18 15:07:55 +08:00
|
|
|
@brief preload a compressed audio file
|
|
|
|
@details the compressed audio will be decode to wave, then write into an
|
|
|
|
internal buffer in SimpleaudioEngine
|
2010-11-29 22:17:30 +08:00
|
|
|
*/
|
2011-01-08 13:41:27 +08:00
|
|
|
void preloadEffect(const char* pszFilePath);
|
2010-10-18 15:07:55 +08:00
|
|
|
|
2010-11-29 22:17:30 +08:00
|
|
|
/**
|
2010-10-18 15:07:55 +08:00
|
|
|
@brief unload the preloaded effect from internal buffer
|
2011-01-08 13:41:27 +08:00
|
|
|
@param[in] pszFilePath The path of the effect file,or the FileName of T_SoundResInfo
|
2010-11-29 22:17:30 +08:00
|
|
|
*/
|
2011-01-08 13:41:27 +08:00
|
|
|
void unloadEffect(const char* pszFilePath);
|
2010-10-18 15:07:55 +08:00
|
|
|
};
|
|
|
|
|
2010-12-15 18:28:18 +08:00
|
|
|
} // end of namespace CocosDenshion
|
|
|
|
|
2010-10-18 15:07:55 +08:00
|
|
|
#endif // _SIMPLE_AUDIO_ENGINE_H_
|