Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
Sound Class Reference

#include <CUSound.h>

Inheritance diagram for Sound:

Public Member Functions

const std::string & getSource () const
 
std::string getSuffix () const
 
float getDuration () const
 
bool isPreloaded () const
 
CC_CONSTRUCTOR_ACCESS _source ("")
 
CC_CONSTRUCTOR_ACCESS _duration (0.0f)
 
 ~Sound ()
 
bool init (std::string source)
 
bool init (std::string source, float duration)
 

Static Public Member Functions

static Soundcreate (std::string source)
 
static Soundcreate (std::string source, float duration)
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: Sound() : Ref()
 

Protected Attributes

std::string _source
 
float _duration
 

Friends

class SoundLoader
 

Detailed Description

Class provides a reference to a (potentially) loaded asset.

We say potentially because Android has substantially inferior sound capabilities and cannot preload sounds. This means that the asset handling for Android is very different from other platforms. To avoid this, we introduce this class as a way of handling the sound across all platforms. It can refer to a sound that is preloaded, or one that should be loaded when used.

This class uses Cocos2d reference counting for memory management. The constructors are protected because only the SoundLoader should construct sounds.

Constructor & Destructor Documentation

Sound::~Sound ( )
inline

Deletes this sound object

The sound should be unloaded before deletion.

Member Function Documentation

NS_CC_BEGIN Sound * Sound::create ( std::string  source)
static

Creates a new sound object for the given source file.

The sound file has no duration, indicating that it was not preloaded.

Parameters
sourcethe source file for the sound
Returns
an autoreleased sound object
Sound * Sound::create ( std::string  source,
float  duration 
)
static

Creates a new sound object for the given source file.

The sound file has a duration, indicating that it was preloaded.

Parameters
sourcethe source file for the sound
durationthe duration of the sound file
Returns
an autoreleased sound object
float Sound::getDuration ( ) const
inline

Returns the duration of this sound file.

If the file has not been preloaded, we cannot determine the duration. In that case, the duration is experimental::AudioEngine::TIME_UNKNOWN.

Returns
the duration of this sound file.
const std::string& Sound::getSource ( ) const
inline

Returns the source file for this sound.

Returns
the source file for this sound.
std::string Sound::getSuffix ( ) const
inline

Returns the file suffix for this sound.

Until we expose more functionality about the encoding, this is a poor man's way of determining the file format.

Returns
the file suffix for this sound.
bool Sound::init ( std::string  source)
inline

Initializes a new sound object for the given source file.

The sound file has no duration, indicating that it was not preloaded.

Parameters
sourcethe source file for the sound
Returns
true if the object was initialized successfully
bool Sound::init ( std::string  source,
float  duration 
)
inline

Initializes a new sound object for the given source file.

The sound file has a duration, indicating that it was preloaded.

Parameters
sourcethe source file for the sound
durationthe duration of the sound file
Returns
true if the object was initialized successfully
bool Sound::isPreloaded ( ) const
inline

Returns true if the sound file was preloaded.

This should return true on any platform that is not Android or Linux.

Returns
true if the sound file was preloaded.

Friends And Related Function Documentation

friend class SoundLoader
friend

Allow the sound loader access to the constructors

Member Data Documentation

float Sound::_duration
protected

The duration of the sound asset

std::string Sound::_source
protected

The source file for the sound


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