gaad

package module
Version: v0.0.0-...-68957ef Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

GoDoc Build Status Go Report Card

GAAD (Go Advanced Audio Decoder)

Package currently provides AAC parsing capabilities. This package performs a full parse of AAC-LC and HE-AACv1 bitstreams. Bitstreams with Parametric Stereo (HE-AACv2) are not yet supported, but AAC bitstream data and SBR data will be extracted. The AAC decode from the parsed data to LPCM (.wav) is not yet implemented. Please help us expand and test this library!

AACParser

This package currently supports AAC audio data contained in an ADTS header. All available data is returned in the adts struct and can be accessed as nested objects as presented in the AAC specification. All parameter names should be verbatim from the AAC specification, if you find an issue with this please file a bug or submit a pull request.

AAC Types
Type Description CODEC
AACLC AAC mp4a.40.2
HEAAC AAC + SBR mp4a.40.5
HEAACv2 AAC + SBR + PS mp4a.40.29

where:

  • SBR = Spectral band replication
  • PS = Parametric Stereo
Usage
var []byte buf
buf = <ADTS+AAC data>

// Parsing the buffer
adts, err := gaad.ParseADTS(buf)

// Looping through top level elements and accessing sub-elements
var sbr bool
if adts.Fill_elements != nil {
	for _, e := range adts.Fill_elements {
		if e.Extension_payload != nil &&
			e.Extension_payload.Extension_type == gaad.EXT_SBR_DATA {
			sbr = true
		}
	}
}
VBR vs CBR

VBR (Variable bitrate) and CBR (Constant bitrate) is derived from the bitstream_type attribute in the adif_header section. It is VBR if bitstream_type is true, and CBR otherwise.

References
ISO/IEC STANDARD 14496-3
Title         : Coding of audio-visual objects — Part 3: Audio
File          : ISO_14496-3-4th-Edition.pdf
Edition       : Fourth edition (2009-09-01)
Relevant Sections
    - Page 64   : 1.6.5 Signaling of SBR
    - Page 120  : 1.A.2 AAC Interchange formats
    - Page 489  : 4.4.2 GA bitstream payloads

Documentation

Index

Constants

View Source
const (
	ID_SCE = 0x00 // "Single Channel Element"
	ID_CPE = 0x01 // "Channel Pair Element"
	ID_CCE = 0x02 // "Coupling Channel Element"
	ID_LFE = 0x03 // "LFE Channel Element"
	ID_DSE = 0x04 // "Data Stream Element"
	ID_PCE = 0x05 // "Program Config Element"
	ID_FIL = 0x06 // "Fill Element"
	ID_END = 0x07 // "End"
)

////////////////////////////////////////////////////////////////////////////// ID_SYN_ELE (Syntactic Element) //////////////////////////////////////////////////////////////////////////////

View Source
const (
	AUDIO_OBJECT_TYPE_NULL                uint8 = 0
	AUDIO_OBJECT_TYPE_AAC_MAIN                  = 1
	AUDIO_OBJECT_TYPE_AAC_LC                    = 2
	AUDIO_OBJECT_TYPE_SSR                       = 3
	AUDIO_OBJECT_TYPE_LTP                       = 4
	AUDIO_OBJECT_TYPE_SBR                       = 5
	AUDIO_OBJECT_TYPE_AAC_SCALABLE              = 6
	AUDIO_OBJECT_TYPE_TWINVQ                    = 7
	AUDIO_OBJECT_TYPE_CELP                      = 8
	AUDIO_OBJECT_TYPE_HXVC                      = 9
	AUDIO_OBJECT_TYPE_TTSI                      = 12
	AUDIO_OBJECT_TYPE_MAIN_SYNTHESIS            = 13
	AUDIO_OBJECT_TYPE_WAVETABLE_SYNTHESIS       = 14
	AUDIO_OBJECT_TYPE_GENERAL_MIDI              = 15
	AUDIO_OBJECT_TYPE_ASAE                      = 16
	AUDIO_OBJECT_TYPE_ER                        = 17
	AUDIO_OBJECT_TYPE_ER_AAC_LTP                = 19
	AUDIO_OBJECT_TYPE_ER_AAC_SCALABLE           = 20
	AUDIO_OBJECT_TYPE_ER_TWINVQ                 = 21
	AUDIO_OBJECT_TYPE_ER_BSAC                   = 22
	AUDIO_OBJECT_TYPE_ER_AAC_LD                 = 23
	AUDIO_OBJECT_TYPE_ER_CELP                   = 24
	AUDIO_OBJECT_TYPE_ER_HVXC                   = 25
	AUDIO_OBJECT_TYPE_ER_HILN                   = 26
	AUDIO_OBJECT_TYPE_ER_PARAMETRIC             = 27
	AUDIO_OBJECT_TYPE_SSC                       = 28
	AUDIO_OBJECT_TYPE_PS                        = 29
	AUDIO_OBJECT_TYPE_MPEG_SURROUND             = 30
	AUDIO_OBJECT_TYPE_LAYER_1                   = 32
	AUDIO_OBJECT_TYPE_LAYER_2                   = 33
	AUDIO_OBJECT_TYPE_LAYER_3                   = 34
	AUDIO_OBJECT_TYPE_DST                       = 35
	AUDIO_OBJECT_TYPE_ALS                       = 36
	AUDIO_OBJECT_TYPE_SLS                       = 37
	AUDIO_OBJECT_TYPE_SLS_NON_CORE              = 38
	AUDIO_OBJECT_TYPE_ER_AAC_ELD                = 39
	AUDIO_OBJECT_TYPE_SMR                       = 40
	AUDIO_OBJECT_TYPE_SMR_MAIN                  = 41
	AUDIO_OBJECT_TYPE_USAC_NO_SBR               = 42
	AUDIO_OBJECT_TYPE_SAOC                      = 43
	AUDIO_OBJECT_TYPE_LD_MPEG_SURROUND          = 44
	AUDIO_OBJECT_TYPE_USAC                      = 45
)

////////////////////////////////////////////////////////////////////////////// Table 1.17 – Audio Object Types //////////////////////////////////////////////////////////////////////////////

View Source
const (
	FIXFIX = 0
	FIXVAR = 1
	VARFIX = 2
	VARVAR = 3
)

////////////////////////////////////////////////////////////////////////////// Table 4.114 – Values of the extension_type field //////////////////////////////////////////////////////////////////////////////

View Source
const (
	EXT_FILL          = 0x00 // ‘0000’ bitstream payload filler
	EXT_FILL_DATA     = 0x01 // ‘0001’ bitstream payload data as filler
	EXT_DATA_ELEMENT  = 0x02 // ’0010‘ data element
	EXT_DYNAMIC_RANGE = 0x0b // ‘1011’ dynamic range control
	EXT_SAC_DATA      = 0x0c // ‘1100’ MPEG Surround
	EXT_SBR_DATA      = 0x0d // ‘1101’ SBR enhancement
	EXT_SBR_DATA_CRC  = 0x0e // ‘1110’ SBR enhancement with CRC
)

////////////////////////////////////////////////////////////////////////////// Table 4.121 – Values of the extension_type field //////////////////////////////////////////////////////////////////////////////

View Source
const (
	ONLY_LONG_SEQUENCE   = 0
	LONG_START_SEQUENCE  = 1
	EIGHT_SHORT_SEQUENCE = 2
	LONG_STOP_SEQUENCE   = 3
)

////////////////////////////////////////////////////////////////////////////// AAC WINDOW SEQUENCE //////////////////////////////////////////////////////////////////////////////

View Source
const (
	MPEG_VERSION_4 = 0
	MPEG_VERSION_2 = 1
)

////////////////////////////////////////////////////////////////////////////// MPEG VERSION //////////////////////////////////////////////////////////////////////////////

View Source
const (
	/* The noiseless coding tool requires these constants (see Table 4.56). */
	ZERO_HCB       = 0
	FIRST_PAIR_HCB = 5
	ESC_HCB        = 11
	QUAD_LEN       = 4
	PAIR_LEN       = 2
	NOISE_HCB      = 13
	INTENSITY_HCB2 = 14
	INTENSITY_HCB  = 15
	ESC_FLAG       = 16
)

////////////////////////////////////////////////////////////////////////////// AAC WINDOW SEQUENCE //////////////////////////////////////////////////////////////////////////////

View Source
const (
	ANC_DATA = 0x00 // ‘0000‘ Ancillary data element
)

////////////////////////////////////////////////////////////////////////////// Table 4.122 – Values of the data_element_version //////////////////////////////////////////////////////////////////////////////

View Source
const (
	EXTENSION_ID_PS = 2
)

////////////////////////////////////////////////////////////////////////////// Table 4.121 – Values of the extension_type field //////////////////////////////////////////////////////////////////////////////

View Source
const (
	MAX_LTP_LONG_SFB uint8 = 40
)

////////////////////////////////////////////////////////////////////////////// 4.6.7.2 - Long Term Prediction (LTP) definitions //////////////////////////////////////////////////////////////////////////////

Variables

View Source
var AACProfileType = [...]string{
	"0: Null",
	"1: AAC Main",
	"2: AAC LC (Low Complexity)",
	"3: AAC SSR (Scalable Sample Rate)",
	"4: AAC LTP (Long Term Prediction)",
	"5: SBR (Spectral Band Replication)",
	"6: AAC Scalable",
	"7: TwinVQ",
	"8: CELP (Code Excited Linear Prediction)",
	"9: HXVC (Harmonic Vector eXcitation Coding)",
	"10: Reserved",
	"11: Reserved",
	"12: TTSI (Text-To-Speech Interface)",
	"13: Main Synthesis",
	"14: Wavetable Synthesis",
	"15: General MIDI",
	"16: Algorithmic Synthesis and Audio Effects",
	"17: ER (Error Resilient) AAC LC",
	"18: Reserved",
	"19: ER AAC LTP",
	"20: ER AAC Scalable",
	"21: ER TwinVQ",
	"22: ER BSAC (Bit-Sliced Arithmetic Coding)",
	"23: ER AAC LD (Low Delay)",
	"24: ER CELP",
	"25: ER HVXC",
	"26: ER HILN (Harmonic and Individual Lines plus Noise)",
	"27: ER Parametric",
	"28: SSC (SinuSoidal Coding)",
	"29: PS (Parametric Stereo)",
	"30: MPEG Surround",
	"31: (Escape value)",
	"32: Layer-1",
	"33: Layer-2",
	"34: Layer-3",
	"35: DST (Direct Stream Transfer)",
	"36: ALS (Audio Lossless)",
	"37: SLS (Scalable LosslesS)",
	"38: SLS non-core",
	"39: ER AAC ELD (Enhanced Low Delay)",
	"40: SMR (Symbolic Music Representation) Simple",
	"41: SMR Main",
	"42: USAC (Unified Speech and Audio Coding) (no SBR)",
	"43: SAOC (Spatial Audio Object Coding)",
	"44: LD MPEG Surround",
	"45: USAC",
}
View Source
var Aac_PRED_SFB_MAX = [...]uint8{
	33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34, 64, 64, 64, 64,
}
View Source
var ChannelConfiguration = [...]string{
	" 0: Defined in AOT Specifc Config",
	" 1: 1 channel: front-center",
	" 2: 2 channels: front-left, front-right",
	" 3: 3 channels: front-center, front-left, front-right",
	" 4: 4 channels: front-center, front-left, front-right, back-center",
	" 5: 5 channels: front-center, front-left, front-right, back-left, back-right",
	" 6: 6 channels: front-center, front-left, front-right, back-left, back-right, LFE-channel",
	" 7: 8 channels: front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel",
	" 8: Reserved",
	" 9: Reserved",
	"10: Reserved",
	"11: Reserved",
	"12: Reserved",
	"13: Reserved",
	"14: Reserved",
	"15: Reserved",
}

////////////////////////////////////////////////////////////////////////////// Table 1.19 – Channel Configuration //////////////////////////////////////////////////////////////////////////////

View Source
var SamplingFrequency = [...]uint32{
	96000,
	88200,
	64000,
	48000,
	44100,
	32000,
	24000,
	22050,
	16000,
	12000,
	11025,
	8000,
	7350,
	0,
	0,
	0,
}

////////////////////////////////////////////////////////////////////////////// Table 1.18 – Sampling Frequency Index //////////////////////////////////////////////////////////////////////////////

View Source
var SyntacticElement = [...]string{
	"ID_SCE: Single Channel Element",
	"ID_CPE: Channel Pair Element",
	"ID_CCE: Coupling Channel Element",
	"ID_LFE: LFE Channel Element",
	"ID_DSE: Data Stream Element",
	"ID_PCE: Program Config Element",
	"ID_FIL: Fill Element",
	"ID_END: End",
}

Functions

This section is empty.

Types

type ADTS

type ADTS struct {
	Bitrate              uint32
	ChannelConfiguration uint8
	Layer                uint8
	MpegVersion          uint8
	Profile              uint8
	SamplingFrequency    uint32
	VbrMode              bool
	Frame_length         uint16

	Single_channel_elements   []*single_channel_element
	Channel_pair_elements     []*channel_pair_element
	Coupling_channel_elements []*coupling_channel_element
	Lfe_channel_elements      []*lfe_channel_element
	Data_stream_elements      []*data_stream_element
	Program_config_elements   []*program_config_element
	Fill_elements             []*fill_element
	// contains filtered or unexported fields
}

func ParseADTS

func ParseADTS(byteArray []byte) (*ADTS, error)

////////////////////////////////////////////////////////////////////////////// MAIN PARSE FUNCTION //////////////////////////////////////////////////////////////////////////////

func (*ADTS) Debug

func (adts *ADTS) Debug() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL