CUGL
Cornell University Game Library
|
#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< Sound > | alloc (const std::string &source) |
static std::shared_ptr< Sound > | alloc (const char *source) |
Friends | |
class | SoundChannel |
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.
|
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.
|
inline |
Deletes this sound asset, disposing of all resources.
|
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.
source | the source file for the sound asset |
|
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.
source | the source file for the sound asset |
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.
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.
Uint64 cugl::Sound::getLength | ( | ) | const |
Returns the frame length of this sound asset.
The frame length is the duration times the sample rate.
double cugl::Sound::getSampleRate | ( | ) | const |
Returns the sample rate of this sound asset.
|
inline |
Returns the source file for this sound asset.
|
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.
|
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.
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.
source | the source file for the sound |
|
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.
source | the source file for the sound asset |
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.
volume | The default volume of this sound asset. |
|
friend |
Allow a sound channel to access the internal buffers