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

#include <CUOGGDecoder.h>

Inheritance diagram for cugl::audio::OGGDecoder:
cugl::audio::AudioDecoder

Public Member Functions

 OGGDecoder ()
 
 ~OGGDecoder ()
 
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< AudioDecoderalloc (const char *file)
 
static std::shared_ptr< AudioDecoderalloc (const std::string &file)
 

Protected Attributes

SDL_RWops * _source
 
OggVorbis_File _oggfile
 
int _bitstream
 
- Protected Attributes inherited from cugl::audio::AudioDecoder
Uint8 _channels
 
Uint32 _rate
 
Uint64 _frames
 
std::string _file
 
Uint32 _pagesize
 
Uint64 _currpage
 
Uint64 _lastpage
 

Detailed Description

This class represents an OGG decoder.

This class only supports Vorbis encodings. It does not support Flac data encoded in an Ogg file container. It also does not support the newer Opus codec.

Ogg Vorbis supports up to 8 channels (7.1 stereo), though SDL is limited to 6 channels (5.1 stereo). The channel layout for Ogg data is nonstandard (e.g. channels > 3 are not stereo compatible), so this decoder standardizes the channel layout to agree with FLAC and other data encodings. The channels are interleaved.

OGG files are not guaranteed to have uniform page sizes. This decoder tries to balance memory requirements with efficiency in paging frame data.

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.

Constructor & Destructor Documentation

◆ OGGDecoder()

cugl::audio::OGGDecoder::OGGDecoder ( )

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.

◆ ~OGGDecoder()

cugl::audio::OGGDecoder::~OGGDecoder ( )

Deletes this decoder, disposing of all resources.

Member Function Documentation

◆ alloc() [1/2]

static std::shared_ptr<AudioDecoder> cugl::audio::OGGDecoder::alloc ( const char *  file)
inlinestatic

Creates a newly allocated decoder for the given OGG file.

This method will fail and return nullptr if the file does not contain Vorbis data.

Parameters
filethe source file for the decoder
Returns
a newly allocated decoder for the given OGG file.

◆ alloc() [2/2]

static std::shared_ptr<AudioDecoder> cugl::audio::OGGDecoder::alloc ( const std::string &  file)
static

Creates a newly allocated decoder for the given OGG file.

This method will fail and return nullptr if the file does not contain Vorbis data.

Parameters
filethe source file for the decoder
Returns
a newly allocated decoder for the given OGG file.

◆ dispose()

void cugl::audio::OGGDecoder::dispose ( )
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.

◆ init() [1/2]

bool cugl::audio::OGGDecoder::init ( const char *  file)
inlineoverridevirtual

Initializes a new decoder for the given OGG file.

This method will fail if the file does not contain Vorbis data.

Parameters
filethe source file for the decoder
Returns
true if the decoder was initialized successfully

Reimplemented from cugl::audio::AudioDecoder.

◆ init() [2/2]

bool cugl::audio::OGGDecoder::init ( const std::string &  file)
overridevirtual

Initializes a new decoder for the given OGG file.

This method will fail if the file does not contain Vorbis data.

Parameters
filethe source file for the decoder
Returns
true if the decoder was initialized successfully

Implements cugl::audio::AudioDecoder.

◆ pagein()

Sint32 cugl::audio::OGGDecoder::pagein ( float *  buffer)
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.

Parameters
bufferThe buffer to store the audio data
Returns
the number of frames actually read (-1 on error).

Implements cugl::audio::AudioDecoder.

◆ setPage()

void cugl::audio::OGGDecoder::setPage ( Uint64  page)
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.

Parameters
pageThe new page of this decoder

Implements cugl::audio::AudioDecoder.

Member Data Documentation

◆ _bitstream

int cugl::audio::OGGDecoder::_bitstream
protected

Reference to the logical bitstream for decoding

◆ _oggfile

OggVorbis_File cugl::audio::OGGDecoder::_oggfile
protected

The OGG decoder struct

◆ _source

SDL_RWops* cugl::audio::OGGDecoder::_source
protected

The file for loading in information


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