CUGL
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Friends | List of all members
cugl::Sound Class Reference

#include <CUSound.h>

Public Member Functions

 Sound ()
 
 ~Sound ()
 
void dispose ()
 
bool init (const std::string &source)
 
bool init (const char *source)
 
const std::string & getSource () const
 
std::string getSuffix () const
 
double getDuration () const
 
double getSampleRate () const
 
Uint64 getLength () const
 
Uint32 getChannels () const
 
float getVolume () const
 
void setVolume (float volume)
 

Static Public Member Functions

static std::shared_ptr< Soundalloc (const std::string &source)
 
static std::shared_ptr< Soundalloc (const char *source)
 

Friends

class SoundChannel
 

Detailed Description

Class provides a reference to a pre-loaded asset.

Sound assets are loaded entirely into memory. They are not streamed. Therefore, this type of asset should be reserved for low-memory footprint sounds such as sound effects. Music files should be streamed and processed as a Music asset instead.

As a general rule, it is best for these assets to be WAV files. There are no cross-platform lossless encodings for both Androi and iOS. For lossy encodings, only OGG Vorbis is good enough for sound effects.

The internal representation of the sound buffer is platform dependent. You should never attempt to access the buffer directly.

Constructor & Destructor Documentation

cugl::Sound::Sound ( )
inline

Creates a degenerate sound asset with no buffer.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an asset on the heap, use one of the static constructors instead.

cugl::Sound::~Sound ( )
inline

Deletes this sound asset, disposing of all resources.

Member Function Documentation

static std::shared_ptr<Sound> cugl::Sound::alloc ( const std::string &  source)
inlinestatic

Returns a newly allocated sound asset for the given source file.

The sound will be decompressed into PCM (e.g. WAV data) which is possibly large. This will be stored in a platform specific buffer.

Parameters
sourcethe source file for the sound asset
Returns
a newly allocated sound asset for the given source file.
static std::shared_ptr<Sound> cugl::Sound::alloc ( const char *  source)
inlinestatic

Returns a newly allocated sound asset for the given source file.

The sound will be decompressed into PCM (e.g. WAV data) which is possibly large. This will be stored in a platform specific buffer.

Parameters
sourcethe source file for the sound asset
Returns
a newly allocated sound asset for the given source file.
void cugl::Sound::dispose ( )

Deletes the sound resources and resets all attributes.

This will delete the preloaded sound buffer. You must reinitialize the sound data to use it.

Uint32 cugl::Sound::getChannels ( ) const

Returns the number of channels used by this sound asset

A value of 1 means mono, while 2 means stereo. Depending on the file format, other channels are possible. For example, 6 channels means support for 5.1 surround sound.

Returns
the number of channels used by this sound asset
double cugl::Sound::getDuration ( ) const

Returns the length of this sound asset in seconds.

Because the asset is fully decompressed at load time, the result of this method is reasonably accurate.

Returns
the length of this sound asset in seconds.
Uint64 cugl::Sound::getLength ( ) const

Returns the frame length of this sound asset.

The frame length is the duration times the sample rate.

Returns
the frame length of this sound asset.
double cugl::Sound::getSampleRate ( ) const

Returns the sample rate of this sound asset.

Returns
the sample rate of this sound asset.
const std::string& cugl::Sound::getSource ( ) const
inline

Returns the source file for this sound asset.

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

Returns the file suffix for this sound asset.

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 asset.
float cugl::Sound::getVolume ( ) const
inline

Returns the default volume of this sound asset.

This default value will be used when the sound is played without a specified volume. The value is between 0 and 1, where 0 means muted and 1 is maximum volume.

Returns
the default volume of this sound asset.
bool cugl::Sound::init ( const std::string &  source)

Initializes a new sound asset for the given source file.

The sound will be decompressed into PCM (e.g. WAV data) which is possibly large. This will be stored in a platform specific buffer.

Parameters
sourcethe source file for the sound
Returns
true if the sound was initialized successfully
bool cugl::Sound::init ( const char *  source)
inline

Initializes a new sound asset for the given source file.

The sound will be decompressed into PCM (e.g. WAV data) which is possibly large. This will be stored in a platform specific buffer.

Parameters
sourcethe source file for the sound asset
Returns
true if the sound asset was initialized successfully
void cugl::Sound::setVolume ( float  volume)

Sets the default volume of this sound asset.

This default value will be used when the sound is played without a specified volume. The value is between 0 and 1, where 0 means muted and 1 is maximum volume.

Parameters
volumeThe default volume of this sound asset.

Friends And Related Function Documentation

friend class SoundChannel
friend

Allow a sound channel to access the internal buffers


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