CUGL 2.1
Cornell University Game Library
Public Member Functions | Protected Attributes | List of all members
cugl::Sound Class Reference

#include <CUSound.h>

Inheritance diagram for cugl::Sound:
cugl::AudioSample cugl::AudioWaveform

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::AudioNodecreateNode ()
 

Protected Attributes

Uint8 _channels
 
Uint32 _rate
 
std::string _file
 
float _volume
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Sound()

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.

◆ ~Sound()

cugl::Sound::~Sound ( )
inline

Deletes this sound, disposing of all resources.

Member Function Documentation

◆ createNode()

virtual std::shared_ptr<audio::AudioNode> cugl::Sound::createNode ( )
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.

Returns
a playble audio node for this asset.

Reimplemented in cugl::AudioWaveform, and cugl::AudioSample.

◆ dispose()

virtual void cugl::Sound::dispose ( )
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::AudioWaveform, and cugl::AudioSample.

◆ getChannels()

Uint32 cugl::Sound::getChannels ( ) const
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.

Returns
the number of channels used by this sound.

◆ getDuration()

virtual double cugl::Sound::getDuration ( ) const
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.

Returns
the length of this sound in seconds.

Reimplemented in cugl::AudioWaveform, and cugl::AudioSample.

◆ getFile()

const std::string cugl::Sound::getFile ( ) const
inline

Returns the file for this sound

This value is the empty string if there was no source file.

Returns
the file for this sound

◆ getLength()

virtual Sint64 cugl::Sound::getLength ( ) const
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.

Returns
the frame length of this sound.

Reimplemented in cugl::AudioWaveform, and cugl::AudioSample.

◆ getRate()

Uint32 cugl::Sound::getRate ( ) const
inline

Returns the sample rate of this sound.

Returns
the sample rate of this sound.

◆ getSuffix()

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.

Returns
the file suffix for this sound asset.

◆ getVolume()

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.

Changing this value will only affect future calls to createNode().

Returns
the default volume of this sound asset.

◆ setVolume()

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().

Parameters
volumeThe default volume of this sound asset.

Member Data Documentation

◆ _channels

Uint8 cugl::Sound::_channels
protected

The number of channels in this sound (max 32)

◆ _file

std::string cugl::Sound::_file
protected

The source for this buffer (may be empty)

◆ _rate

Uint32 cugl::Sound::_rate
protected

The sampling rate (frequency) of this sound

◆ _volume

float cugl::Sound::_volume
protected

The default volume for this sound


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