utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::sound::AAudioDecoder Class Referenceabstract

Abstract base class for audio decoders. More...

#include <headers/utility/sound/decoder/audio_decoder.hpp>

Inheritance diagram for utility::sound::AAudioDecoder:

Public Member Functions

virtual ~AAudioDecoder ()=default
 Virtual destructor.
 
virtual bool canDecode (const std::string &filePath) const =0
 Determines whether the decoder supports the specified file.
 
virtual bool canDecode (AudioDecoderType type=AudioDecoderType::UNKNOWN) const =0
 Determines whether the decoder supports the specified audio type.
 
virtual std::shared_ptr< AudioBufferdecode (std::shared_ptr< utility::File > file)=0
 Decodes an audio file into an AudioBuffer.
 
ALenum getALFormat (uint16_t channels, uint16_t bitsPerSample) const
 Converts audio properties to an OpenAL format.
 

Detailed Description

Abstract base class for audio decoders.

This class defines the common interface for decoding audio files into AudioBuffer objects that can be played through the audio subsystem.

Concrete implementations are responsible for:

  • Detecting whether they support a specific audio format
  • Reading and decoding audio data from files
  • Converting decoded samples to a format compatible with OpenAL
  • Creating and populating AudioBuffer instances

Supported formats are identified either by file path or by AudioDecoderType.

Definition at line 123 of file audio_decoder.hpp.

Member Function Documentation

◆ canDecode() [1/2]

virtual bool utility::sound::AAudioDecoder::canDecode ( AudioDecoderType  type = AudioDecoderType::UNKNOWN) const
pure virtual

Determines whether the decoder supports the specified audio type.

Parameters
typeThe audio format to test.
Returns
true if the decoder supports the specified type, false otherwise.

Implemented in utility::sound::MP3Decoder, and utility::sound::WAVDecoder.

◆ canDecode() [2/2]

virtual bool utility::sound::AAudioDecoder::canDecode ( const std::string &  filePath) const
pure virtual

Determines whether the decoder supports the specified file.

Implementations typically inspect the file extension or file contents to determine compatibility.

Parameters
filePathPath to the audio file.
Returns
true if the decoder supports the specified file, false otherwise.

Implemented in utility::sound::MP3Decoder, and utility::sound::WAVDecoder.

◆ decode()

virtual std::shared_ptr< AudioBuffer > utility::sound::AAudioDecoder::decode ( std::shared_ptr< utility::File file)
pure virtual

Decodes an audio file into an AudioBuffer.

This function reads the specified file, decodes its audio content, uploads the decoded samples to an AudioBuffer, and returns the resulting buffer.

Parameters
fileThe file containing the encoded audio data.
Returns
A shared pointer to the decoded AudioBuffer.
Exceptions
std::runtime_errorIf decoding fails or the file format is invalid.

Implemented in utility::sound::MP3Decoder, and utility::sound::WAVDecoder.

◆ getALFormat()

ALenum utility::sound::AAudioDecoder::getALFormat ( uint16_t  channels,
uint16_t  bitsPerSample 
) const

Converts audio properties to an OpenAL format.

This helper function maps the specified channel count and sample size to the corresponding OpenAL format enumeration.

Parameters
channelsNumber of audio channels.
bitsPerSampleNumber of bits per sample.
Returns
The corresponding OpenAL format.
Exceptions
std::runtime_errorIf the specified format is unsupported.

Definition at line 24 of file audio_decoder.cpp.


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