CUGL 2.1
Cornell University Game Library
|
#include <CUMP3Decoder.h>
Public Member Functions | |
MP3Decoder () | |
~MP3Decoder () | |
bool | init (const char *file) override |
bool | init (const std::string &file) override |
void | dispose () override |
Sint32 | pagein (float *buffer) override |
void | setPage (Uint64 page) override |
Public Member Functions inherited from cugl::audio::AudioDecoder | |
AudioDecoder () | |
~AudioDecoder () | |
double | getDuration () const |
Uint32 | getSampleRate () const |
Uint64 | getLength () const |
Uint32 | getChannels () const |
std::string | getFile () const |
Uint32 | getPageSize () const |
bool | ready () |
Uint64 | getPage () const |
Uint64 | getPageCount () const |
void | rewind () |
Sint32 | decode (float *buffer) |
Static Public Member Functions | |
static std::shared_ptr< AudioDecoder > | alloc (const char *file) |
static std::shared_ptr< AudioDecoder > | alloc (const std::string &file) |
Protected Attributes | |
Soundinputstream | _loader |
Mpegtoraw * | _decoder |
Sint16 * | _chunker |
bool | _booted |
Protected Attributes inherited from cugl::audio::AudioDecoder | |
Uint8 | _channels |
Uint32 | _rate |
Uint64 | _frames |
std::string | _file |
Uint32 | _pagesize |
Uint64 | _currpage |
Uint64 | _lastpage |
This class represents an MP3 decoder.
This decoder accesses the MP3 in the traditionally grouping of 1152 frames (we use frames to refer to samples, consistent with modern usage) per page. This class uses Jung woo-jae's free MPEG/WAVE Sound library to convert the individual pages into raw PCM data.
All channels are interleaved. Because of the age of the MPEG/WAVE Sound library, this decoder only supports stereo and mono MP3 files. In particular, it does not support MP3 surround.
A decoder is NOT thread safe. If a decoder is used by an audio thread, then it should not be accessed directly in the main thread, and vice versa.
cugl::audio::MP3Decoder::MP3Decoder | ( | ) |
Creates an initialized audio decoder
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an asset on the heap, use one of the static constructors instead.
cugl::audio::MP3Decoder::~MP3Decoder | ( | ) |
Deletes this decoder, disposing of all resources.
|
inlinestatic |
Creates a newly allocated decoder for the given MP3 file.
This method will fail and return nullptr if the file is not a (stereo or mono) MP3 file.
file | the source file for the decoder |
|
static |
Creates a newly allocated decoder for the given MP3 file.
This method will fail and return nullptr if the file is not a (stereo or mono) MP3 file.
file | the source file for the decoder |
|
overridevirtual |
Deletes the decoder resources and resets all attributes.
This will close the associated file. You must reinitialize the decoder to use it.
Implements cugl::audio::AudioDecoder.
|
inlineoverridevirtual |
Initializes a new decoder for the given MP3 file.
This method will fail if the file is not a (stereo or mono) MP3 file.
file | the source file for the decoder |
Reimplemented from cugl::audio::AudioDecoder.
|
overridevirtual |
Initializes a new decoder for the given MP3 file.
This method will fail if the file is not a (stereo or mono) MP3 file.
file | the source file for the decoder |
Implements cugl::audio::AudioDecoder.
|
overridevirtual |
Reads a page of data into the provided buffer.
The buffer should be able to hold channels * page size many elements. The data is interpretted as floats and channels are all interleaved. If a full page is read, this method should return the page size. If it reads less, it will return the number of frames read. It will return -1 on a processing error.
buffer | The buffer to store the audio data |
Implements cugl::audio::AudioDecoder.
|
overridevirtual |
Sets the current page of this decoder
This value is the next page to be read in with the pagein() command. If the page is greater than the total number of pages, it will be set just beyond the last page.
page | The new page of this decoder |
Implements cugl::audio::AudioDecoder.
|
protected |
Whether this decoder was successfully booted
|
protected |
The buffer for reading pages
|
protected |
The MP3 decoder
|
protected |
The loader for reading from a file