Commit 9bf37cc9 authored by Dave Burke's avatar Dave Burke

Fraunhofer AAC codec.

License boilerplate update to follow.

Change-Id: I2810460c11a58b6d148d84673cc031f3685e79b5
parent a37315fe
include $(call all-subdir-makefiles)
include $(call all-subdir-makefiles)
This diff is collapsed.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
aacdec_drc.cpp \
aacdec_hcr.cpp \
aacdecoder.cpp \
aacdec_pns.cpp \
aac_ram.cpp \
block.cpp \
channelinfo.cpp \
ldfiltbank.cpp \
rvlcbit.cpp \
rvlc.cpp \
aacdec_hcr_bit.cpp \
aacdec_hcrs.cpp \
aacdecoder_lib.cpp \
aacdec_tns.cpp \
aac_rom.cpp \
channel.cpp \
conceal.cpp \
pulsedata.cpp \
rvlcconceal.cpp \
stereo.cpp
LOCAL_CFLAGS := -DANDROID
LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
$(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../../libPCMutils/include \
$(LOCAL_PATH)/../../libFDK/include \
$(LOCAL_PATH)/../../libSYS/include \
$(LOCAL_PATH)/../../libMpegTPDec/include \
$(LOCAL_PATH)/../../libSBRdec/include
LOCAL_MODULE:= libAACdec
include $(BUILD_STATIC_LIBRARY)
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2002)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Josef Hoepfl
Description:
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#include "aac_ram.h"
#include "aac_rom.h"
#define WORKBUFFER1_TAG 0
#define WORKBUFFER2_TAG 1
/*! The structure AAC_DECODER_INSTANCE is the top level structure holding all decoder configurations,
handles and structs.
*/
C_ALLOC_MEM(AacDecoder, AAC_DECODER_INSTANCE, 1)
/*!
\name StaticAacData
Static memory areas, must not be overwritten in other sections of the decoder
*/
/* @{ */
/*! The structure CAacDecoderStaticChannelInfo contains the static sideinfo which is needed
for the decoding of one aac channel. <br>
Dimension: #AacDecoderChannels */
C_ALLOC_MEM2(AacDecoderStaticChannelInfo, CAacDecoderStaticChannelInfo, 1, (6))
/*! The structure CAacDecoderChannelInfo contains the dynamic sideinfo which is needed
for the decoding of one aac channel. <br>
Dimension: #AacDecoderChannels */
C_ALLOC_MEM2(AacDecoderChannelInfo, CAacDecoderChannelInfo, 1, (6))
/*! Overlap buffer */
C_ALLOC_MEM2(OverlapBuffer, FIXP_DBL, OverlapBufferSize, (6))
C_ALLOC_MEM(DrcInfo, CDrcInfo, 1)
/* @} */
/*!
\name DynamicAacData
Dynamic memory areas, might be reused in other algorithm sections,
e.g. the sbr decoder
*/
C_ALLOC_MEM_OVERLAY(WorkBufferCore2, FIXP_DBL, ((6)*1024), SECT_DATA_L2, WORKBUFFER2_TAG)
C_ALLOC_MEM_OVERLAY(WorkBufferCore1, CWorkBufferCore1, 1, SECT_DATA_L1, WORKBUFFER1_TAG)
/* @{ */
/* @} */
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2005)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Josef Hoepfl
Description:
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#ifndef AAC_RAM_H
#define AAC_RAM_H
#include "common_fix.h"
#include "aacdecoder.h"
#include "channel.h"
#include "aacdec_hcr_types.h"
#include "aacdec_hcr.h"
/* End of formal fix.h */
#define MAX_SYNCHS 10
#define SAMPL_FREQS 12
H_ALLOC_MEM(AacDecoder, AAC_DECODER_INSTANCE)
H_ALLOC_MEM(DrcInfo, CDrcInfo)
H_ALLOC_MEM(AacDecoderStaticChannelInfo, CAacDecoderStaticChannelInfo)
H_ALLOC_MEM(AacDecoderChannelInfo, CAacDecoderChannelInfo)
H_ALLOC_MEM(OverlapBuffer, FIXP_DBL)
H_ALLOC_MEM_OVERLAY(WorkBufferCore1, CWorkBufferCore1)
H_ALLOC_MEM_OVERLAY(WorkBufferCore2, FIXP_DBL)
#endif /* #ifndef AAC_RAM_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2004)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Josef Hoepfl
Description: Definition of constant tables
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#ifndef AAC_ROM_H
#define AAC_ROM_H
#include "common_fix.h"
#include "FDK_audio.h"
#include "aacdec_hcr_types.h"
#include "aacdec_hcrs.h"
#define AAC_NF_NO_RANDOM_VAL 512 /*!< Size of random number array for noise floor */
#define INV_QUANT_TABLESIZE 256
extern const FIXP_DBL InverseQuantTable [INV_QUANT_TABLESIZE + 1] ;
extern const FIXP_DBL MantissaTable [4][14] ;
extern const SCHAR ExponentTable [4][14] ;
#define NUM_LD_COEF_512 1536
#define NUM_LD_COEF_480 1440
/* Window table partition exponents. */
#define WTS0 (1)
#define WTS1 (0)
#define WTS2 (-2)
extern const FIXP_WTB LowDelaySynthesis512[1536];
extern const FIXP_WTB LowDelaySynthesis480[1440];
typedef struct {
const SHORT *sfbOffsetLong;
const SHORT *sfbOffsetShort;
UCHAR numberOfSfbLong;
UCHAR numberOfSfbShort;
} SFB_INFO;
extern const SFB_INFO sfbOffsetTables[5][16];
/* Huffman tables */
enum {
HuffmanBits = 2,
HuffmanEntries = (1 << HuffmanBits)
};
typedef struct
{
const USHORT (*CodeBook)[HuffmanEntries];
UCHAR Dimension;
UCHAR numBits;
UCHAR Offset;
} CodeBookDescription;
extern const CodeBookDescription AACcodeBookDescriptionTable[13];
extern const CodeBookDescription AACcodeBookDescriptionSCL;
extern const STATEFUNC aStateConstant2State[];
extern const SCHAR aCodebook2StartInt[];
extern const UCHAR aMinOfCbPair[];
extern const UCHAR aMaxOfCbPair[];
extern const UCHAR aMaxCwLen[];
extern const UCHAR aDimCb[];
extern const UCHAR aDimCbShift[];
extern const UCHAR aSignCb[];
extern const UCHAR aCbPriority[];
extern const UINT *aHuffTable[];
extern const SCHAR *aQuantTable[];
extern const USHORT aLargestAbsoluteValue[];
extern const UINT aHuffTreeRvlcEscape[];
extern const UINT aHuffTreeRvlCodewds[];
extern const UCHAR tns_max_bands_tbl[13][2];
extern const UCHAR tns_max_bands_tbl_480[5];
extern const UCHAR tns_max_bands_tbl_512[5];
#define FIXP_TCC FIXP_DBL
extern const FIXP_TCC FDKaacDec_tnsCoeff3[8];
extern const FIXP_TCC FDKaacDec_tnsCoeff4[16];
extern const USHORT randomSign[AAC_NF_NO_RANDOM_VAL/16];
extern const FIXP_DBL pow2_div24minus1[47];
extern const int offsetTab[2][16];
/* Channel mapping indices for time domain I/O. First dimension is channel count-1. */
extern const UCHAR channelMappingTablePassthrough[8][8];
extern const UCHAR channelMappingTableWAV[8][8];
/* Lookup tables for elements in ER bitstream */
extern const MP4_ELEMENT_ID elementsTab[8][7];
#endif /* #ifndef AAC_ROM_H */
This diff is collapsed.
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2004)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Christian Griebel
Description: Dynamic range control (DRC) decoder tool for AAC
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#ifndef AACDEC_DRC_H
#define AACDEC_DRC_H
#include "tp_data.h" /* for program config element support */
#include "aacdec_drc_types.h"
#include "channel.h"
#include "FDK_bitstream.h"
#define AACDEC_DRC_DEFAULT_REF_LEVEL ( 108 ) /* -27 dB below full scale (typical for movies) */
#define AACDEC_DRC_DFLT_EXPIRY_FRAMES ( 40 ) /* Default DRC data expiry time in AAC frames */
#define MAX_SBR_SYN_CHAN ( 64 )
#define MAX_SBR_COLS ( 32 )
/**
* \brief DRC module setting parameters
*/
typedef enum
{
DRC_CUT_SCALE = 0,
DRC_BOOST_SCALE,
TARGET_REF_LEVEL,
DRC_BS_DELAY,
DRC_DATA_EXPIRY_FRAME,
APPLY_HEAVY_COMPRESSION
} AACDEC_DRC_PARAM;
/**
* \brief DRC module interface functions
*/
void aacDecoder_drcInit (
HANDLE_AAC_DRC self );
void aacDecoder_drcInitChannelData (
CDrcChannelData *pDrcChannel );
AAC_DECODER_ERROR aacDecoder_drcSetParam (
HANDLE_AAC_DRC self,
AACDEC_DRC_PARAM param,
INT value );
int aacDecoder_drcMarkPayload (
HANDLE_AAC_DRC self,
HANDLE_FDK_BITSTREAM hBs,
AACDEC_DRC_PAYLOAD_TYPE type );
int aacDecoder_drcProlog (
HANDLE_AAC_DRC self,
HANDLE_FDK_BITSTREAM hBs,
CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
UCHAR pceInstanceTag,
UCHAR channelMapping[],
int numChannels );
void aacDecoder_drcApply (
HANDLE_AAC_DRC self,
void *pSbrDec,
CAacDecoderChannelInfo *pAacDecoderChannelInfo,
CDrcChannelData *pDrcDat,
int ch,
int aacFrameSize,
int bSbrPresent );
int aacDecoder_drcEpilog (
HANDLE_AAC_DRC self,
HANDLE_FDK_BITSTREAM hBs,
CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[],
UCHAR pceInstanceTag,
UCHAR channelMapping[],
int validChannels );
#endif /* AACDEC_DRC_H */
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2010)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Christian Griebel
Description: Dynamic range control (DRC) global data types
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#ifndef AACDEC_DRC_TYPES_H
#define AACDEC_DRC_TYPES_H
#include "common_fix.h"
#define MAX_DRC_THREADS ( 3 ) /* Heavy compression value is handled just like MPEG DRC data */
#define MAX_DRC_BANDS ( 16 ) /* 2^LEN_DRC_BAND_INCR (LEN_DRC_BAND_INCR = 4) */
/**
* \brief DRC module global data types
*/
typedef enum
{
UNKNOWN_PAYLOAD = 0,
MPEG_DRC_EXT_DATA,
DVB_DRC_ANC_DATA
} AACDEC_DRC_PAYLOAD_TYPE;
typedef struct
{
UINT expiryCount;
UINT numBands;
USHORT bandTop[MAX_DRC_BANDS];
SHORT drcInterpolationScheme;
UCHAR drcValue[MAX_DRC_BANDS];
} CDrcChannelData;
typedef struct
{
AACDEC_DRC_PAYLOAD_TYPE type;
UINT excludedChnsMask;
SCHAR progRefLevel;
SCHAR pceInstanceTag;
CDrcChannelData channelData;
} CDrcPayload;
typedef struct
{
FIXP_DBL cut;
FIXP_DBL boost;
UINT expiryFrame;
SCHAR targetRefLevel;
UCHAR bsDelayEnable;
UCHAR applyHeavyCompression;
} CDrcParams;
typedef struct
{
CDrcParams params; /* Module parameters that can be set by user (via SetParam API function) */
UCHAR enable; /* Switch that controls dynamic range processing */
UCHAR digitalNorm; /* Switch to en-/disable reference level normalization in digital domain */
USHORT numPayloads; /* The number of DRC data payload elements found within frame */
USHORT numThreads; /* The number of DRC data threads extracted from the found payload elements */
SCHAR progRefLevel; /* Program reference level for all channels */
UCHAR dvbAncDataAvailable; /* Flag that indicates whether DVB ancillary data is present or not */
UINT dvbAncDataPosition; /* Used to store the DVB ancillary data payload position in the bitstream (only one per frame) */
UINT drcPayloadPosition[MAX_DRC_THREADS]; /* Used to store the DRC payload positions in the bitstream */
} CDrcInfo;
typedef CDrcInfo *HANDLE_AAC_DRC;
#endif /* AACDEC_DRC_TYPES_H */
This diff is collapsed.
/***************************** MPEG-4 AAC Decoder ***************************
(C) Copyright Fraunhofer IIS 2000-2008
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Robert Weidner (DSP Solutions)
Description: HCR Decoder: Interface function declaration; common defines
and structures; defines for switching error-generator,
-detector, and -concealment
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
*******************************************************************************/
#ifndef _AACDEC_HCR_H_
#define _AACDEC_HCR_H_
#include "channelinfo.h"
#include "FDK_bitstream.h"
void HcrInitRom (H_HCR_INFO hHcr);
UINT HcrInit(H_HCR_INFO pHcr,
CAacDecoderChannelInfo *pAacDecoderChannelInfo,
const SamplingRateInfo *pSamplingRateInfo,
HANDLE_FDK_BITSTREAM bs);
UINT HcrDecoder (H_HCR_INFO hHcr,
CAacDecoderChannelInfo *pAacDecoderChannelInfo,
const SamplingRateInfo *pSamplingRateInfo,
HANDLE_FDK_BITSTREAM bs);
void CarryBitToBranchValue(
UCHAR carryBit,
UINT treeNode,
UINT *branchValue,
UINT *branchNode
);
void CHcr_Read (HANDLE_FDK_BITSTREAM bs,
CAacDecoderChannelInfo *pAacDecoderChannelInfo);
void HcrMuteErroneousLines(H_HCR_INFO hHcr);
void setHcrType(H_HCR_INFO hHcr, MP4_ELEMENT_ID type);
INT getHcrType(H_HCR_INFO hHcr);
#endif /* _AACDEC_HCR_H_ */
/***************************** MPEG-4 AAC Decoder ***************************
(C) Copyright Fraunhofer IIS 2000-2008
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Robert Weidner (DSP Solutions)
Description: HCR Decoder: Bitstream reading
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
*******************************************************************************/
#include "aacdec_hcr_bit.h"
/*---------------------------------------------------------------------------------------------
description: This function toggles the read direction.
-----------------------------------------------------------------------------------------------
input: current read direction
-----------------------------------------------------------------------------------------------
return: new read direction
-------------------------------------------------------------------------------------------- */
UCHAR ToggleReadDirection(UCHAR readDirection)
{
if ( readDirection == FROM_LEFT_TO_RIGHT ) {
return FROM_RIGHT_TO_LEFT;
}
else {
return FROM_LEFT_TO_RIGHT;
}
}
/*---------------------------------------------------------------------------------------------
description: This function returns a bit from the bitstream according to read direction.
It is called very often, therefore it makes sense to inline it (runtime).
-----------------------------------------------------------------------------------------------
input: - handle to FDK bitstream
- reference value marking start of bitfield
- pLeftStartOfSegment
- pRightStartOfSegment
- readDirection
-----------------------------------------------------------------------------------------------
return: - bit from bitstream
-------------------------------------------------------------------------------------------- */
UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs,
USHORT *pLeftStartOfSegment,
USHORT *pRightStartOfSegment,
UCHAR readDirection)
{
UINT bit;
INT readBitOffset;
if (readDirection == FROM_LEFT_TO_RIGHT) {
readBitOffset = *pLeftStartOfSegment-FDKgetBitCnt(bs);
if( readBitOffset ) {
FDKpushBiDirectional(bs, readBitOffset);
}
bit = FDKreadBits(bs, 1);
*pLeftStartOfSegment += 1;
}
else {
readBitOffset = *pRightStartOfSegment-FDKgetBitCnt(bs);
if( readBitOffset ) {
FDKpushBiDirectional(bs, readBitOffset);
}
/* to be replaced with a brother function of FDKreadBits() */
bit = FDKreadBits(bs, 1);
FDKpushBack(bs, 2);
*pRightStartOfSegment -= 1;
}
#if ERROR_GENERATOR_BIT_STREAM_HCR
static int a;
if ((++a % MODULO_DIVISOR_HCR) == 0) {
bit = (bit == 0) ? 1 : 0;
}
#endif
return (bit);
}
/***************************** MPEG-4 AAC Decoder ***************************
(C) Copyright Fraunhofer IIS 2000-2008
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Robert Weidner (DSP Solutions)
Description: HCR Decoder: Bitstream reading prototypes
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
*******************************************************************************/
#ifndef _AACDEC_HCR_BIT_H_
#define _AACDEC_HCR_BIT_H_
#include "aacdec_hcr.h"
UCHAR ToggleReadDirection(UCHAR readDirection);
UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs,
USHORT *pLeftStartOfSegment,
USHORT *pRightStartOfSegment,
UCHAR readDirection);
#endif /* _AACDEC_HCR_BIT_H_ */
This diff is collapsed.
This diff is collapsed.
/***************************** MPEG-4 AAC Decoder ***************************
(C) Copyright Fraunhofer IIS 2000-2008
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Robert Weidner (DSP Solutions)
Description: HCR Decoder: Defines of state-constants, masks and
state-prototypes
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
*******************************************************************************/
#ifndef _AACDEC_HCRS_H_
#define _AACDEC_HCRS_H_
#include "FDK_bitstream.h"
#include "aacdec_hcr_types.h"
/* The four different kinds of types of states are: */
/* different states are defined as constants */ /* start middle=self next stop */
#define STOP_THIS_STATE 0 /* */
#define BODY_ONLY 1 /* X X X */
#define BODY_SIGN__BODY 2 /* X X X X [stop if no sign] */
#define BODY_SIGN__SIGN 3 /* X X [stop if sign bits decoded] */
#define BODY_SIGN_ESC__BODY 4 /* X X X X [stop if no sign] */
#define BODY_SIGN_ESC__SIGN 5 /* X X X [stop if no escape sequence] */
#define BODY_SIGN_ESC__ESC_PREFIX 6 /* X X */
#define BODY_SIGN_ESC__ESC_WORD 7 /* X X X [stop if abs(second qsc) != 16] */
/* examples: */
/* BODY_ONLY means only the codeword body will be decoded; no sign bits will follow and no escapesequence will follow */
/* BODY_SIGN__BODY means that the codeword consists of two parts; body and sign part. The part '__BODY' after the two underscores shows */
/* that the bits which are currently decoded belong to the '__BODY' of the codeword and not to the sign part. */
/* BODY_SIGN_ESC__ESC_PB means that the codeword consists of three parts; body, sign and (here: two) escape sequences; */
/* P = Prefix = ones */
/* W = Escape Word */
/* A = first possible (of two) Escape sequeces */
/* B = second possible (of two) Escape sequeces */
/* The part after the two underscores shows that the current bits which are decoded belong to the '__ESC_PB' - part of the */
/* codeword. That means the body and the sign bits are decoded completely and the bits which are decoded now belong to */
/* the escape sequence [P = prefix; B=second possible escape sequence] */
#define MSB_31_MASK 0x80000000 /* masks MSB (= Bit 31) in a 32 bit word */
#define DIMENSION_OF_ESCAPE_CODEBOOK 2 /* for cb >= 11 is dimension 2 */
#define ESCAPE_CODEBOOK 11
#define MASK_ESCAPE_PREFIX_UP 0x000F0000
#define LSB_ESCAPE_PREFIX_UP 16
#define MASK_ESCAPE_PREFIX_DOWN 0x0000F000
#define LSB_ESCAPE_PREFIX_DOWN 12
#define MASK_ESCAPE_WORD 0x00000FFF
#define MASK_FLAG_A 0x00200000
#define MASK_FLAG_B 0x00100000
extern void DecodeNonPCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO hHcr);
UINT Hcr_State_BODY_ONLY (HANDLE_FDK_BITSTREAM, void*);
UINT Hcr_State_BODY_SIGN__BODY (HANDLE_FDK_BITSTREAM, void*);
UINT Hcr_State_BODY_SIGN__SIGN (HANDLE_FDK_BITSTREAM, void*);
UINT Hcr_State_BODY_SIGN_ESC__BODY (HANDLE_FDK_BITSTREAM, void*);
UINT Hcr_State_BODY_SIGN_ESC__SIGN (HANDLE_FDK_BITSTREAM, void*);
UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX (HANDLE_FDK_BITSTREAM, void*);
UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD (HANDLE_FDK_BITSTREAM, void*);
#endif /* _AACDEC_HCRS_H_ */
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2004)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Josef Hoepfl
Description: perceptual noise substitution tool
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#include "aacdec_pns.h"
#include "aac_ram.h"
#include "aac_rom.h"
#include "channelinfo.h"
#include "block.h"
#include "FDK_bitstream.h"
#include "genericStds.h"
#define NOISE_OFFSET 90 /* cf. ISO 14496-3 p. 175 */
/*!
\brief Reset InterChannel and PNS data
The function resets the InterChannel and PNS data
*/
void CPns_ResetData(
CPnsData *pPnsData,
CPnsInterChannelData *pPnsInterChannelData
)
{
/* Assign pointer always, since pPnsData is not persistent data */
pPnsData->pPnsInterChannelData = pPnsInterChannelData;
pPnsData->PnsActive = 0;
pPnsData->CurrentEnergy = 0;
FDKmemclear(pPnsData->pnsUsed,(8*16)*sizeof(UCHAR));
FDKmemclear(pPnsInterChannelData->correlated,(8*16)*sizeof(UCHAR));
}
/*!
\brief Initialize PNS data
The function initializes the PNS data
*/
void CPns_InitPns(
CPnsData *pPnsData,
CPnsInterChannelData *pPnsInterChannelData,
INT* currentSeed, INT* randomSeed)
{
/* save pointer to inter channel data */
pPnsData->pPnsInterChannelData = pPnsInterChannelData;
/* use pointer because seed has to be
same, left and right channel ! */
pPnsData->currentSeed = currentSeed;
pPnsData->randomSeed = randomSeed;
}
/*!
\brief Indicates if PNS is used
The function returns a value indicating whether PNS is used or not
acordding to the noise energy
\return PNS used
*/
int CPns_IsPnsUsed (const CPnsData *pPnsData,
const int group,
const int band)
{
unsigned pns_band = group*16+band;
return pPnsData->pnsUsed[pns_band] & (UCHAR)1;
}
/*!
\brief Set correlation
The function activates the noise correlation between the channel pair
*/
void CPns_SetCorrelation(CPnsData *pPnsData,
const int group,
const int band,
const int outofphase)
{
CPnsInterChannelData *pInterChannelData = pPnsData->pPnsInterChannelData;
unsigned pns_band = group*16+band;
pInterChannelData->correlated[pns_band] = (outofphase) ? 3 : 1;
}
/*!
\brief Indicates if correlation is used
The function indicates if the noise correlation between the channel pair
is activated
\return PNS is correlated
*/
static
int CPns_IsCorrelated(const CPnsData *pPnsData,
const int group,
const int band)
{
CPnsInterChannelData *pInterChannelData = pPnsData->pPnsInterChannelData;
unsigned pns_band = group*16+band;
return (pInterChannelData->correlated[pns_band] & 0x01) ? 1 : 0;
}
/*!
\brief Indicates if correlated out of phase mode is used.
The function indicates if the noise correlation between the channel pair
is activated in out-of-phase mode.
\return PNS is out-of-phase
*/
static
int CPns_IsOutOfPhase(const CPnsData *pPnsData,
const int group,
const int band)
{
CPnsInterChannelData *pInterChannelData = pPnsData->pPnsInterChannelData;
unsigned pns_band = group*16+band;
return (pInterChannelData->correlated[pns_band] & 0x02) ? 1 : 0;
}
/*!
\brief Read PNS information
The function reads the PNS information from the bitstream
*/
void CPns_Read (CPnsData *pPnsData,
HANDLE_FDK_BITSTREAM bs,
const CodeBookDescription *hcb,
SHORT *pScaleFactor,
UCHAR global_gain,
int band,
int group /* = 0 */)
{
int delta ;
UINT pns_band = group*16+band;
if (pPnsData->PnsActive) {
/* Next PNS band case */
delta = CBlock_DecodeHuffmanWord (bs, hcb) - 60;
} else {
/* First PNS band case */
int noiseStartValue = FDKreadBits(bs,9);
delta = noiseStartValue - 256 ;
pPnsData->PnsActive = 1;
pPnsData->CurrentEnergy = global_gain - NOISE_OFFSET;
}
pPnsData->CurrentEnergy += delta ;
pScaleFactor[pns_band] = pPnsData->CurrentEnergy;
pPnsData->pnsUsed[pns_band] = 1;
}
/**
* \brief Generate a vector of noise of given length. The noise values are
* scaled in order to yield a noise energy of 1.0
* \param spec pointer to were the noise values will be written to.
* \param size amount of noise values to be generated.
* \param pRandomState pointer to the state of the random generator being used.
* \return exponent of generated noise vector.
*/
static int GenerateRandomVector (FIXP_DBL *RESTRICT spec,
int size,
int *pRandomState)
{
int i, invNrg_e = 0, nrg_e = 0;
FIXP_DBL invNrg_m, nrg_m = FL2FXCONST_DBL(0.0f) ;
FIXP_DBL *RESTRICT ptr = spec;
int randomState = *pRandomState;
#define GEN_NOISE_NRG_SCALE 7
/* Generate noise and calculate energy. */
for (i=0; i<size; i++)
{
randomState = (1664525L * randomState) + 1013904223L; // Numerical Recipes
nrg_m = fPow2AddDiv2(nrg_m, (FIXP_DBL)randomState>>GEN_NOISE_NRG_SCALE);
*ptr++ = (FIXP_DBL)randomState;
}
nrg_e = GEN_NOISE_NRG_SCALE*2 + 1;
/* weight noise with = 1 / sqrt_nrg; */
invNrg_m = invSqrtNorm2(nrg_m<<1, &invNrg_e);
invNrg_e += -((nrg_e-1)>>1);
for (i=size; i--; )
{
spec[i] = fMult(spec[i], invNrg_m);
}
/* Store random state */
*pRandomState = randomState;
return invNrg_e;
}
static void ScaleBand (FIXP_DBL *RESTRICT spec, int size, int scaleFactor, int specScale, int noise_e, int out_of_phase)
{
int i, shift, sfExponent;
FIXP_DBL sfMatissa;
/* Get gain from scale factor value = 2^(scaleFactor * 0.25) */
sfMatissa = MantissaTable[scaleFactor & 0x03][0];
/* sfExponent = (scaleFactor >> 2) + ExponentTable[scaleFactor & 0x03][0]; */
/* Note: ExponentTable[scaleFactor & 0x03][0] is always 1. */
sfExponent = (scaleFactor >> 2) + 1;
if (out_of_phase != 0) {
sfMatissa = -sfMatissa;
}
/* +1 because of fMultDiv2 below. */
shift = sfExponent - specScale + 1 + noise_e;
/* Apply gain to noise values */
if (shift>=0) {
shift = fixMin( shift, DFRACT_BITS-1 );
for (i = size ; i-- != 0; ) {
spec [i] = fMultDiv2 (spec [i], sfMatissa) << shift;
}
} else {
shift = fixMin( -shift, DFRACT_BITS-1 );
for (i = size ; i-- != 0; ) {
spec [i] = fMultDiv2 (spec [i], sfMatissa) >> shift;
}
}
}
/*!
\brief Apply PNS
The function applies PNS (i.e. it generates noise) on the bands
flagged as noisy bands
*/
void CPns_Apply (const CPnsData *pPnsData,
const CIcsInfo *pIcsInfo,
SPECTRAL_PTR pSpectrum,
const SHORT *pSpecScale,
const SHORT *pScaleFactor,
const SamplingRateInfo *pSamplingRateInfo,
const INT granuleLength,
const int channel)
{
if (pPnsData->PnsActive) {
const short *BandOffsets = GetScaleFactorBandOffsets(pIcsInfo, pSamplingRateInfo);
int ScaleFactorBandsTransmitted = GetScaleFactorBandsTransmitted(pIcsInfo);
for (int window = 0, group = 0; group < GetWindowGroups(pIcsInfo); group++) {
for (int groupwin = 0; groupwin < GetWindowGroupLength(pIcsInfo, group); groupwin++, window++) {
FIXP_DBL *spectrum = SPEC(pSpectrum, window, granuleLength);
for (int band = 0 ; band < ScaleFactorBandsTransmitted; band++) {
if (CPns_IsPnsUsed (pPnsData, group, band)) {
UINT pns_band = group*16+band;
int bandWidth = BandOffsets [band + 1] - BandOffsets [band] ;
int noise_e;
FDK_ASSERT(bandWidth >= 0);
if (channel > 0 && CPns_IsCorrelated(pPnsData, group, band))
{
noise_e = GenerateRandomVector (spectrum + BandOffsets [band], bandWidth,
&pPnsData->randomSeed [pns_band]) ;
}
else
{
pPnsData->randomSeed [pns_band] = *pPnsData->currentSeed ;
noise_e = GenerateRandomVector (spectrum + BandOffsets [band], bandWidth,
pPnsData->currentSeed) ;
}
int outOfPhase = CPns_IsOutOfPhase (pPnsData, group, band);
ScaleBand (spectrum + BandOffsets [band], bandWidth,
pScaleFactor[pns_band],
pSpecScale[window], noise_e, outOfPhase) ;
}
}
}
}
}
}
/***************************** MPEG-4 AAC Decoder **************************
(C) Copyright Fraunhofer IIS (2004)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s): Josef Hoepfl
Description: perceptual noise substitution tool
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
#ifndef PNS_H
#define PNS_H
#include "common_fix.h"
#define NO_OFBANDS ((8*16))
typedef struct {
UCHAR correlated[NO_OFBANDS];
} CPnsInterChannelData;
typedef struct {
CPnsInterChannelData *pPnsInterChannelData;
UCHAR pnsUsed[NO_OFBANDS];
int CurrentEnergy;
UCHAR PnsActive;
INT *currentSeed;
INT *randomSeed;
} CPnsData;
void CPns_InitPns ( CPnsData *pPnsData,
CPnsInterChannelData *pPnsInterChannelData,
INT* currentSeed,
INT* randomSeed );
void CPns_ResetData ( CPnsData *pPnsData, CPnsInterChannelData *pPnsInterChannelData );
#endif /* #ifndef PNS_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment