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

#include <CUMusic.h>

Public Types

enum  Type : int {
  Type::WAV = 0, Type::MP3 = 1, Type::AAC = 2, Type::OGG = 3,
  Type::M4A = 4, Type::FLAC = 5, Type::UNSUPPORTED = 6
}
 

Public Member Functions

 Music ()
 
 ~Music ()
 
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
 
Type getType () const
 
float getVolume () const
 
void setVolume (float volume)
 

Static Public Member Functions

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

Friends

class MusicQueue
 

Detailed Description

Class provides a reference to a streaming asset.

Music assets are not loaded entirely into memory. Instead, they are streamed from a file. This assets should not be used for low-latency sound effects. Those should be processed as a Sound asset instead.

These best cross-platform options for this asset are MP3 and OGG Vorbis. All other options (AAC, FLAC, M4A) only work on specific platforms.

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

Member Enumeration Documentation

enum cugl::Music::Type : int
strong

The type of supported music files

Beware that not all platforms support all music types. Right now, the only guaranteed assets that work on more than one platform are WAV and MP3 files.

Enumerator
WAV 

Uncompressed WAV (why are you doing this for music)

MP3 

The good old standard, royalty free as of April 2017

AAC 

The Apple alternative to MP3

OGG 

The Linux alternative to MP3

M4A 

The Apple lossless encoding

FLAC 

The Linux lossless encoding

UNSUPPORTED 

Either the encoding is unknown or unsupported

Constructor & Destructor Documentation

cugl::Music::Music ( )
inline

Creates a degenerate music asset with no buffer.

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

cugl::Music::~Music ( )
inline

Deletes this music asset, disposing of all resources.

Member Function Documentation

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

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

The sound will be decoded immediately. However, the actual data will be streamed from disk.

Be aware that music files are very not platform. SDL wants to support the Linux options (OGG, FLAC), while Apple wants to support its own options (AAC, M4A). We are working on fixing this, but until we do, you should probably make different sound assets for the Android and Apple platforms (unless you just want to use MP3 and WAV).

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

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

The sound will be decoded immediately. However, the actual data will be streamed from disk.

Be aware that music files are very not platform. SDL wants to support the Linux options (OGG, FLAC), while Apple wants to support its own options (AAC, M4A). We are working on fixing this, but until we do, you should probably make different sound assets for the Android and Apple platforms (unless you just want to use MP3 and WAV).

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

Deletes the music resources and resets all attributes.

This will delete decoding information for the stream. You must reinitialize the music data to use it.

double cugl::Music::getDuration ( ) const

Returns the length of this music asset in seconds.

This information is retrieved from the decoder. As the file is completely decoded at load time, the result of this method is reasonably accurate.

Returns
the length of this music asset in seconds.
const std::string& cugl::Music::getSource ( ) const
inline

Returns the source file for this music asset.

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

Returns the file suffix for this music asset.

While we have another function below to return the music encoding type, we still include this method to unify it with sound assets.

Returns
the file suffix for this music asset.
Type cugl::Music::getType ( ) const

Returns the encoding type for this music asset.

Returns
the encoding type for this music asset.
float cugl::Music::getVolume ( ) const
inline

Returns the default volume of this music 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 music asset.
bool cugl::Music::init ( const std::string &  source)

Initializes a new music asset for the given source file.

The sound will be decoded immediately. However, the actual data will be streamed from disk.

Be aware that music files are very not platform. SDL wants to support the Linux options (OGG, FLAC), while Apple wants to support its own options (AAC, M4A). We are working on fixing this, but until we do, you should probably make different sound assets for the Android and Apple platforms (unless you just want to use MP3 and WAV).

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

Initializes a new music asset for the given source file.

The sound will be decoded immediately. However, the actual data will be streamed from disk.

Be aware that music files are very not platform. SDL wants to support the Linux options (OGG, FLAC), while Apple wants to support its own options (AAC, M4A). We are working on fixing this, but until we do, you should probably make different sound assets for the Android and Apple platforms (unless you just want to use MP3 and WAV).

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

Sets the default volume of this music 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 music asset.

Friends And Related Function Documentation

friend class MusicQueue
friend

Allow a music queue to access the internal buffers


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