arduino-audio-tools
Loading...
Searching...
No Matches
OpusAudioEncoder Class Reference

Encode for Opus audio. More...

#include <CodecOpus.h>

Inheritance diagram for OpusAudioEncoder:
AudioEncoder AudioWriter MimeSource AudioWriter MimeSource AudioInfoSupport AudioInfoSupport AudioInfoSupport AudioInfoSupport

Public Member Functions

 OpusAudioEncoder ()=default
 OpusAudioEncoder (Print &out)
AudioInfo audioInfo () override
 provides the actual input AudioInfo
AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
virtual bool begin (AudioInfo info)
bool begin () override
 starts the processing using the actual OpusAudioInfo
bool begin (OpusEncoderSettings settings)
OpusEncoderSettings & config ()
 Provides access to the configuration.
OpusEncoderSettings & defaultConfig ()
void end () override
 stops the processing
virtual uint32_t frameDurationUs ()
 Optional rtsp function: provide the frame duration in microseconds.
virtual uint32_t frameDurationUs ()
 Optional rtsp function: provide the frame duration in microseconds.
virtual int frameSize ()
virtual int frameSize ()
int frameSizeSamples ()
bool isOpen ()
int lookaheadSamples ()
const char * mime () override
 Provides "audio/pcm".
 operator bool () override
int pendingSamples ()
uint16_t samplesPerFrame ()
 Optional rtsp function: provide samples per the frame.
void setAudioInfo (AudioInfo from) override
 Defines the sample rate, number of channels and bits per sample.
void setAudioInfo (AudioInfo from) override
 We actually do nothing with this.
void setOutput (Print &out_stream) override
 Defines the output Stream.
size_t write (const uint8_t *data, size_t len) override
 Writes PCM data to be encoded as Opus.

Protected Member Functions

void encodeByte (uint8_t data)
void encodeFrame ()
int getFrameSizeSamples (int sampling_rate)
 Returns the frame size in samples.
bool settings ()
void writeBlocking (Print *out, uint8_t *data, size_t len)
void writeBlocking (Print *out, uint8_t *data, size_t len)

Protected Attributes

OpusEncoderSettings cfg
OpusEncoder * enc = nullptr
Vector< uint8_t > frame {0}
int frame_pos = 0
AudioInfo info
bool is_open = false
Print * p_print = nullptr

Detailed Description

Encode for Opus audio.

Depends on https://github.com/pschatzmann/codec-opus.git Please note that each fully encoded frame is written to the output stream.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ OpusAudioEncoder() [1/2]

OpusAudioEncoder ( )
default

◆ OpusAudioEncoder() [2/2]

OpusAudioEncoder ( Print & out)
inline

Member Function Documentation

◆ audioInfo() [1/2]

AudioInfo audioInfo ( )
inlineoverridevirtualinherited

provides the actual input AudioInfo

Implements AudioInfoSupport.

Reimplemented in CodecNOP, CodecNOP, BinaryContainerEncoder, CodecNOP, MP3EncoderShine, and MP3ParserEncoder.

◆ audioInfo() [2/2]

AudioInfo audioInfo ( )
inlineoverridevirtualinherited

provides the actual input AudioInfo

Implements AudioInfoSupport.

Reimplemented in CodecNOP, CodecNOP, BinaryContainerEncoder, CodecNOP, MP3EncoderShine, and MP3ParserEncoder.

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ begin() [1/3]

virtual bool begin ( AudioInfo info)
inlinevirtualinherited

Reimplemented in AudioDecoder, and AudioDecoder.

◆ begin() [2/3]

bool begin ( )
inlineoverridevirtual

starts the processing using the actual OpusAudioInfo

Implements AudioWriter.

◆ begin() [3/3]

bool begin ( OpusEncoderSettings settings)
inline

◆ config()

OpusEncoderSettings & config ( )
inline

Provides access to the configuration.

◆ defaultConfig()

OpusEncoderSettings & defaultConfig ( )
inline

◆ encodeByte()

void encodeByte ( uint8_t data)
inlineprotected

◆ encodeFrame()

void encodeFrame ( )
inlineprotected

◆ end()

void end ( )
inlineoverridevirtual

stops the processing

Implements AudioWriter.

◆ frameDurationUs() [1/2]

virtual uint32_t frameDurationUs ( )
inlinevirtualinherited

Optional rtsp function: provide the frame duration in microseconds.

Reimplemented in ADPCMEncoder, MetaDataFilterEncoder, MP3EncoderShine, MP3ParserEncoder, and OpusOggEncoder.

◆ frameDurationUs() [2/2]

virtual uint32_t frameDurationUs ( )
inlinevirtualinherited

Optional rtsp function: provide the frame duration in microseconds.

Reimplemented in ADPCMEncoder, MetaDataFilterEncoder, MP3EncoderShine, MP3ParserEncoder, and OpusOggEncoder.

◆ frameSize() [1/2]

virtual int frameSize ( )
inlinevirtualinherited

Optional rtsp function: provide the encoded size (in bytes) of one frame, once known (e.g. after the encoder has seen real data). Lets an RTSPFormat size its RTP fragments to match one frame instead of a fixed guess, so throughput actually tracks frameDurationUs() - a fragment size covering several frames' worth of bytes sent at one-frame timing overruns real-time bandwidth and, over UDP (no flow control), causes packet loss. Returns 0 if not yet known/not applicable (fixed-frame-size codecs have no need to override this).

Reimplemented in ADPCMEncoder, AMRNBEncoder, AMRWBEncoder, EncoderALAC, and MP3ParserEncoder.

◆ frameSize() [2/2]

virtual int frameSize ( )
inlinevirtualinherited

Optional rtsp function: provide the encoded size (in bytes) of one frame, once known (e.g. after the encoder has seen real data). Lets an RTSPFormat size its RTP fragments to match one frame instead of a fixed guess, so throughput actually tracks frameDurationUs() - a fragment size covering several frames' worth of bytes sent at one-frame timing overruns real-time bandwidth and, over UDP (no flow control), causes packet loss. Returns 0 if not yet known/not applicable (fixed-frame-size codecs have no need to override this).

Reimplemented in ADPCMEncoder, AMRNBEncoder, AMRWBEncoder, EncoderALAC, and MP3ParserEncoder.

◆ frameSizeSamples()

int frameSizeSamples ( )
inline

◆ getFrameSizeSamples()

int getFrameSizeSamples ( int sampling_rate)
inlineprotected

Returns the frame size in samples.

◆ isOpen()

bool isOpen ( )
inline

◆ lookaheadSamples()

int lookaheadSamples ( )
inline

◆ mime()

const char * mime ( )
inlineoverridevirtual

Provides "audio/pcm".

Implements AudioEncoder.

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Implements AudioWriter.

◆ pendingSamples()

int pendingSamples ( )
inline

◆ samplesPerFrame()

uint16_t samplesPerFrame ( )
inlinevirtual

Optional rtsp function: provide samples per the frame.

Reimplemented from AudioEncoder.

◆ setAudioInfo() [1/2]

void setAudioInfo ( AudioInfo from)
inlineoverridevirtualinherited

Defines the sample rate, number of channels and bits per sample.

Implements AudioWriter.

Reimplemented in CodecNOP, and CodecNOP.

◆ setAudioInfo() [2/2]

void setAudioInfo ( AudioInfo from)
inlineoverride

We actually do nothing with this.

◆ setOutput()

void setOutput ( Print & out_stream)
inlineoverridevirtual

Defines the output Stream.

Reimplemented from AudioEncoder.

◆ settings()

bool settings ( )
inlineprotected

◆ write()

size_t write ( const uint8_t * data,
size_t len )
inlineoverridevirtual

Writes PCM data to be encoded as Opus.

Implements AudioWriter.

◆ writeBlocking() [1/2]

void writeBlocking ( Print * out,
uint8_t * data,
size_t len )
inlineprotectedinherited

◆ writeBlocking() [2/2]

void writeBlocking ( Print * out,
uint8_t * data,
size_t len )
inlineprotectedinherited

Member Data Documentation

◆ cfg

OpusEncoderSettings cfg
protected

◆ enc

OpusEncoder* enc = nullptr
protected

◆ frame

Vector<uint8_t> frame {0}
protected

◆ frame_pos

int frame_pos = 0
protected

◆ info

AudioInfo info
protectedinherited

◆ is_open

bool is_open = false
protected

◆ p_print

Print* p_print = nullptr
protected

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