cocos2d-x  3.0-rc0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SimpleAudioEngine Class Reference

Offers a VERY simple interface to play background music & sound effects. More...

#include <SimpleAudioEngine.h>

Inheritance diagram for SimpleAudioEngine:
AndroidJavaEngine OpenSLEngine

Public Member Functions

virtual void preloadBackgroundMusic (const char *pszFilePath)
 Preload background music. More...
 
virtual void playBackgroundMusic (const char *pszFilePath, bool bLoop=false)
 Play background music. More...
 
var playMusic ( var pszFilePath, var false)
 Play background music. More...
 
local playMusic ( local pszFilePath, local false)
 Play background music. More...
 
virtual void stopBackgroundMusic (bool bReleaseData=false)
 Stop playing background music. More...
 
virtual void pauseBackgroundMusic ()
 Pause playing background music. More...
 
virtual void resumeBackgroundMusic ()
 Resume playing background music. More...
 
virtual void rewindBackgroundMusic ()
 Rewind playing background music. More...
 
virtual bool willPlayBackgroundMusic ()
 Indicates whether any background music can be played or not. More...
 
virtual bool isBackgroundMusicPlaying ()
 Indicates whether the background music is playing. More...
 
virtual float getBackgroundMusicVolume ()
 The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum. More...
 
virtual void setBackgroundMusicVolume (float volume)
 Set the volume of background music. More...
 
var setMusicVolume ( var volume)
 Set the volume of background music. More...
 
local setMusicVolume ( local volume)
 Set the volume of background music. More...
 
virtual float getEffectsVolume ()
 The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum. More...
 
virtual void setEffectsVolume (float volume)
 Set the volume of sound effects. More...
 
local setEffectsVolume ( local volume)
 Set the volume of sound effects. More...
 
virtual unsigned int playEffect (const char *pszFilePath, bool bLoop=false, float pitch=1.0f, float pan=0.0f, float gain=1.0f)
 Play sound effect with a file path, pitch, pan and gain. More...
 
virtual void pauseEffect (unsigned int nSoundId)
 Pause playing sound effect. More...
 
virtual void pauseAllEffects ()
 Pause all playing sound effect. More...
 
virtual void resumeEffect (unsigned int nSoundId)
 Resume playing sound effect. More...
 
local resumeEffect ( local nSoundId)
 Resume playing sound effect. More...
 
virtual void resumeAllEffects ()
 Resume all playing sound effect. More...
 
virtual void stopEffect (unsigned int nSoundId)
 Stop playing sound effect. More...
 
virtual void stopAllEffects ()
 Stop all playing sound effects. More...
 
virtual void preloadEffect (const char *pszFilePath)
 preload a compressed audio file More...
 
local preloadEffect ( local pszFilePath)
 preload a compressed audio file More...
 
virtual void unloadEffect (const char *pszFilePath)
 unload the preloaded effect from internal buffer More...
 

Static Public Member Functions

static SimpleAudioEnginegetInstance ()
 Get the shared Engine object,it will new one when first time be called. More...
 
local getInstance ()
 Get the shared Engine object,it will new one when first time be called. More...
 
static SimpleAudioEnginesharedEngine ()
static void end ()
 Release the shared Engine object. More...
 
local end ()
 Release the shared Engine object. More...
 

Protected Member Functions

 SimpleAudioEngine ()
virtual ~SimpleAudioEngine ()

Detailed Description

Offers a VERY simple interface to play background music & sound effects.

Note
Make sure to call SimpleAudioEngine::end() when the sound engine is not needed anymore to release allocated resources.

Constructor & Destructor Documentation

SimpleAudioEngine ( )
protected
var SimpleAudioEngine ( )
protected
local SimpleAudioEngine ( )
protected
virtual ~SimpleAudioEngine ( )
protectedvirtual
var ~SimpleAudioEngine ( )
protectedvirtual
local ~SimpleAudioEngine ( )
protectedvirtual

Member Function Documentation

static void end ( )
static

Release the shared Engine object.

Warning
It must be called before the application exit, or a memory leak will be casued.
var end ( )
static

Release the shared Engine object.

Warning
It must be called before the application exit, or a memory leak will be casued.
local end ( )
static

Release the shared Engine object.

Warning
It must be called before the application exit, or a memory leak will be casued.
virtual float
getBackgroundMusicVolume
( )
virtual

The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.

var getMusicVolume ( )
virtual

The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.

local getMusicVolume ( )
virtual

The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum.

virtual float getEffectsVolume ( )
virtual

The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.

var getEffectsVolume ( )
virtual

The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.

local getEffectsVolume ( )
virtual

The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum.

static SimpleAudioEngine*
getInstance
( )
static

Get the shared Engine object,it will new one when first time be called.

var getInstance ( )
static

Get the shared Engine object,it will new one when first time be called.

local getInstance ( )
static

Get the shared Engine object,it will new one when first time be called.

virtual bool
isBackgroundMusicPlaying
( )
virtual

Indicates whether the background music is playing.

Returns
true if the background music is playing, otherwise false
var isMusicPlaying ( )
virtual

Indicates whether the background music is playing.

Returns
true if the background music is playing, otherwise false
local isMusicPlaying ( )
virtual

Indicates whether the background music is playing.

Returns
true if the background music is playing, otherwise false
virtual void pauseAllEffects ( )
virtual

Pause all playing sound effect.

var pauseAllEffects ( )
virtual

Pause all playing sound effect.

local pauseAllEffects ( )
virtual

Pause all playing sound effect.

virtual void pauseBackgroundMusic ( )
virtual

Pause playing background music.

var pauseMusic ( )
virtual

Pause playing background music.

local pauseMusic ( )
virtual

Pause playing background music.

virtual void pauseEffect ( unsigned int  nSoundId)
virtual

Pause playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
var pauseEffect ( var  nSoundId)
virtual

Pause playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
local pauseEffect ( local  nSoundId)
virtual

Pause playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
virtual void playBackgroundMusic ( const char *  pszFilePath,
bool  bLoop = false 
)
virtual

Play background music.

Parameters
pszFilePathThe path of the background music file,or the FileName of T_SoundResInfo
bLoopWhether the background music loop or not
var playMusic ( var  pszFilePath,
var  bLoop = false 
)
virtual

Play background music.

Parameters
pszFilePathThe path of the background music file,or the FileName of T_SoundResInfo
bLoopWhether the background music loop or not
local playMusic ( local  pszFilePath,
local  bLoop = false 
)
virtual

Play background music.

Parameters
pszFilePathThe path of the background music file,or the FileName of T_SoundResInfo
bLoopWhether the background music loop or not
virtual unsigned int playEffect ( const char *  pszFilePath,
bool  bLoop = false,
float  pitch = 1.0f,
float  pan = 0.0f,
float  gain = 1.0f 
)
virtual

Play sound effect with a file path, pitch, pan and gain.

Parameters
pszFilePathThe path of the effect file.
bLoopDetermines whether to loop the effect playing or not. The default value is false.
pitchFrequency, normal value is 1.0. Will also change effect play time.
panStereo effect, in the range of [-1..1] where -1 enables only left channel.
gainVolume, in the range of [0..1]. The normal value is 1.
Returns
the OpenAL source id
Note
Full support is under development, now there are limitations:
  • no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
  • no pitch/pan/gain on emscrippten, win32, marmalade.
var playEffect ( var  pszFilePath,
var  bLoop = false,
var  pitch = 1.0f,
var  pan = 0.0f,
var  gain = 1.0f 
)
virtual

Play sound effect with a file path, pitch, pan and gain.

Parameters
pszFilePathThe path of the effect file.
bLoopDetermines whether to loop the effect playing or not. The default value is false.
pitchFrequency, normal value is 1.0. Will also change effect play time.
panStereo effect, in the range of [-1..1] where -1 enables only left channel.
gainVolume, in the range of [0..1]. The normal value is 1.
Returns
the OpenAL source id
Note
Full support is under development, now there are limitations:
  • no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
  • no pitch/pan/gain on emscrippten, win32, marmalade.
local playEffect ( local  pszFilePath,
local  bLoop = false,
local  pitch = 1.0f,
local  pan = 0.0f,
local  gain = 1.0f 
)
virtual

Play sound effect with a file path, pitch, pan and gain.

Parameters
pszFilePathThe path of the effect file.
bLoopDetermines whether to loop the effect playing or not. The default value is false.
pitchFrequency, normal value is 1.0. Will also change effect play time.
panStereo effect, in the range of [-1..1] where -1 enables only left channel.
gainVolume, in the range of [0..1]. The normal value is 1.
Returns
the OpenAL source id
Note
Full support is under development, now there are limitations:
  • no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled;
  • no pitch/pan/gain on emscrippten, win32, marmalade.
virtual void preloadBackgroundMusic ( const char *  pszFilePath)
virtual

Preload background music.

Parameters
pszFilePathThe path of the background music file.
var preloadMusic ( var  pszFilePath)
virtual

Preload background music.

Parameters
pszFilePathThe path of the background music file.
local preloadMusic ( local  pszFilePath)
virtual

Preload background music.

Parameters
pszFilePathThe path of the background music file.
virtual void preloadEffect ( const char *  pszFilePath)
virtual

preload a compressed audio file

the compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine

Parameters
pszFilePathThe path of the effect file
var preloadEffect ( var  pszFilePath)
virtual

preload a compressed audio file

the compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine

Parameters
pszFilePathThe path of the effect file
local preloadEffect ( local  pszFilePath)
virtual

preload a compressed audio file

the compressed audio will be decoded to wave, then written into an internal buffer in SimpleAudioEngine

Parameters
pszFilePathThe path of the effect file
virtual void resumeAllEffects ( )
virtual

Resume all playing sound effect.

var resumeAllEffects ( )
virtual

Resume all playing sound effect.

local resumeAllEffects ( )
virtual

Resume all playing sound effect.

virtual void resumeBackgroundMusic ( )
virtual

Resume playing background music.

var resumeMusic ( )
virtual

Resume playing background music.

local resumeMusic ( )
virtual

Resume playing background music.

virtual void resumeEffect ( unsigned int  nSoundId)
virtual

Resume playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
var resumeEffect ( var  nSoundId)
virtual

Resume playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
local resumeEffect ( local  nSoundId)
virtual

Resume playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
virtual void rewindBackgroundMusic ( )
virtual

Rewind playing background music.

var rewindMusic ( )
virtual

Rewind playing background music.

local rewindMusic ( )
virtual

Rewind playing background music.

virtual void
setBackgroundMusicVolume
( float  volume)
virtual

Set the volume of background music.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
var setMusicVolume ( var  volume)
virtual

Set the volume of background music.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
local setMusicVolume ( local  volume)
virtual

Set the volume of background music.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
virtual void setEffectsVolume ( float  volume)
virtual

Set the volume of sound effects.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
var setEffectsVolume ( var  volume)
virtual

Set the volume of sound effects.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
local setEffectsVolume ( local  volume)
virtual

Set the volume of sound effects.

Parameters
volumemust be within the range of 0.0 as the minimum and 1.0 as the maximum.
static SimpleAudioEngine*
sharedEngine
( )
inlinestatic
virtual void stopAllEffects ( )
virtual

Stop all playing sound effects.

var stopAllEffects ( )
virtual

Stop all playing sound effects.

local stopAllEffects ( )
virtual

Stop all playing sound effects.

virtual void stopBackgroundMusic ( bool  bReleaseData = false)
virtual

Stop playing background music.

Parameters
bReleaseDataIf release the background music data or not.As default value is false
var stopMusic ( var  bReleaseData = false)
virtual

Stop playing background music.

Parameters
bReleaseDataIf release the background music data or not.As default value is false
local stopMusic ( local  bReleaseData = false)
virtual

Stop playing background music.

Parameters
bReleaseDataIf release the background music data or not.As default value is false
virtual void stopEffect ( unsigned int  nSoundId)
virtual

Stop playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
var stopEffect ( var  nSoundId)
virtual

Stop playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
local stopEffect ( local  nSoundId)
virtual

Stop playing sound effect.

Parameters
nSoundIdThe return value of function playEffect
virtual void unloadEffect ( const char *  pszFilePath)
virtual

unload the preloaded effect from internal buffer

Parameters
pszFilePathThe path of the effect file
var unloadEffect ( var  pszFilePath)
virtual

unload the preloaded effect from internal buffer

Parameters
pszFilePathThe path of the effect file
local unloadEffect ( local  pszFilePath)
virtual

unload the preloaded effect from internal buffer

Parameters
pszFilePathThe path of the effect file
virtual bool
willPlayBackgroundMusic
( )
virtual

Indicates whether any background music can be played or not.

Returns
true if background music can be played, otherwise false.
var willPlayMusic ( )
virtual

Indicates whether any background music can be played or not.

Returns
true if background music can be played, otherwise false.
local willPlayMusic ( )
virtual

Indicates whether any background music can be played or not.

Returns
true if background music can be played, otherwise false.

The documentation for this class was generated from the following file: