Skip to content

Decoder

class Decoder

Audio file reader.

The Decoder is built by a Codec instance. It's used to read an audio file and process its data. Each implementation should allow to load the entire file into memory or stream it from the file system.

The Stream() method of a decoder implementation must be thread-safe.

Variables

Name Description
m_format The audio sample format of the file currently loaded by this decoder.
m_codec The codec instance which built this decoder.

Functions

Name Description
Decoder Creates a new instance of the decoder for the given codec.
~Decoder Default destructor.
Open Opens the given file to start decoding.
Close Closes the previously opened file.
GetFormat Gets the audio sample format.
Load Loads the entire audio file into the output buffer.
Stream Streams a part of the file from disk into the output buffer.
Seek Moves the cursor to the given frame.

Variable Details

m_codec

const Codec* m_codec

The codec instance which built this decoder.

m_format

SoundFormat m_format

The audio sample format of the file currently loaded by this decoder.

The sound format must be filled during the initialization of this decoder.

Function Details

Close

virtual bool Close() = 0

Closes the previously opened file.

Return
true if the file was closed successfully, false otherwise.

Decoder

explicit Decoder(const Codec* codec)

Creates a new instance of the decoder for the given codec.

Parameter codec
The codec wrapper for the decoder.

GetFormat

[[nodiscard]] const SoundFormat& GetFormat() const

Gets the audio sample format.

Return
The audio sample format.
See
SoundFormat

Load

virtual AmUInt64 Load(AudioBuffer* out) = 0

Loads the entire audio file into the output buffer.

The output buffer must allocate enough size for this operation to be successful.

Parameter out
The buffer to load audio data data into.
Return
The number of audio frames loaded into the buffer.

Open

virtual bool Open(std::shared_ptr<File> file) = 0

Opens the given file to start decoding.

Parameter file
The file to read.
Return
true if the file was opened successfully, false otherwise.

Seek

virtual bool Seek(AmUInt64 offset) = 0

Moves the cursor to the given frame.

Parameter offset
The offset in frames to move the cursor to.
Return
true if the cursor was moved successfully, false otherwise.

Stream

virtual AmUInt64 Stream(AudioBuffer* out, AmUInt64 bufferOffset, AmUInt64 seekOffset, AmUInt64 length) = 0

Streams a part of the file from disk into the output buffer.

Parameter out
The buffer to stream the file data into.
Parameter bufferOffset
The offset in frames from which start to write in the out buffer.
Parameter seekOffset
The offset in frames from which start to read the file.
Parameter length
The length in frames to read from the file.
Return
The number of frames read.

~Decoder

virtual ~Decoder() = default

Default destructor.