Arduino FDK AAC Encoder and Decoder Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
aac_fdk::AACEncoderFDK Class Reference

Encodes PCM data to the AAC format and writes the result to a stream. More...

#include <AACEncoderFDK.h>

Public Member Functions

 AACEncoderFDK ()
 Empty Constructor.
 
 AACEncoderFDK (AACCallbackFDK cb)
 Default constructor.
 
 ~AACEncoderFDK ()
 Destructor.
 
 AACEncoderFDK (Stream &out_stream)
 
void setOutput (Print &out_stream)
 Defines the output stream.
 
void setDataCallback (AACCallbackFDK cb)
 Defines the callback method.
 
void setBitrate (int bitrate)
 Total encoder bitrate. This parameter is mandatory and interacts with AACENC_BITRATEMODE. More...
 
void setAudioObjectType (int aot)
 Audio object type. See ::AUDIO_OBJECT_TYPE in FDK_audio.h. More...
 
void setAfterburner (bool afterburner)
 This parameter controls the use of the afterburner feature. The afterburner is a type of analysis by synthesis algorithm which increases the audio quality but also the required processing power. It is recommended to always activate this if additional memory consumption and processing power consumption is not a problem. If increased MHz and memory consumption are an issue then the MHz and memory cost of this optional module need to be evaluated against the improvement in audio quality on a case by case basis. More...
 
void setSpectralBandReplication (int eld_sbr)
 Configure SBR independently of the chosen Audio Object Type ::AUDIO_OBJECT_TYPE. This parameter is for ELD audio object type only. More...
 
void setVariableBitrateMode (int vbr)
 Bitrate mode. Configuration can be different kind of bitrate configurations: More...
 
void setOutputBufferSize (int outbuf_size)
 Set the Output Buffer Size object. More...
 
void setAudioInfo (AudioInfo from)
 Defines the Audio Info.
 
void begin ()
 Opens the encoder - Please call setAudioInfo before.
 
void begin (AudioInfo info)
 Opens the encoder
More...
 
bool begin (int input_channels, int input_sample_rate, int input_bits_per_sample)
 Opens the encoder
More...
 
int32_t write (uint8_t *in_ptr, int in_size)
 write PCM data to be converted to AAC - The size is in bytes
 
void end ()
 closes the processing and release resources
 
UINT getParameter (const AACENC_PARAM param)
 determines a decoder parameter
 
int setParameter (AACENC_PARAM param, uint32_t value)
 sets an encoder parameter
 
 operator boolean ()
 

Protected Member Functions

bool setup ()
 starts the processing
 
int updateParams ()
 Updates all parameters with the values defined by the setter methods.
 
void provideResult (uint8_t *data, size_t len)
 return the result PWM data
 
void setEncoderModules (UINT encModules)
 Specify encoder modules to be supported in this encoder (0x01: AAC module,0x02: SBR module,0x04: PS module,0x10: Metadata module). E.g. (0x01|0x02|0x04|0x10) - Use 0 for all modules.
 
const char * setupErrorText (int no)
 convert error code to error text
 

Protected Attributes

int vbr = 0
 
int bitrate = 0
 
int ch = 0
 
int format
 
int sample_rate
 
int channels =2
 
int bits_per_sample
 
int aot = 2
 
bool afterburner = false
 
int eld_sbr = 0
 
HANDLE_AACENCODER handle
 
CHANNEL_MODE mode
 
AACENC_InfoStruct info = { 0 }
 
AACENC_BufDesc in_buf = { 0 }
 
AACENC_BufDesc out_buf = { 0 }
 
AACENC_InArgs in_args = { 0 }
 
AACENC_OutArgs out_args = { 0 }
 
int in_identifier = IN_AUDIO_DATA
 
int in_elem_size
 
int out_identifier = OUT_BITSTREAM_DATA
 
int out_elem_size =1
 
uint8_t * outbuf = nullptr
 
int out_size = 2048
 
AACENC_ERROR err
 
bool active = false
 
AACCallbackFDK aacCallback =nullptr
 
UINT encModules = 0x01
 
UINT openEncModules = 0
 
int openChannels = 0
 
int sce =0
 
int cpe =0
 
Print * out
 

Detailed Description

Encodes PCM data to the AAC format and writes the result to a stream.

Member Function Documentation

◆ begin() [1/2]

void aac_fdk::AACEncoderFDK::begin ( AudioInfo  info)
inline

Opens the encoder

Parameters
info
Returns
int

◆ begin() [2/2]

bool aac_fdk::AACEncoderFDK::begin ( int  input_channels,
int  input_sample_rate,
int  input_bits_per_sample 
)
inline

Opens the encoder

Parameters
input_channels
input_sample_rate
input_bits_per_sample
Returns
int 0 => ok; error with negative number

◆ setAfterburner()

void aac_fdk::AACEncoderFDK::setAfterburner ( bool  afterburner)
inline

This parameter controls the use of the afterburner feature. The afterburner is a type of analysis by synthesis algorithm which increases the audio quality but also the required processing power. It is recommended to always activate this if additional memory consumption and processing power consumption is not a problem. If increased MHz and memory consumption are an issue then the MHz and memory cost of this optional module need to be evaluated against the improvement in audio quality on a case by case basis.

  • 0: Disable afterburner (default).
  • 1: Enable afterburner.

◆ setAudioObjectType()

void aac_fdk::AACEncoderFDK::setAudioObjectType ( int  aot)
inline

Audio object type. See ::AUDIO_OBJECT_TYPE in FDK_audio.h.

  • 2: MPEG-4 AAC Low Complexity.
  • 5: MPEG-4 AAC Low Complexity with Spectral Band Replication (HE-AAC).
  • 29: MPEG-4 AAC Low Complexity with Spectral Band Replication and Parametric Stereo (HE-AAC v2). This configuration can be used only with stereo input audio data.
  • 23: MPEG-4 AAC Low-Delay.
  • 39: MPEG-4 AAC Enhanced Low-Delay. Since there is no ::AUDIO_OBJECT_TYPE for ELD in combination with SBR defined, enable SBR explicitely by AACENC_SBR_MODE parameter. The ELD v2 212 configuration can be configured by AACENC_CHANNELMODE parameter.
  • 129: MPEG-2 AAC Low Complexity.
  • 132: MPEG-2 AAC Low Complexity with Spectral Band Replication (HE-AAC).

Please note that the MPEG-2 AOT's basically disables non-existing Perceptual Noise Substitution tool in AAC encoder and controls the MPEG_ID flag in adts header. The MPEG-2 AOT doesn't prohibit specific transport formats.

◆ setBitrate()

void aac_fdk::AACEncoderFDK::setBitrate ( int  bitrate)
inline

Total encoder bitrate. This parameter is mandatory and interacts with AACENC_BITRATEMODE.

  • CBR: Bitrate in bits/second.
  • VBR: Variable bitrate. Bitrate argument will be ignored. See suppBitrates for details.

◆ setOutputBufferSize()

void aac_fdk::AACEncoderFDK::setOutputBufferSize ( int  outbuf_size)
inline

Set the Output Buffer Size object.

Parameters
outbuf_size

◆ setSpectralBandReplication()

void aac_fdk::AACEncoderFDK::setSpectralBandReplication ( int  eld_sbr)
inline

Configure SBR independently of the chosen Audio Object Type ::AUDIO_OBJECT_TYPE. This parameter is for ELD audio object type only.

  • -1: Use ELD SBR auto configurator (default).
  • 0: Disable Spectral Band Replication.
  • 1: Enable Spectral Band Replication.

◆ setVariableBitrateMode()

void aac_fdk::AACEncoderFDK::setVariableBitrateMode ( int  vbr)
inline

Bitrate mode. Configuration can be different kind of bitrate configurations:

  • 0: Constant bitrate, use bitrate according to AACENC_BITRATE. (default) Within none LD/ELD ::AUDIO_OBJECT_TYPE, the CBR mode makes use of full allowed bitreservoir. In contrast, at Low-Delay ::AUDIO_OBJECT_TYPE the bitreservoir is kept very small.
  • 1: Variable bitrate mode, very low bitrate.
  • 2: Variable bitrate mode, low bitrate.
  • 3: Variable bitrate mode, medium bitrate.
  • 4: Variable bitrate mode, high bitrate.
  • 5: Variable bitrate mode, very high bitrate.

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