CUGL 2.3
Cornell University Game Library
|
#include <CUSound.h>
Public Member Functions | |
Sound () | |
~Sound () | |
virtual void | dispose () |
Uint32 | getRate () const |
Uint32 | getChannels () const |
virtual Sint64 | getLength () const |
virtual double | getDuration () const |
const std::string | getFile () const |
const std::string | getSuffix () const |
float | getVolume () const |
void | setVolume (float volume) |
virtual std::shared_ptr< audio::AudioNode > | createNode () |
Protected Attributes | |
Uint8 | _channels |
Uint32 | _rate |
std::string | _file |
float | _volume |
This class is the base type for a sound asset.
Eventually, our goal is to support arbitrary audio graphs as assets (e.g. PureData patch files). But we need a way of distinguishing a graph as an asset and a graph as an active audio instance. That is the purpose of this class. While an audio::AudioNode
is an active sound instance, this is the class of an asset file.
This is an abstract class. You should never make a sound object directly. The factory allocator will create the proper subclass. Currently there are only two completed subclass: AudioSample
and AudioWaveform
. Will expand on this in future releases.
cugl::Sound::Sound | ( | ) |
Creates a degenerate sound with no resources.
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, disposing of all resources.
|
inlinevirtual |
Returns a playble audio node for this asset.
This audio node may be attached to an audio::AudioOutput
for immediate playback. Nodes are distinct. Each call to this method allocates a new audio node.
Reimplemented in cugl::AudioSample, and cugl::AudioWaveform.
|
virtual |
Deletes the sound resources and resets all attributes.
This will delete the file reference and any allocated resources. You must reinitialize the sound data to use the object.
Reimplemented in cugl::AudioSample, and cugl::AudioWaveform.
|
inline |
Returns the number of channels used by this sound.
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. 8 channels (7.1 surround) is the current maximum.
We support up to 32 possible channels.
|
inlinevirtual |
Returns the length of this sound in seconds.
The accuracy of this method depends on the specific implementation. If the asset is infinite (e.g. AudioWaveform
), then this method returns a negative value.
Reimplemented in cugl::AudioSample, and cugl::AudioWaveform.
|
inline |
Returns the file for this sound
This value is the empty string if there was no source file.
|
inlinevirtual |
Returns the frame length of this sound.
The frame length is the number of audio samples in the asset. If the asset is infinite (e.g. AudioWaveform
), then this method returns a negative value.
Reimplemented in cugl::AudioSample, and cugl::AudioWaveform.
|
inline |
Returns the sample rate of this sound.
const std::string cugl::Sound::getSuffix | ( | ) | const |
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.
Changing this value will only affect future calls to createNode()
.
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.
Changing this value will only affect future calls to createNode()
.
volume | The default volume of this sound asset. |
|
protected |
The number of channels in this sound (max 32)
|
protected |
The source for this buffer (may be empty)
|
protected |
The sampling rate (frequency) of this sound
|
protected |
The default volume for this sound