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

#include <CUWAVDecoder.h>

Inheritance diagram for cugl::audio::WAVDecoder:
cugl::audio::AudioDecoder

Public Types

enum  Type : int {
  Type::PCM_DATA = 0, Type::IEEE_FLOAT = 1, Type::MS_ADPCM = 2, Type::IMA_ADPCM = 3,
  Type::MP3_DATA = 4, Type::UNKNOWN = 5
}
 

Public Member Functions

 WAVDecoder ()
 
 ~WAVDecoder ()
 
bool init (const char *file) override
 
bool init (const std::string &file) override
 
void dispose () override
 
Type getType () const
 
virtual 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
 
Uint8 * _chunker
 
Type _datatype
 
Uint32 _sampbits
 
Uint32 _sampsize
 
Sint64 _datamark
 
std::shared_ptr< ADPCMDecoder_adpcm
 
- 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 WAV decoder.

This decoder supports supports PCM, IEEE Float, and ADPCM encoding (both MS and IMA). However, it does not support MP3 data stored in a WAV file.
MP3 data should be stored in an MP3 file.

WAV files are not normally paged (except in the case of AD PCM). This decoder tries to balance memory requirements with efficiency in paging the WAV data. For ADPCM files, the page size is the same as the block alignment size.

All channels are interleaved. ADPCM only supports stereo, but more channels may be supported in general WAV files. SDL supports up to 6 channels in general.

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.

Member Enumeration Documentation

◆ Type

enum cugl::audio::WAVDecoder::Type : int
strong

This represents the supported WAV encoding types

More obscure coding types (e.g. DTS WAV) may or may not be supported.

Enumerator
PCM_DATA 

Raw PCM data in 16bit samples (the most common format)

IEEE_FLOAT 

Raw PCM data with 32bit float samples

MS_ADPCM 

MS encoded ADPCM data

IMA_ADPCM 

IMA encoded ADPCM data

MP3_DATA 

MP3 data encoded in a WAV file

UNKNOWN 

Unsupported WAV encoding

Constructor & Destructor Documentation

◆ WAVDecoder()

cugl::audio::WAVDecoder::WAVDecoder ( )

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.

◆ ~WAVDecoder()

cugl::audio::WAVDecoder::~WAVDecoder ( )

Deletes this decoder, disposing of all resources.

Member Function Documentation

◆ alloc() [1/2]

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

Creates a newly allocated decoder for the given WAV file.

This method will fail and return nullptr if the file is not a supported WAV file.

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

◆ alloc() [2/2]

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

Creates a newly allocated decoder for the given WAV file.

This method will fail and return nullptr if the file is not a supported WAV file.

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

◆ dispose()

void cugl::audio::WAVDecoder::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.

◆ getType()

Type cugl::audio::WAVDecoder::getType ( ) const
inline

Returns the WAV encoding type

Returns
the WAV encoding type

◆ init() [1/2]

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

Initializes a new decoder for the given WAV file.

This method will fail if the file is not a supported WAV file.

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::WAVDecoder::init ( const std::string &  file)
overridevirtual

Initializes a new decoder for the given WAV file.

This method will fail if the file is not a supported WAV file.

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

Implements cugl::audio::AudioDecoder.

◆ pagein()

virtual Sint32 cugl::audio::WAVDecoder::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::WAVDecoder::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

◆ _adpcm

std::shared_ptr<ADPCMDecoder> cugl::audio::WAVDecoder::_adpcm
protected

An optional proxy for decoding ACPCM data

◆ _chunker

Uint8* cugl::audio::WAVDecoder::_chunker
protected

The buffer for reading pages

◆ _datamark

Sint64 cugl::audio::WAVDecoder::_datamark
protected

The start of the audio stream, just after the header

◆ _datatype

Type cugl::audio::WAVDecoder::_datatype
protected

The encoding type

◆ _sampbits

Uint32 cugl::audio::WAVDecoder::_sampbits
protected

The number of bits per sample represented as a flag mask

◆ _sampsize

Uint32 cugl::audio::WAVDecoder::_sampsize
protected

The number of bytes per sample

◆ _source

SDL_RWops* cugl::audio::WAVDecoder::_source
protected

The file for loading in information


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