Skip to content

Encoder

class Encoder

Audio file writer.

The Encoder is built by a Codec instance. It's used to write data to an audio file.

The Write() methods of an encoder implementation must be thread safe.

Variables

Name Description
m_format The audio sample format of the file to write using this encoder.
m_codec The codec instance which built this decoder.

Functions

Name Description
Encoder Creates a new instance of the encoder for the given codec.
~Encoder Default destructor.
Open Opens or create a file at the given path to start encoding.
Close Closes a previously opened file.
SetFormat Sets the audio sample format.
Write Writes the given buffer into the file.

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 to write using this encoder.

The sound format must be set before the initialization of this encoder. Otherwise, the encoder initialization should fail.

Note

The final behavior depend on the specific codec implementation.

Function Details

Close

virtual bool Close() = 0

Closes a previously opened file.

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

Encoder

explicit Encoder(const Codec* codec)

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

Parameter codec
The codec wrapper for the encoder.

Open

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

Opens or create a file at the given path to start encoding.

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

SetFormat

virtual void SetFormat(const SoundFormat& format)

Sets the audio sample format.

Parameter format
The audio sample format.

Write

virtual AmUInt64 Write(AudioBuffer* in, AmUInt64 offset, AmUInt64 length) = 0

Writes the given buffer into the file.

Parameter in
The buffer to write into the the file.
Parameter offset
The offset in frames from which write the input buffer.
Parameter length
The length in frames to write from the input buffer.
Return
The number of frames written.

~Encoder

virtual ~Encoder() = default

Default destructor.