fdkaac

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 3 Imported by: 0

README

PkgGoDev

fdk-aac-go

Go bindings for fdk-aac. A standalone library of the Fraunhofer FDK AAC code from Android.

Why fdk-aac-go

The purpose of fdk-aac-go is easing the adoption of fdk-aac codec library. Using Go, with just a few lines of code you can implement an application that encode/decode data easy.

Is this a new implementation of fdk-aac?

No! We are just exposing the great work done by the research organization of Fraunhofer IIS as a golang library. All the functionality and implementation still resides in the official fdk-aac project.

Features supported

  • Decode AAC to PCM
  • Encode PCM to AAC

Usage

Decode AAC frame to PCM

package main

import (
	"fmt"

	fdkaac "github.com/qrtc/fdk-aac-go"
)

func main() {
	decoder, err := fdkaac.CreateAccDecoder(&fdkaac.AacDecoderConfig{
		TransportFmt: fdkaac.TtMp4Adts,
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	defer func() {
		decoder.Close()
	}()

	inBuf := []byte{
        // AAC frame
    }
	outBuf := make([]byte, 4096)

	n, err := decoder.DecodeFrame(inBuf, outBuf)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(outBuf[0:n])
}

Enode PCM to AAC

package main

import (
	"fmt"

	fdkaac "github.com/qrtc/fdk-aac-go"
)

func main() {
	encoder, err := fdkaac.CreateAccEncoder(&fdkaac.AacEncoderConfig{
		TransMux:    TtMp4Adts,
		AOT:         AotAacLc,
		SampleRate:  44100,
		MaxChannels: 2,
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	defer func() {
		encoder.Close()
	}()

	inBuf := []byte{
		// PCM bytes
	}
	outBuf := make([]byte, 4096)

	n, err := encoder.Encode(inBuf, outBuf)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(outBuf[0:n])
}

Dependencies

  • fdk-aac

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DecNotEnoughBits = decErrors[C.AAC_DEC_NOT_ENOUGH_BITS]
View Source
var EncEOF = encErrors[C.AACENC_ENCODE_EOF]

Encoder End Of File.

Functions

func AotCanDoPs

func AotCanDoPs(aot AudioObjectType) bool

AotCanDoPs check a audio object type is support parameter stereo.

func IsDecodeError

func IsDecodeError(err error) bool

IsDecodeError identify decode errors. Output buffer is valid but concealed.

func IsInitError

func IsInitError(err error) bool

IsInitError identify initialization errors. Output buffer is invalid.

func IsLowDelay

func IsLowDelay(aot AudioObjectType) bool

IsLowDelay check a audio object type is low delay

func IsOutputValid

func IsOutputValid(err error) bool

IsOutputValid identify if the audio output buffer contains valid samples after calling DecodeFrame(). Output buffer is valid but can be concealed.

func IsUSAC

func IsUSAC(aot AudioObjectType) bool

IsUSAC check a audio object type is USAC

func TtIsPacket

func TtIsPacket(tt TransportType) bool

TtIsPacket check transport type is support packet.

Types

type AacDecoder

type AacDecoder struct {

	// config
	AacDecoderConfig
	// contains filtered or unexported fields
}

func CreateAccDecoder

func CreateAccDecoder(config *AacDecoderConfig) (*AacDecoder, error)

CreateAccDecoder

func (*AacDecoder) Close

func (dec *AacDecoder) Close() error

Close

func (*AacDecoder) ConfigRaw

func (dec *AacDecoder) ConfigRaw(conf []byte) error

ConfigRaw

func (*AacDecoder) DecodeFrame

func (dec *AacDecoder) DecodeFrame(in, out []byte) (n int, err error)

DecodeFrame

func (*AacDecoder) Flush

func (dec *AacDecoder) Flush() error

Flush

func (*AacDecoder) GetStreamInfo

func (dec *AacDecoder) GetStreamInfo() (*CStreamInfo, error)

GetStreamInfo

type AacDecoderConfig

type AacDecoderConfig struct {
	// Transport type
	TransportFmt TransportType
	// Defines how the decoder processes two channel signals.
	PcmDualChannelOutputMode PcmDualChannelOutputMode
	// Output buffer channel ordering.
	PcmOutputChannelMappingMpeg bool
	// Enable signal level limiting.
	PcmLimiterMode PcmLimiterMode
	// Signal level limiting attack time in ms.
	PcmLimiterAttackTime int
	// Signal level limiting release time in ms.
	PcmLimiterReleasTime int
	// Minimum number of PCM output channels.
	PcmMinOutputChannels int
	// Maximum number of PCM output channels.
	PcmMaxOutputChannels int
	// Meta data profile.
	MetadataProfile MetaDataProfile
	// Defines the time in ms after which all the bitstream associated meta-data.
	MetadataExpiryTime int
	// Error concealment: Processing method.
	ConcealMethod ConcealMethod
	// MPEG-4 / MPEG-D Dynamic Range Control (DRC):
	// Defines how the boosting DRC factors will be applied to the decoded signal.
	DrcBoostFactor int
	// MPEG-4 DRC: Scaling factor for attenuating gain values.
	DrcAttenuationFactor int
	// MPEG-4 DRC: Defines the level below full-scale to which
	// the output audio signal will be normalized to by the DRC module.
	DrcReferenceLevel int
	// MPEG-4 DRC: Enable DVB specific heavy compression
	EnableDrcHeavyCompression bool
	// MPEG-4 DRC: Default presentation mode.
	DrcDefaultPresentationMode DrcDefaultPresentationMode
	// MPEG-4 DRC: Encoder target level for light.
	DrcEncTargetLevel int
	// MPEG-D DRC: Request a DRC effect type for selection of a DRC set.
	UnidrcSetEffect int
	// MPEG-D DRC: Enable album mode.
	EnableUnidrcAlbumMode bool
	// Quadrature Mirror Filter (QMF) Bank processing mode.
	QmfLowpowerMode QmfLowpowerMode
}

type AacEncoder

type AacEncoder struct {

	// config
	AacEncoderConfig
	// contains filtered or unexported fields
}

AAC Encoder

func CreateAccEncoder

func CreateAccEncoder(config *AacEncoderConfig) (enc *AacEncoder, err error)

Create AAC Encoder

func (*AacEncoder) Close

func (enc *AacEncoder) Close() error

Close

func (*AacEncoder) Encode

func (enc *AacEncoder) Encode(in, out []byte) (n int, err error)

Encode

func (*AacEncoder) Flush

func (enc *AacEncoder) Flush(out []byte) (n int, err error)

Flush

func (*AacEncoder) GetInfo

func (enc *AacEncoder) GetInfo() (*EncInfo, error)

type AacEncoderConfig

type AacEncoderConfig struct {
	// Number of channels to be allocated.
	MaxChannels int
	// Sample bitdepth.
	SampleBitDepth int
	// Audio object type.
	AOT AudioObjectType
	// Total encoder bitrate.
	Bitrate int
	// Bitrate mode.
	BitrateMode BitrateMode
	// Audio input data sampling rate.
	SampleRate int
	// Configure SBR independently of the chosen Audio Object Type.
	SbrMode SbrMode
	// Core encoder (AAC) audio frame length in samples.
	GranuleLength int
	// Set explicit channel mode. Channel mode must match with number of input channels.
	ChannelMode ChannelMode
	// Input audio data channel ordering scheme.
	ChannelOrder ChannelOrder
	// Controls activation of downsampled SBR.
	SbrRatio int
	// Controls the use of the afterburner feature.
	IsAfterBurner bool
	// Core encoder audio bandwidth.
	Bandwith int
	// Peak bitrate configuration parameter to adjust maximum bits per audio frame.
	PeakBitrate int
	// Transport type to be used.
	TransMux TransportType
	// Frame count period for sending in-band configuration buffers within LATM/LOAS transport layer.
	HeaderPeriod int
	// Signaling mode of the extension AOT.
	SignalingMode SignalingMode
	// Number of sub frames in a transport frame for LOAS/LATM or ADTS (default 1).
	TransportSubFrames int
	// AudioMuxVersion to be used for LATM.
	AudioMuxVersion int
	// Configure protection in transport layer.
	IsProtection bool
	// Constant ancillary data bitrate in bits/second.
	AncillaryBitrate int
	// Configure Meta Data.
	MetaDataMode MetaDataMode
}

AAC Encoder Config

type AudioChannelType

type AudioChannelType uint8

Speaker description tags. segmentation: - Bit 0-3: Horizontal postion (0: none, 1: front, 2: side, 3: back, 4: lfe) - Bit 4-7: Vertical position (0: normal, 1: top, 2: bottom)

const (
	ActNone AudioChannelType = 0x00
	// Front speaker position (at normal height)
	ActFront AudioChannelType = 0x01
	// Side speaker position (at normal height)
	ActSide AudioChannelType = 0x02
	// Back speaker position (at normal height)
	ActBack AudioChannelType = 0x03
	// Low frequency effect speaker postion (front)
	ActLfe AudioChannelType = 0x04
	// Top speaker area (for combination with speaker positions)
	ActTop AudioChannelType = 0x10
	// Top front speaker = (ACT_FRONT|ACT_TOP)
	ActFrontTop AudioChannelType = 0x11
	// Top side speaker  = (ACT_SIDE |ACT_TOP)
	ActSideTop AudioChannelType = 0x12
	// Top back speaker  = (ACT_BACK |ACT_TOP)
	ActBackTop AudioChannelType = 0x13
	// Bottom speaker area (for combination with speaker positions)
	ActBottom AudioChannelType = 0x20
	// Bottom front speaker = (ACT_FRONT|ACT_BOTTOM)
	ActFrontBottom AudioChannelType = 0x21
	// Bottom side speaker  = (ACT_SIDE |ACT_BOTTOM)
	ActSideBottom AudioChannelType = 0x22
	// Bottom back speaker  = (ACT_BACK |ACT_BOTTOM)
	ActBackBottom AudioChannelType = 0x23
)

type AudioObjectType

type AudioObjectType int

The AudioObjectType is audio object type

const (
	// None
	AotNone AudioObjectType = -1
	// Null Object
	AotNullObject AudioObjectType = 0
	// Main profile
	AotAacMain AudioObjectType = 1
	// Low Complexity object
	AotAacLc AudioObjectType = 2
	// Scalable Sampling Rate
	AotAacSsr AudioObjectType = 3
	// Long Term Prediction
	AotAacLtp AudioObjectType = 4
	// Spectral Band Replication
	AotSbr AudioObjectType = 5
	// Scalable
	AotAacScal AudioObjectType = 6
	// TwinVQ
	AotTwinVq AudioObjectType = 7
	// Code-Excited Linear Prediction
	AotCelp AudioObjectType = 8
	// Harmonic Vector Excitation Coding
	AotHvxc AudioObjectType = 9
	// Reserved
	AotRsvd10 AudioObjectType = 10
	// Reserved
	AotRsvd11 AudioObjectType = 11
	// TTSI Object
	AotTtsi AudioObjectType = 12
	// Main Synthetic object
	AotMainSynth AudioObjectType = 13
	// Wavetable Synthesis object
	AotWavTabSynth AudioObjectType = 14
	// General MIDI object
	AotGenMidi AudioObjectType = 15
	// Algorithmic Synthesis and Audio FX object
	AotAlgSynthAudFx AudioObjectType = 16
	// Error Resilient(ER) AAC Low Complexity
	AotErAacLc AudioObjectType = 17
	// Reserved
	AotRsvd18 AudioObjectType = 18
	// Error Resilient(ER) AAC LTP object
	AotErAacLtp AudioObjectType = 19
	// Error Resilient(ER) AAC Scalable object
	AotErAacScal AudioObjectType = 20
	// Error Resilient(ER) TwinVQ object
	AotErTwinVq AudioObjectType = 21
	// Error Resilient(ER) BSAC object
	AotErBsac AudioObjectType = 22
	// Error Resilient(ER) AAC LowDelay object
	AotErAacLd AudioObjectType = 23
	// Error Resilient(ER) CELP object
	AotErCelp AudioObjectType = 24
	// Error Resilient(ER) HVXC object
	AotErHvxc AudioObjectType = 25
	// Error Resilient(ER) HILN object
	AotErHiln AudioObjectType = 26
	// Error Resilient(ER) Parametric object
	AotErPara AudioObjectType = 27
	// Might become SSC
	AotRsvd28 AudioObjectType = 28
	// PS, Parametric Stereo (includes SBR)
	AotPs AudioObjectType = 29
	// MPEG Surround
	AotMpegs AudioObjectType = 30

	// Signal AOT uses more than 5 bits
	AotEscape AudioObjectType = 31

	// MPEG-Layer1 in mp4
	AotMp3OnMp4L1 AudioObjectType = 32
	// MPEG-Layer2 in mp4
	AotMp3OnMp4L2 AudioObjectType = 33
	// MPEG-Layer3 in mp4
	AotMp3OnMp4L3 AudioObjectType = 34
	// Might become DST (Direct Stream Transfer)
	AotRsvd35 AudioObjectType = 35
	// Might become ALS (Audio Lossless Coding)
	AotRsvd36 AudioObjectType = 36
	// AAC + SLS
	AotAacSls AudioObjectType = 37
	// Scalable To Lossless
	AotSls AudioObjectType = 38
	// AAC Enhanced Low Delay
	AotErAacEld AudioObjectType = 39
	// Unified Speech and Audio Coding
	AotUsac AudioObjectType = 42
	// Spatial Audio Object Coding
	AotSaoc AudioObjectType = 43
	// Low Delay MPEG Surround
	AotLdMpegs AudioObjectType = 44

	// Pseudo AOTs
	// Virtual AOT MP2 Low Complexity profile
	AotMp2AacLc AudioObjectType = 129
	// Virtual AOT MP2 Low Complexity Profile with SBR
	AotMp3Sbr AudioObjectType = 132
	// Virtual AOT for DRM (ER-AAC-SCAL without SBR)
	AotDrmAac AudioObjectType = 143
	// Virtual AOT for DRM (ER-AAC-SCAL with SBR)
	AotDrmSbr AudioObjectType = 144
	// Virtual AOT for DRM (ER-AAC-SCAL with SBR and MPEG-PS)
	AotDrmMpegPs AudioObjectType = 145
	// Virtual AOT for DRM Surround (ER-AAC-SCAL (+SBR) +MPS)
	AotDrmSurround AudioObjectType = 146
	// Virtual AOT for DRM with USAC
	AotDrmUsac AudioObjectType = 147
)

type BitrateMode

type BitrateMode int

Bitrate Mode

const (
	BitrateModeConstant BitrateMode = iota
	BitrateModeVeryLow
	BitrateModeLow
	BitrateModeMedium
	BitrateModeHigh
	BitrateModeVeryHigh
)

type CStreamInfo

type CStreamInfo struct {
	// The sample rate in Hz of the decoded PCM audio signal.
	SampleRate int
	// The frame size of the decoded PCM audio signal.
	FrameSize int
	// The number of output audio channels before the rendering module.
	NumChannels int

	// Decoder internal members.
	//Sampling rate in Hz without SBR divided by a (ELD) downscale factor if present.
	AacSampleRate int
	// MPEG-2 profile
	Profile int
	// Audio Object Type (from ASC)
	AOT AudioObjectType
	// Channel configuration
	ChannelConfig int
	// Instantaneous bit rate.
	BitRate int
	// Samples per frame for the AAC core (from ASC) divided by a (ELD) downscale factor if present.
	AacSamplesPerFrame int
	// The number of audio channels after AAC core processing (before PS or MPS processing).
	AacNumChannels int
	// Extension Audio Object Type (from ASC)
	ExtAot AudioObjectType
	// Extension sampling rate in Hz (from ASC) divided by a (ELD) downscale factor if present.
	ExtSamplingRate int
	// The number of samples the output is additionally delayed by the decoder.
	OutputDelay uint
	// Copy of internal flags. Only to be written by the decoder, and only to be read externally.
	Flags uint
	// epConfig level (from ASC)
	// only level 0 supported, -1 means no ER (e. g. AOT=2, MPEG-2 AAC, etc.)
	EpConfig int8
	// This integer will reflect the estimated amount of lost access units in case aacDecoder_DecodeFrame()
	// returns AAC_DEC_TRANSPORT_SYNC_ERROR.
	NumLostAccessUnits int64
	// This is the number of total bytes that have passed through the decoder.
	NumTotalBytes int64
	// This is the number of total bytes that were considered with errors from numTotalBytes.
	NumBadBytes int64
	// This is the number of total access units that have passed through the decoder.
	NumTotalAccessUnits int64
	// This is the number of total access units that were considered with errors from numTotalBytes.
	NumBadAccessUnits int64
	// DRC program reference level.
	DrcProgRefLev int8
	// DRC presentation mode.
	DrcPresMode int8
}

CStreamInfo gives information about the currently decoded audio data.

type ChannelMode

type ChannelMode int

Channel Mode ( 1-7 equals MPEG channel configurations, others are arbitrary).

const (
	ModeInvalid ChannelMode = -1
	ModeUnknown ChannelMode = 0
	// C
	Mode_1 ChannelMode = 1
	// L+R
	Mode_2 ChannelMode = 2
	// C, L+R
	Mode_1_2 ChannelMode = 3
	// C, L+R, Rear
	Mode_1_2_1 ChannelMode = 4
	// C, L+R, LS+RS
	Mode_1_2_2 ChannelMode = 5
	// C, L+R, LS+RS, LFE
	Mode_1_2_2_1 ChannelMode = 6
	// C, LC+RC, L+R, LS+RS, LFE
	Mode_1_2_2_2_1 ChannelMode = 7

	// C, L+R, LS+RS, Crear, LFE
	Mode_6_1 ChannelMode = 11
	// C, L+R, LS+RS, Lrear+Rrear, LFE
	Mode_7_1_Back ChannelMode = 12
	// C, L+R, LS+RS, LFE, Ltop+Rtop
	Mode_7_1_Top_Front ChannelMode = 14

	// C, L+R, LS+RS, Lrear+Rrear, LFE
	Mode_7_1_Rear_Surround ChannelMode = 33
	// C, LC+RC, L+R, LS+RS, LFE
	Mode_7_1_Front_Center ChannelMode = 34

	// 212 configuration, used in ELDv2
	Mode_212 ChannelMode = 128
)

type ChannelOrder

type ChannelOrder int

Channel Order

const (
	ChannelOrderMpeg ChannelOrder = iota
	ChannelOrderWav
)

type ConcealMethod

type ConcealMethod int

Error concealment: Processing method.

const (
	ConcealSpectralMuting ConcealMethod = iota
	ConcealNoiseSubstitution
	ConcealEnergyInterpolation
)

type DrcDefaultPresentationMode

type DrcDefaultPresentationMode int

MPEG-4 DRC: Default presentation mode.

const (
	DrcParameterHandlingDisabled DrcDefaultPresentationMode = iota
	DrcParameterHandlingEnabled
	DrcPresentationMode1Default
	DrcPresentationMode2Default
)

type EncInfo

type EncInfo struct {
	// Maximum number of encoder bitstream bytes within one frame.
	// Size depends on maximum number of supported channels in encoder instance.
	MaxOutBufBytes uint
	// Maximum number of ancillary data bytes which can be
	// inserted into bitstream within one frame.
	MaxAncBytes uint
	// Internal input buffer fill level in samples per channel.
	InBufFillLevel uint
	// Number of input channels expected in encoding process.
	InputChannels uint
	// Amount of input audio samples consumed each frame per channel,
	// depending on audio object type configuration.
	FrameLength uint
	// Codec delay in PCM samples/channel.
	NDelay uint
	// Codec delay in PCM samples/channel.
	NDelayCore uint
	// Configuration buffer in binary format as an AudioSpecificConfig or
	// StreamMuxConfig according to the selected transport type.
	ConfBuf []byte
	// Number of valid bytes in confBuf.
	ConfSize uint
}

EncInfo provides some info about the encoder configuration.

type FileFormat

type FileFormat int

The FileFormat is file format.

const (
	// Unknown format
	FfUnknown FileFormat = -1
	// No container, bit stream data conveyed "as is"
	FfRaw FileFormat = 0
	// 3GPP file format
	Ff3gpp FileFormat = 3
	// MPEG-4 File format
	FfMp4f FileFormat = 4
	// Proprietary raw packet file
	FfRawPackets FileFormat = 5
)

type MetaDataMode

type MetaDataMode int

Meta Data Mode

const (
	MetaDataModeNone MetaDataMode = iota
	MetaDataModeDynamicRangeInfoOnly
	MetaDataModeDynamicRangeInfoAndAncillaryData
	MetaDataModeNoneAncillaryDataOnly
)

type MetaDataProfile

type MetaDataProfile int

Meta data profile.

const (
	MdProfileMpegStandard MetaDataProfile = iota
	MdProfileMpegLegacy
	MdProfileMpegLegacyPrio
	MdProfileAribJapan
)

type PcmDualChannelOutputMode

type PcmDualChannelOutputMode int

PcmDualChannelOutputMode defines how the decoder processes two channel signals.

const (
	PcmDualChannelLeaveBoth PcmDualChannelOutputMode = iota
	PcmDualChannelMonoCH1
	PcmDualChannelMonoCH2
	PcmDualChannelMix
)

type PcmLimiterMode

type PcmLimiterMode int

PcmLimiterMode enable signal level limiting.

const (
	PcmLimiterAutoConfig PcmLimiterMode = iota
	PcmLimiterEnable
	PcmLimiterDisable
)

type QmfLowpowerMode

type QmfLowpowerMode int

Quadrature Mirror Filter (QMF) Bank processing mode.

const (
	QmfLowpowerInternal QmfLowpowerMode = iota
	QmfLowpowerComplex
	QmfLowpowerReal
)

type SbrMode

type SbrMode int

SBR Mode

const (
	SbrModeDefault SbrMode = iota
	SbrModeDisable
	SbrModeEnable
)

type SignalingMode

type SignalingMode int

Signaling Mode

const (
	SignalingModeImplicitCompatible SignalingMode = iota
	SignalingModeExplicitCompatible
	SignalingModeExplicitHierarchical
)

type TransportType

type TransportType int

The TransportType is transport type.

const (
	// Unknown format
	TtUnknown TransportType = -1
	// As is access units (packet based since there is obviously no sync layer)
	TtMp4Raw TransportType = 0
	// ADIF bitstream format
	TtMp4Adif TransportType = 1
	// ADTS bitstream format
	TtMp4Adts TransportType = 2
	// Audio Mux Elements with muxConfigPresent = 1
	TtMp4LatmMcp1 TransportType = 6
	// Audio Mux Elements with muxConfigPresent = 0, out of band StreamMuxConfig
	TtMp4LatmMcp0 TransportType = 7
	// Audio Sync Stream
	TtMp4Loas TransportType = 10
	// Digital Radio Mondial (DRM30/DRM+) bitstream format
	TtDrm TransportType = 12
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL