CUGL
Cornell University Game Library
|
#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< Music > | alloc (const std::string &source) |
static std::shared_ptr< Music > | alloc (const char *source) |
Friends | |
class | MusicQueue |
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.
|
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.
|
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.
|
inline |
Deletes this music asset, disposing of all resources.
|
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).
source | the source file for the music asset |
|
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).
source | the source file for the music asset |
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.
|
inline |
Returns the source file for this music asset.
|
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.
Type cugl::Music::getType | ( | ) | const |
Returns the encoding type for this music asset.
|
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.
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).
source | the source file for the music asset |
|
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).
source | the source file for the music asset |
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.
volume | The default volume of this music asset. |
|
friend |
Allow a music queue to access the internal buffers