1
0
Fork 0
forked from len0rd/rockbox

Rework of libfaad in several areas. Allow removal of malloc with a new define FAAD_STATIC_ALLOC (in common.h). For now malloc is not fully removed but used by a few arrays needed for AAC-HE SBR+PS only. Reason to keep malloc is to have this amount of memory available for AAC-LC files which might require large m4a tables. The changes make the allocation routines much smaller, better centralized and allow to move duplicated code from aac.c/raa.c to libfaad. The rework includes removal of (now and former) unused code as well.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29778 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andree Buschmann 2011-04-24 20:19:05 +00:00
parent 69580a96eb
commit a602f46d69
26 changed files with 262 additions and 688 deletions

View file

@ -32,12 +32,6 @@ CODEC_HEADER
* for each frame. */
#define FAAD_BYTE_BUFFER_SIZE (2048-12)
/* Global buffers to be used in the mdct synthesis. This way the arrays can
* be moved to IRAM for some targets */
#define GB_BUF_SIZE 1024
static real_t gb_time_buffer[2][GB_BUF_SIZE] IBSS_ATTR_FAAD_LARGE_IRAM MEM_ALIGN_ATTR;
static real_t gb_fb_intermed[2][GB_BUF_SIZE] IBSS_ATTR_FAAD_LARGE_IRAM MEM_ALIGN_ATTR;
/* this is the codec entry point */
enum codec_status codec_main(void)
{
@ -55,7 +49,6 @@ enum codec_status codec_main(void)
int file_offset;
int framelength;
int lead_trim = 0;
int needed_bufsize;
unsigned int i;
unsigned char* buffer;
NeAACDecFrameInfo frame_info;
@ -120,34 +113,6 @@ next_track:
goto done;
}
/* Set pointer to be able to use IRAM an to avoid alloc in decoder. Must
* be called after NeAACDecOpen(). */
/* A buffer of framelength or 2*frameLenght size must be allocated for
* time_out. If frameLength is too big or SBR/forceUpSampling is active,
* we do not use the IRAM buffer and keep faad's internal allocation (see
* specrec.c). */
needed_bufsize = decoder->frameLength;
#ifdef SBR_DEC
if ((decoder->sbr_present_flag == 1) || (decoder->forceUpSampling == 1))
{
needed_bufsize *= 2;
}
#endif
if (needed_bufsize <= GB_BUF_SIZE)
{
decoder->time_out[0] = &gb_time_buffer[0][0];
decoder->time_out[1] = &gb_time_buffer[1][0];
}
/* A buffer of with frameLength elements must be allocated for fb_intermed.
* If frameLength is too big, we do not use the IRAM buffer and keep faad's
* internal allocation (see specrec.c). */
needed_bufsize = decoder->frameLength;
if (needed_bufsize <= GB_BUF_SIZE)
{
decoder->fb_intermed[0] = &gb_fb_intermed[0][0];
decoder->fb_intermed[1] = &gb_fb_intermed[1][0];
}
#ifdef SBR_DEC
/* Check for need of special handling for seek/resume and elapsed time. */
if (ci->id3->needs_upsampling_correction) {

View file

@ -36,7 +36,7 @@
* Samples were observed to need up to 1500 bytes (400 kbps nero aac).
*/
#define BUFFER_SIZE 2048
uint8_t static_buffer[BUFFER_SIZE] IBSS_ATTR;
static uint8_t static_buffer[BUFFER_SIZE] IBSS_ATTR;
/* initialize buffer, call once before first getbits or showbits */
void faad_initbits(bitfile *ld, const void *_buffer, const uint32_t buffer_size)
@ -111,6 +111,7 @@ uint8_t faad_byte_align(bitfile *ld)
}
/* rewind to beginning */
/* not used
void faad_rewindbits(bitfile *ld)
{
uint32_t tmp;
@ -131,7 +132,9 @@ void faad_rewindbits(bitfile *ld)
ld->bytes_used = 0;
ld->no_more_reading = 0;
}
*/
#ifdef ERROR_RESILIENCE
uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
DEBUGDEC)
{
@ -156,6 +159,7 @@ uint8_t *faad_getbitbuffer(bitfile *ld, uint32_t bits
return buffer;
}
#endif
#ifdef DRM
/* return the original data buffer */
@ -172,6 +176,7 @@ uint32_t faad_origbitbuffer_size(bitfile *ld)
#endif
/* reversed bit reading routines, used for RVLC and HCR */
/* not used
void faad_initbits_rev(bitfile *ld, void *buffer,
uint32_t bits_in_buffer)
{
@ -200,3 +205,4 @@ void faad_initbits_rev(bitfile *ld, void *buffer,
ld->no_more_reading = 0;
ld->error = 0;
}
*/

View file

@ -73,8 +73,10 @@ static uint32_t bitmask[] = {
void faad_initbits(bitfile *ld, const void *buffer, const uint32_t buffer_size);
void faad_endbits(bitfile *ld);
/* not used
void faad_initbits_rev(bitfile *ld, void *buffer,
uint32_t bits_in_buffer);
*/
uint8_t faad_byte_align(bitfile *ld);
uint32_t faad_get_processed_bits(bitfile *ld);
void faad_rewindbits(bitfile *ld);

View file

@ -169,25 +169,6 @@ int8_t can_decode_ot(const uint8_t object_type)
return -1;
}
void *faad_malloc(size_t size)
{
#if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
return _aligned_malloc(size, 16);
#else // #ifdef 0
return malloc(size);
#endif // #ifdef 0
}
/* common free function */
void faad_free(void *b)
{
#if 0 // defined(_WIN32) && !defined(_WIN32_WCE)
_aligned_free(b);
#else
free(b);
}
#endif
static const uint8_t Parity [256] = { // parity
0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,

View file

@ -56,30 +56,30 @@ extern struct codec_api* ci;
#define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
#define ICODE_ATTR_FAAD_LARGE_IRAM
#define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
#define IBSS_ATTR_FAAD_XLARGE_IRAM
#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
/* Enough IRAM to move additional data and code to it. */
#define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
#define ICODE_ATTR_FAAD_LARGE_IRAM ICODE_ATTR
#define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
#define IBSS_ATTR_FAAD_XLARGE_IRAM
#elif defined(CPU_S5L870X)
/* Very large IRAM. Move even more data to it. */
#define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
#define ICODE_ATTR_FAAD_LARGE_IRAM ICODE_ATTR
#define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
#define IBSS_ATTR_FAAD_XLARGE_IRAM IBSS_ATTR
#define FAAD_HAVE_XLR_IN_IRAM
#else
/* Not enough IRAM available. */
#define IBSS_ATTR_FAAD_LARGE_IRAM
#define ICODE_ATTR_FAAD_LARGE_IRAM
#define ICONST_ATTR_FAAD_LARGE_IRAM
#define IBSS_ATTR_FAAD_XLARGE_IRAM
#endif
/* Used to allocate several SBR + PS arrays and variables statically. */
//#define FAAD_STATIC_ALLOC
#define INLINE __inline
#if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
#define ALIGN __declspec(align(16))
@ -442,8 +442,11 @@ uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
uint32_t get_sample_rate(const uint8_t sr_index);
int8_t can_decode_ot(const uint8_t object_type);
void *faad_malloc(size_t size);
void faad_free(void *b);
#ifndef FAAD_STATIC_ALLOC
/* Those should not be defined or used anymore */
#define faad_malloc(A) malloc(A)
#define faad_free(A) free(A)
#endif
//#define PROFILE
#ifdef PROFILE

View file

@ -48,14 +48,35 @@
#include "ssr.h"
#endif
/* Globals */
#ifdef ANALYSIS
uint16_t dbg_count;
#endif
/* static variables */
static NeAACDecStruct s_AACDec;
static real_t s_fb_intermed [MAX_CHANNELS][1*FRAME_LEN] IBSS_ATTR_FAAD_LARGE_IRAM MEM_ALIGN_ATTR;
static real_t s_time_buf_1024[MAX_CHANNELS][1*FRAME_LEN] IBSS_ATTR_FAAD_LARGE_IRAM MEM_ALIGN_ATTR;
#ifdef SBR_DEC
#ifdef FAAD_STATIC_ALLOC
static real_t s_time_buf_2048[MAX_CHANNELS][2*FRAME_LEN] MEM_ALIGN_ATTR;
#endif
#endif
#ifdef SSR_DEC
static real_t s_ssr_overlap [MAX_CHANNELS][2*FRAME_LEN] MEM_ALIGN_ATTR;
static real_t s_prev_fmd [MAX_CHANNELS][2*FRAME_LEN] MEM_ALIGN_ATTR;
#endif
#ifdef MAIN_DEC
static pred_state s_pred_stat[MAX_CHANNELS][1*FRAME_LEN] MEM_ALIGN_ATTR;
#endif
#ifdef LTP_DEC
static int16_t s_lt_pred_stat[MAX_CHANNELS][4*FRAME_LEN] MEM_ALIGN_ATTR;
#endif
/* static function declarations */
static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
uint8_t *buffer, uint32_t buffer_size,
void **sample_buffer, int32_t sample_buffer_size);
uint8_t *buffer, uint32_t buffer_size);
static void create_channel_config(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo);
@ -101,14 +122,21 @@ NeAACDecHandle NEAACDECAPI NeAACDecOpen(void)
coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
#endif
if ((hDecoder = (NeAACDecHandle)faad_malloc(sizeof(NeAACDecStruct))) == NULL)
return NULL;
hDecoder = &s_AACDec;
memset(hDecoder, 0, sizeof(NeAACDecStruct));
memset(hDecoder , 0, sizeof(NeAACDecStruct));
memset(s_fb_intermed, 0, sizeof(s_fb_intermed));
#ifdef SSR_DEC
memset(s_ssr_overlap, 0, sizeof(s_ssr_overlap));
memset(s_prev_fmd , 0, sizeof(s_prev_fmd));
#endif
#ifdef LTP_DEC
memset(s_lt_pred_stat, 0, sizeof(s_s_lt_pred_statpred_stat));
#endif
hDecoder->config.outputFormat = FAAD_FMT_16BIT;
hDecoder->config.defObjectType = MAIN;
hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
hDecoder->config.defSampleRate = 44100;
hDecoder->config.downMatrix = 0;
hDecoder->adts_header_present = 0;
hDecoder->adif_header_present = 0;
@ -117,26 +145,28 @@ NeAACDecHandle NEAACDECAPI NeAACDecOpen(void)
hDecoder->aacScalefactorDataResilienceFlag = 0;
hDecoder->aacSpectralDataResilienceFlag = 0;
#endif
hDecoder->frameLength = 1024;
hDecoder->frameLength = FRAME_LEN;
hDecoder->frame = 0;
hDecoder->sample_buffer = NULL;
for (i = 0; i < MAX_CHANNELS; i++)
{
hDecoder->window_shape_prev[i] = 0;
hDecoder->time_out[i] = NULL;
hDecoder->fb_intermed[i] = NULL;
hDecoder->fb_intermed[i] = s_fb_intermed[i];
#ifdef SSR_DEC
hDecoder->ssr_overlap[i] = NULL;
hDecoder->prev_fmd[i] = NULL;
hDecoder->ssr_overlap[i] = s_ssr_overlap[i];
hDecoder->prev_fmd[i] = s_prev_fmd[i];
for (int k = 0; k < 2048; k++)
hDecoder->prev_fmd[i][k] = REAL_CONST(-1);
#endif
#ifdef MAIN_DEC
hDecoder->pred_stat[i] = NULL;
hDecoder->pred_stat[i] = s_pred_stat[i];
reset_all_predictors(hDecoder->pred_stat[channel], FRAME_LEN);
#endif
#ifdef LTP_DEC
hDecoder->ltp_lag[i] = 0;
hDecoder->lt_pred_stat[i] = NULL;
hDecoder->lt_pred_stat[i] = s_lt_pred_stat[i];
#endif
}
@ -204,6 +234,7 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
uint32_t buffer_size,
uint32_t *samplerate, uint8_t *channels)
{
uint32_t i;
uint32_t bits = 0;
bitfile ld;
adif_header adif;
@ -298,6 +329,28 @@ int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
hDecoder->frameLength >>= 1;
#endif
for (i=0; i<MAX_CHANNELS; ++i)
{
#ifdef SBR_DEC
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0;
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
{
#ifdef FAAD_STATIC_ALLOC
hDecoder->time_out[i] = s_time_buf_2048[i];
#else
hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t));
#endif
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
}
else
#endif
{
hDecoder->time_out[i] = s_time_buf_1024[i];
memset(hDecoder->time_out[i], 0, 1*FRAME_LEN);
}
}
if (can_decode_ot(hDecoder->object_type) < 0)
return -1;
@ -310,6 +363,7 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer,
uint32_t *samplerate, uint8_t *channels)
{
int8_t rc;
uint32_t i;
mp4AudioSpecificConfig mp4ASC;
if((hDecoder == NULL)
@ -391,6 +445,28 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer,
hDecoder->frameLength >>= 1;
#endif
for (i=0; i<MAX_CHANNELS; ++i)
{
#ifdef SBR_DEC
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0;
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
{
#ifdef FAAD_STATIC_ALLOC
hDecoder->time_out[i] = s_time_buf_2048[i];
#else
hDecoder->time_out[i] = (real_t*)faad_malloc(2*FRAME_LEN*sizeof(real_t));
#endif
memset(hDecoder->time_out[i], 0, 2*FRAME_LEN);
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
}
else
#endif
{
hDecoder->time_out[i] = s_time_buf_1024[i];
memset(hDecoder->time_out[i], 0, 1*FRAME_LEN);
}
}
return 0;
}
@ -401,8 +477,6 @@ int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate
if (hDecoder == NULL)
return 1; /* error */
NeAACDecClose(*hDecoder);
*hDecoder = NeAACDecOpen();
/* Special object type defined for DRM */
@ -435,59 +509,6 @@ int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate
}
#endif
void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder)
{
uint8_t i;
if (hDecoder == NULL)
return;
#ifdef PROFILE
printf("AAC decoder total: %I64d cycles\n", hDecoder->cycles);
printf("requant: %I64d cycles\n", hDecoder->requant_cycles);
printf("spectral_data: %I64d cycles\n", hDecoder->spectral_cycles);
printf("scalefactors: %I64d cycles\n", hDecoder->scalefac_cycles);
printf("output: %I64d cycles\n", hDecoder->output_cycles);
#endif
for (i = 0; i < MAX_CHANNELS; i++)
{
if (hDecoder->time_out[i]) faad_free(hDecoder->time_out[i]);
if (hDecoder->fb_intermed[i]) faad_free(hDecoder->fb_intermed[i]);
#ifdef SSR_DEC
if (hDecoder->ssr_overlap[i]) faad_free(hDecoder->ssr_overlap[i]);
if (hDecoder->prev_fmd[i]) faad_free(hDecoder->prev_fmd[i]);
#endif
#ifdef MAIN_DEC
if (hDecoder->pred_stat[i]) faad_free(hDecoder->pred_stat[i]);
#endif
#ifdef LTP_DEC
if (hDecoder->lt_pred_stat[i]) faad_free(hDecoder->lt_pred_stat[i]);
#endif
}
#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
ssr_filter_bank_end(hDecoder->fb);
else
#endif
drc_end(hDecoder->drc);
if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer);
#ifdef SBR_DEC
for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
{
if (hDecoder->sbr[i])
sbrDecodeEnd(hDecoder->sbr[i]);
}
#endif
if (hDecoder) faad_free(hDecoder);
}
void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame)
{
if (hDecoder)
@ -708,34 +729,17 @@ void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
uint8_t *buffer, uint32_t buffer_size)
{
return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size, NULL, 0);
}
void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
uint8_t *buffer, uint32_t buffer_size,
void **sample_buffer, uint32_t sample_buffer_size)
{
if ((sample_buffer == NULL) || (sample_buffer_size == 0))
{
hInfo->error = 27;
return NULL;
}
return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size,
sample_buffer, sample_buffer_size);
return aac_frame_decode(hDecoder, hInfo, buffer, buffer_size);
}
static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
uint8_t *buffer, uint32_t buffer_size,
void **sample_buffer2, int32_t sample_buffer_size)
uint8_t *buffer, uint32_t buffer_size)
{
uint8_t channels = 0;
uint8_t output_channels = 0;
bitfile ld;
uint32_t bitsconsumed;
uint16_t frame_len;
void *sample_buffer;
#ifdef PROFILE
int64_t count = faad_get_ts();
@ -908,42 +912,11 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
}
/* allocate the buffer for the final samples */
if ((hDecoder->sample_buffer == NULL) ||
(hDecoder->alloced_channels != output_channels))
if (hDecoder->alloced_channels != output_channels)
{
static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t),
sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t),
sizeof(int16_t), sizeof(int16_t), 0, 0, 0
};
uint8_t stride = str[hDecoder->config.outputFormat-1];
#ifdef SBR_DEC
if (((hDecoder->sbr_present_flag == 1)&&(!hDecoder->downSampledSBR)) || (hDecoder->forceUpSampling == 1))
{
stride = 2 * stride;
}
#endif
/* check if we want to use internal sample_buffer */
if (sample_buffer_size == 0)
{
if (hDecoder->sample_buffer)
faad_free(hDecoder->sample_buffer);
hDecoder->sample_buffer = NULL;
hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride);
} else if (sample_buffer_size < frame_len*output_channels*stride) {
/* provided sample buffer is not big enough */
hInfo->error = 27;
return NULL;
}
hDecoder->alloced_channels = output_channels;
}
if (sample_buffer_size == 0)
{
sample_buffer = hDecoder->sample_buffer;
} else {
sample_buffer = *sample_buffer2;
}
#ifdef SBR_DEC
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
{
@ -982,11 +955,6 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
}
#endif
/* we don't need sample conversion in rockbox.
sample_buffer = output_to_PCM(hDecoder, hDecoder->time_out, sample_buffer,
output_channels, frame_len, hDecoder->config.outputFormat);
*/
hDecoder->postSeekResetFlag = 0;
hDecoder->frame++;
@ -1014,7 +982,7 @@ static void* aac_frame_decode(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
hDecoder->cycles += count;
#endif
return sample_buffer;
return hDecoder; /* return void* != NULL */
error:

View file

@ -72,8 +72,6 @@ extern "C" {
char* NEAACDECAPI NeAACDecGetErrorMessage(uint8_t errcode);
uint32_t NEAACDECAPI NeAACDecGetCapabilities(void);
NeAACDecHandle NEAACDECAPI NeAACDecOpen(void);
NeAACDecConfigurationPtr NEAACDECAPI NeAACDecGetCurrentConfiguration(NeAACDecHandle hDecoder);
@ -97,8 +95,6 @@ int8_t NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, uint8_t *pBuffer,
int8_t NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, uint32_t samplerate,
uint8_t channels);
void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder);
void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, int32_t frame);
void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
@ -106,11 +102,6 @@ void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
uint8_t *buffer,
uint32_t buffer_size);
void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
uint8_t *buffer, uint32_t buffer_size,
void **sample_buffer, uint32_t sample_buffer_size);
#ifdef _WIN32
#pragma pack(pop)
#endif

View file

@ -33,9 +33,12 @@
#include "syntax.h"
#include "drc.h"
/* static variables */
static drc_info s_drc_info;
drc_info *drc_init(real_t cut, real_t boost)
{
drc_info *drc = (drc_info*)faad_malloc(sizeof(drc_info));
drc_info *drc = &s_drc_info;
memset(drc, 0, sizeof(drc_info));
drc->ctrl1 = cut;
@ -49,11 +52,6 @@ drc_info *drc_init(real_t cut, real_t boost)
return drc;
}
void drc_end(drc_info *drc)
{
if (drc) faad_free(drc);
}
#ifdef FIXED_POINT
static real_t drc_pow2_table[] =
{

View file

@ -36,7 +36,6 @@ extern "C" {
drc_info *drc_init(real_t cut, real_t boost);
void drc_end(drc_info *drc);
void drc_decode(drc_info *drc, real_t *spec);

View file

@ -41,7 +41,7 @@
#define DECAY_CUTOFF 3
#define DECAY_SLOPE 0.05f
/* type definitaions */
/* type definitions */
typedef const int8_t (*drm_ps_huff_tab)[2];
@ -445,6 +445,8 @@ static const complex_t Phi_Fract_Qmf[] = {
{ FRAC_CONST(-0.7396311164), FRAC_CONST(0.6730124950) }
};
/* static variables */
static drm_ps_info s_drm_ps_info;
/* static function declarations */
static void drm_ps_sa_element(drm_ps_info *ps, bitfile *ld);
@ -915,18 +917,12 @@ static void drm_add_pan(drm_ps_info *ps, uint8_t rateselect,
drm_ps_info *drm_ps_init(void)
{
drm_ps_info *ps = (drm_ps_info*)faad_malloc(sizeof(drm_ps_info));
drm_ps_info *ps = &s_drm_ps_info;
memset(ps, 0, sizeof(drm_ps_info));
return ps;
}
void drm_ps_free(drm_ps_info *ps)
{
faad_free(ps);
}
/* main DRM PS decoding function */
uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, uint32_t samplerate,
qmf_t X_left[MAX_NTSRPS][64],

View file

@ -86,7 +86,6 @@ typedef struct
uint16_t drm_ps_data(drm_ps_info *ps, bitfile *ld);
drm_ps_info *drm_ps_init(void);
void drm_ps_free(drm_ps_info *ps);
uint8_t drm_ps_decode(drm_ps_info *ps, uint8_t guess, uint32_t samplerate,
qmf_t X_left[MAX_NTSRPS][64],

View file

@ -43,8 +43,14 @@
#include "sine_win.h"
/*Windowing functions borrowed from libwmai*/
/* static variables */
static real_t transf_buf[2*FRAME_LEN] IBSS_ATTR MEM_ALIGN_ATTR;
#ifdef LTP_DEC
static real_t windowed_buf[2*FRAME_LEN] MEM_ALIGN_ATTR = {0};
#endif
/*Windowing functions borrowed from libwmai*/
#ifdef CPU_ARM
static inline
void vector_fmul_add_add(real_t *dst, const real_t *src0, const real_t *src1, const real_t *src2, int len)
@ -196,8 +202,6 @@ static INLINE void mdct(fb_info *fb, real_t *in_data, real_t *out_data, uint16_t
}
#endif
real_t transf_buf[2*1024] IBSS_ATTR MEM_ALIGN_ATTR;
void ifilter_bank(uint8_t window_sequence, uint8_t window_shape,
uint8_t window_shape_prev, real_t *freq_in,
real_t *time_out, real_t *overlap,
@ -403,7 +407,6 @@ void ifilter_bank(uint8_t window_sequence, uint8_t window_shape,
#ifdef LTP_DEC
real_t windowed_buf[2*1024] MEM_ALIGN_ATTR = {0};
/* only works for LTP -> no overlapping, no short blocks */
void filter_bank_ltp(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
uint8_t window_shape_prev, real_t *in_data, real_t *out_mdct,

View file

@ -152,19 +152,26 @@ typedef struct
uint8_t resolution20[3];
uint8_t resolution34[5];
qmf_t *work;
qmf_t **buffer;
qmf_t **temp;
qmf_t work[32+12];
qmf_t buffer[5][32];
qmf_t temp[32][12];
} hyb_info;
/* static variables */
#ifdef FAAD_STATIC_ALLOC
static hyb_info s_hyb_info;
static ps_info s_ps_info;
#endif
/* static function declarations */
static void ps_data_decode(ps_info *ps);
static hyb_info *hybrid_init(void);
static void channel_filter2(hyb_info *hyb, uint8_t frame_len, const real_t *filter,
qmf_t *buffer, qmf_t **X_hybrid);
qmf_t *buffer, qmf_t X_hybrid[32][12]);
static INLINE void DCT3_4_unscaled(real_t *y, real_t *x);
static void channel_filter8(hyb_info *hyb, uint8_t frame_len, const real_t *filter,
qmf_t *buffer, qmf_t **X_hybrid);
qmf_t *buffer, qmf_t X_hybrid[32][12]);
static void hybrid_analysis(hyb_info *hyb, qmf_t X[32][64], qmf_t X_hybrid[32][32],
uint8_t use34);
static void hybrid_synthesis(hyb_info *hyb, qmf_t X[32][64], qmf_t X_hybrid[32][32],
@ -197,9 +204,11 @@ static void ps_mix_phase(ps_info *ps,
static hyb_info *hybrid_init()
{
uint8_t i;
#ifdef FAAD_STATIC_ALLOC
hyb_info *hyb = &s_hyb_info;
#else
hyb_info *hyb = (hyb_info*)faad_malloc(sizeof(hyb_info));
#endif
hyb->resolution34[0] = 12;
hyb->resolution34[1] = 8;
@ -213,52 +222,16 @@ static hyb_info *hybrid_init()
hyb->frame_len = 32;
hyb->work = (qmf_t*)faad_malloc((hyb->frame_len+12) * sizeof(qmf_t));
memset(hyb->work, 0, (hyb->frame_len+12) * sizeof(qmf_t));
hyb->buffer = (qmf_t**)faad_malloc(5 * sizeof(qmf_t*));
for (i = 0; i < 5; i++)
{
hyb->buffer[i] = (qmf_t*)faad_malloc(hyb->frame_len * sizeof(qmf_t));
memset(hyb->buffer[i], 0, hyb->frame_len * sizeof(qmf_t));
}
hyb->temp = (qmf_t**)faad_malloc(hyb->frame_len * sizeof(qmf_t*));
for (i = 0; i < hyb->frame_len; i++)
{
hyb->temp[i] = (qmf_t*)faad_malloc(12 /*max*/ * sizeof(qmf_t));
}
memset(hyb->work , 0, sizeof(hyb->work));
memset(hyb->buffer, 0, sizeof(hyb->buffer));
memset(hyb->temp , 0, sizeof(hyb->temp));
return hyb;
}
static void hybrid_free(hyb_info *hyb)
{
uint8_t i;
if (hyb->work)
faad_free(hyb->work);
for (i = 0; i < 5; i++)
{
if (hyb->buffer[i])
faad_free(hyb->buffer[i]);
}
if (hyb->buffer)
faad_free(hyb->buffer);
for (i = 0; i < hyb->frame_len; i++)
{
if (hyb->temp[i])
faad_free(hyb->temp[i]);
}
if (hyb->temp)
faad_free(hyb->temp);
}
/* real filter, size 2 */
static void channel_filter2(hyb_info *hyb, uint8_t frame_len, const real_t *filter,
qmf_t *buffer, qmf_t **X_hybrid)
qmf_t *buffer, qmf_t X_hybrid[32][12])
{
uint8_t i;
@ -292,7 +265,7 @@ static void channel_filter2(hyb_info *hyb, uint8_t frame_len, const real_t *filt
/* complex filter, size 4 */
static void channel_filter4(hyb_info *hyb, uint8_t frame_len, const real_t *filter,
qmf_t *buffer, qmf_t **X_hybrid)
qmf_t *buffer, qmf_t X_hybrid[32][12])
{
uint8_t i;
real_t input_re1[2], input_re2[2], input_im1[2], input_im2[2];
@ -367,7 +340,7 @@ static INLINE void DCT3_4_unscaled(real_t *y, real_t *x)
/* complex filter, size 8 */
static void channel_filter8(hyb_info *hyb, uint8_t frame_len, const real_t *filter,
qmf_t *buffer, qmf_t **X_hybrid)
qmf_t *buffer, qmf_t X_hybrid[32][12])
{
uint8_t i, n;
real_t input_re1[4], input_re2[4], input_im1[4], input_im2[4];
@ -460,7 +433,7 @@ static INLINE void DCT3_6_unscaled(real_t *y, real_t *x)
/* complex filter, size 12 */
static void channel_filter12(hyb_info *hyb, uint8_t frame_len, const real_t *filter,
qmf_t *buffer, qmf_t **X_hybrid)
qmf_t *buffer, qmf_t X_hybrid[32][12])
{
uint8_t i, n;
real_t input_re1[6], input_re2[6], input_im1[6], input_im2[6];
@ -1848,20 +1821,16 @@ static void ps_mix_phase(ps_info *ps,
}
}
void ps_free(ps_info *ps)
{
/* free hybrid filterbank structures */
hybrid_free(ps->hyb);
faad_free(ps);
}
ps_info *ps_init(uint8_t sr_index)
{
uint8_t i;
uint8_t short_delay_band;
#ifdef FAAD_STATIC_ALLOC
ps_info *ps = &s_ps_info;
#else
ps_info *ps = (ps_info*)faad_malloc(sizeof(ps_info));
#endif
memset(ps, 0, sizeof(ps_info));
(void)sr_index;

View file

@ -138,7 +138,6 @@ uint16_t ps_data(ps_info *ps, bitfile *ld, uint8_t *header);
/* ps_dec.c */
ps_info *ps_init(uint8_t sr_index);
void ps_free(ps_info *ps);
uint8_t ps_decode(ps_info *ps,
qmf_t X_left[MAX_NTSRPS][64],

View file

@ -1525,7 +1525,7 @@ static const real_t dct4_post_tab[] ICONST_ATTR MEM_ALIGN_ATTR = {
};
// Table adapted from codeclib to fit into IRAM
const uint32_t dct4_revtab[32] ICONST_ATTR MEM_ALIGN_ATTR = {
static const uint32_t dct4_revtab[32] ICONST_ATTR MEM_ALIGN_ATTR = {
0, 24, 12, 22, 6, 30, 11, 19, 3, 27, 15, 21, 5, 29, 9, 17,
1, 25, 13, 23, 7, 31, 10, 18, 2, 26, 14, 20, 4, 28, 8, 16};

View file

@ -41,35 +41,64 @@
#include "sbr_hfgen.h"
#include "sbr_hfadj.h"
/* globals */
/* type definitons */
typedef struct {
#if (defined(PS_DEC) || defined(DRM_PS))
/* In case of PS_DEC or DRM_PS we need larger buffer data when calling
* ps_decode() or drm_ps_decode(). */
static qmf_t X_left [MAX_NTSRPS][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR;
static qmf_t X_right[MAX_NTSRPS][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR;
/* In case of PS_DEC or DRM_PS we need larger buffer data when calling
* ps_decode() or drm_ps_decode(). */
qmf_t X_L[MAX_NTSRPS][64];
qmf_t X_R[MAX_NTSRPS][64];
#else
/* No PS functions called. Keep using MAX_NTSR as array size. */
static qmf_t X_left [MAX_NTSR][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR;
static qmf_t X_right[MAX_NTSR][64] IBSS_ATTR_FAAD_XLARGE_IRAM MEM_ALIGN_ATTR;
/* No PS functions called. Keep using MAX_NTSR as array size. */
qmf_t X_L[MAX_NTSR][64];
qmf_t X_R[MAX_NTSR][64];
#endif
} XLR_t;
/* static variables */
static XLR_t *p_XLR = NULL;
#if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM)
static XLR_t s_XLR IBSS_ATTR MEM_ALIGN_ATTR;
#endif
#if defined(FAAD_STATIC_ALLOC)
static sbr_info s_sbr[MAX_SYNTAX_ELEMENTS];
#endif
#ifdef SBR_LOW_POWER
static real_t deg[64] MEM_ALIGN_ATTR;
#endif
/* static function declarations */
static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch);
static void sbr_save_matrix(sbr_info *sbr, uint8_t ch);
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac,
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
uint32_t sample_rate, uint8_t downSampledSBR
#ifdef DRM
, uint8_t IsDRM
#endif
)
{
sbr_info *sbr = faad_malloc(sizeof(sbr_info));
(void)downSampledSBR;
/* Allocate sbr_info. */
#if defined(FAAD_STATIC_ALLOC)
sbr_info *sbr = &s_sbr[id_ele];
#else
(void)id_ele;
sbr_info *sbr =(sbr_info*)faad_malloc(sizeof(sbr_info));
#endif
memset(sbr, 0, sizeof(sbr_info));
/* Allocate XLR temporary variable. Use static allocation if either
* FAAD_STATIC_ALLOC is set or XLR fits to IRAM. */
#if defined(FAAD_STATIC_ALLOC) || defined(FAAD_HAVE_XLR_IN_IRAM)
p_XLR = &s_XLR;
#else
p_XLR =(XLR_t*)faad_malloc(sizeof(XLR_t));
#endif
memset(p_XLR, 0, sizeof(XLR_t));
/* save id of the parent element */
sbr->id_aac = id_aac;
sbr->sample_rate = sample_rate;
@ -115,80 +144,15 @@ sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac,
sbr->GQ_ringbuf_index[0] = 0;
sbr->GQ_ringbuf_index[1] = 0;
if (id_aac == ID_CPE)
{
/* stereo */
uint8_t j;
sbr->qmfa[0] = qmfa_init(32);
sbr->qmfa[1] = qmfa_init(32);
sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64);
sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
memset(sbr->qmfa, 0, 2*sizeof(qmfa_info));
memset(sbr->qmfs, 0, 2*sizeof(qmfs_info));
for (j = 0; j < 5; j++)
{
sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
sbr->G_temp_prev[1][j] = faad_malloc(64*sizeof(real_t));
sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
sbr->Q_temp_prev[1][j] = faad_malloc(64*sizeof(real_t));
}
memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
} else {
/* mono */
uint8_t j;
sbr->qmfa[0] = qmfa_init(32);
sbr->qmfs[0] = qmfs_init((downSampledSBR)?32:64);
sbr->qmfs[1] = NULL;
for (j = 0; j < 5; j++)
{
sbr->G_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
sbr->Q_temp_prev[0][j] = faad_malloc(64*sizeof(real_t));
}
memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
}
memset(sbr->Xsbr[0], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
memset(sbr->Xsbr[1], 0, (sbr->numTimeSlotsRate+sbr->tHFGen)*64 * sizeof(qmf_t));
return sbr;
}
void sbrDecodeEnd(sbr_info *sbr)
{
uint8_t j;
if (sbr)
{
qmfa_end(sbr->qmfa[0]);
qmfs_end(sbr->qmfs[0]);
if (sbr->qmfs[1] != NULL)
{
qmfa_end(sbr->qmfa[1]);
qmfs_end(sbr->qmfs[1]);
}
for (j = 0; j < 5; j++)
{
if (sbr->G_temp_prev[0][j]) faad_free(sbr->G_temp_prev[0][j]);
if (sbr->Q_temp_prev[0][j]) faad_free(sbr->Q_temp_prev[0][j]);
if (sbr->G_temp_prev[1][j]) faad_free(sbr->G_temp_prev[1][j]);
if (sbr->Q_temp_prev[1][j]) faad_free(sbr->Q_temp_prev[1][j]);
}
#ifdef PS_DEC
if (sbr->ps != NULL)
ps_free(sbr->ps);
#endif
#ifdef DRM_PS
if (sbr->drm_ps != NULL)
drm_ps_free(sbr->drm_ps);
#endif
faad_free(sbr);
}
}
static uint8_t sbr_save_prev_data(sbr_info *sbr, uint8_t ch)
{
uint8_t i;
@ -239,10 +203,6 @@ static void sbr_save_matrix(sbr_info *sbr, uint8_t ch)
}
}
#ifdef SBR_LOW_POWER
real_t deg[64] MEM_ALIGN_ATTR;
#endif
static void sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_NTSR][64],
uint8_t ch, uint8_t dont_process,
const uint8_t downSampledSBR)
@ -276,9 +236,9 @@ static void sbr_process_channel(sbr_info *sbr, real_t *channel_buf, qmf_t X[MAX_
/* subband analysis */
if (dont_process)
sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, 32);
sbr_qmf_analysis_32(sbr, &sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, 32);
else
sbr_qmf_analysis_32(sbr, sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, sbr->kx);
sbr_qmf_analysis_32(sbr, &sbr->qmfa[ch], channel_buf, sbr->Xsbr[ch], sbr->tHFGen, sbr->kx);
if (!dont_process)
{
@ -413,22 +373,22 @@ uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_cha
sbr->just_seeked = 0;
}
sbr_process_channel(sbr, left_chan, X_left, 0, dont_process, downSampledSBR);
sbr_process_channel(sbr, left_chan, p_XLR->X_L, 0, dont_process, downSampledSBR);
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, left_chan);
sbr_qmf_synthesis_32(sbr, &sbr->qmfs[0], p_XLR->X_L, left_chan);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, left_chan);
sbr_qmf_synthesis_64(sbr, &sbr->qmfs[0], p_XLR->X_L, left_chan);
}
sbr_process_channel(sbr, right_chan, X_right, 1, dont_process, downSampledSBR);
sbr_process_channel(sbr, right_chan, p_XLR->X_R, 1, dont_process, downSampledSBR);
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X_right, right_chan);
sbr_qmf_synthesis_32(sbr, &sbr->qmfs[1], p_XLR->X_R, right_chan);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X_right, right_chan);
sbr_qmf_synthesis_64(sbr, &sbr->qmfs[1], p_XLR->X_R, right_chan);
}
if (sbr->bs_header_flag)
@ -495,13 +455,13 @@ uint8_t sbrDecodeSingleFrame(sbr_info *sbr, real_t *channel,
sbr->just_seeked = 0;
}
sbr_process_channel(sbr, channel, X_left, 0, dont_process, downSampledSBR);
sbr_process_channel(sbr, channel, p_XLR->X_L, 0, dont_process, downSampledSBR);
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, channel);
sbr_qmf_synthesis_32(sbr, &sbr->qmfs[0], p_XLR->X_L, channel);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, channel);
sbr_qmf_synthesis_64(sbr, &sbr->qmfs[0], p_XLR->X_L, channel);
}
if (sbr->bs_header_flag)
@ -540,8 +500,8 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ
uint8_t dont_process = 0;
uint8_t ret = 0;
memset(X_left,0,sizeof(X_left));
memset(X_right,0,sizeof(X_right));
memset(p_XLR->X_L, 0, sizeof(*p_XLR->X_L));
memset(p_XLR->X_R, 0, sizeof(*p_XLR->X_R));
if (sbr == NULL)
return 20;
@ -566,20 +526,15 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ
sbr->just_seeked = 0;
}
if (sbr->qmfs[1] == NULL)
{
sbr->qmfs[1] = qmfs_init((downSampledSBR)?32:64);
}
sbr_process_channel(sbr, left_channel, X_left, 0, dont_process, downSampledSBR);
sbr_process_channel(sbr, left_channel, p_XLR->X_L, 0, dont_process, downSampledSBR);
/* copy some extra data for PS */
for (l = 32; l < 38; l++)
{
for (k = 0; k < 5; k++)
{
QMF_RE(X_left[l][k]) = QMF_RE(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
QMF_IM(X_left[l][k]) = QMF_IM(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
QMF_RE(p_XLR->X_L[l][k]) = QMF_RE(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
QMF_IM(p_XLR->X_L[l][k]) = QMF_IM(sbr->Xsbr[0][sbr->tHFAdj+l][k]);
}
}
@ -587,11 +542,11 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ
#ifdef DRM_PS
if (sbr->Is_DRM_SBR)
{
drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), sbr->sample_rate, X_left, X_right);
drm_ps_decode(sbr->drm_ps, (sbr->ret > 0), sbr->sample_rate, p_XLR->X_L, p_XLR->X_R);
} else {
#endif
#ifdef PS_DEC
ps_decode(sbr->ps, X_left, X_right);
ps_decode(sbr->ps, p_XLR->X_L, p_XLR->X_R);
#endif
#ifdef DRM_PS
}
@ -600,11 +555,11 @@ uint8_t sbrDecodeSingleFramePS(sbr_info *sbr, real_t *left_channel, real_t *righ
/* subband synthesis */
if (downSampledSBR)
{
sbr_qmf_synthesis_32(sbr, sbr->qmfs[0], X_left, left_channel);
sbr_qmf_synthesis_32(sbr, sbr->qmfs[1], X_right, right_channel);
sbr_qmf_synthesis_32(sbr, &sbr->qmfs[0], p_XLR->X_L, left_channel);
sbr_qmf_synthesis_32(sbr, &sbr->qmfs[1], p_XLR->X_R, right_channel);
} else {
sbr_qmf_synthesis_64(sbr, sbr->qmfs[0], X_left, left_channel);
sbr_qmf_synthesis_64(sbr, sbr->qmfs[1], X_right, right_channel);
sbr_qmf_synthesis_64(sbr, &sbr->qmfs[0], p_XLR->X_L, left_channel);
sbr_qmf_synthesis_64(sbr, &sbr->qmfs[1], p_XLR->X_R, right_channel);
}
if (sbr->bs_header_flag)

View file

@ -48,15 +48,13 @@ extern "C" {
#define MAX_L_E 5
typedef struct {
real_t *x;
real_t x[2*32*10];
int16_t x_index;
uint8_t channels;
} qmfa_info;
typedef struct {
real_t *v;
real_t v[2*64*20]; /* Size was "(downSampledSBR)?32:64". We use 64 now. */
int16_t v_index;
uint8_t channels;
} qmfs_info;
typedef struct
@ -105,8 +103,8 @@ typedef struct
uint8_t f[2][MAX_L_E+1];
uint8_t f_prev[2];
real_t *G_temp_prev[2][5];
real_t *Q_temp_prev[2][5];
real_t G_temp_prev[2][5][64];
real_t Q_temp_prev[2][5][64];
int8_t GQ_ringbuf_index[2];
int16_t E[2][64][MAX_L_E];
@ -160,10 +158,10 @@ typedef struct
uint32_t header_count;
uint8_t id_aac;
qmfa_info *qmfa[2];
qmfs_info *qmfs[2];
qmfa_info qmfa[2] MEM_ALIGN_ATTR;
qmfs_info qmfs[2] MEM_ALIGN_ATTR;
qmf_t Xsbr[2][MAX_NTSRHFG][64];
qmf_t Xsbr[2][MAX_NTSRHFG][64] MEM_ALIGN_ATTR;
#ifdef DRM
uint8_t Is_DRM_SBR;
@ -223,13 +221,12 @@ typedef struct
uint8_t bs_df_noise[2][3];
} sbr_info;
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac,
sbr_info *sbrDecodeInit(uint16_t framelength, uint8_t id_aac, uint8_t id_ele,
uint32_t sample_rate, uint8_t downSampledSBR
#ifdef DRM
, uint8_t IsDRM
#endif
);
void sbrDecodeEnd(sbr_info *sbr);
uint8_t sbrDecodeCoupleFrame(sbr_info *sbr, real_t *left_chan, real_t *right_chan,
const uint8_t just_seeked, const uint8_t downSampledSBR);

View file

@ -231,7 +231,7 @@ static const real_t Q_div_tab_right[31][13] = {
/* calculates 1/(1+Q) */
/* [0..1] */
real_t calc_Q_div(sbr_info *sbr, uint8_t ch, uint8_t m, uint8_t l)
static real_t calc_Q_div(sbr_info *sbr, uint8_t ch, uint8_t m, uint8_t l)
{
if (sbr->bs_coupling)
{
@ -350,7 +350,7 @@ static const real_t Q_div2_tab_right[31][13] = {
/* calculates Q/(1+Q) */
/* [0..1] */
real_t calc_Q_div2(sbr_info *sbr, uint8_t ch, uint8_t m, uint8_t l)
static real_t calc_Q_div2(sbr_info *sbr, uint8_t ch, uint8_t m, uint8_t l)
{
if (sbr->bs_coupling)
{

View file

@ -50,7 +50,8 @@ static void calc_chirp_factors(sbr_info *sbr, uint8_t ch);
static void patch_construction(sbr_info *sbr);
void hf_generation(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
void hf_generation(sbr_info *sbr,
qmf_t Xlow[MAX_NTSRHFG][64],
qmf_t Xhigh[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
,real_t *deg

View file

@ -32,7 +32,8 @@
extern "C" {
#endif
void hf_generation(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
void hf_generation(sbr_info *sbr,
qmf_t Xlow[MAX_NTSRHFG][64],
qmf_t Xhigh[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
,real_t *deg

View file

@ -50,30 +50,6 @@
#define FAAD_ANALYSIS_SCALE3(X) ((X)/32.0f)
#endif
qmfa_info *qmfa_init(uint8_t channels)
{
qmfa_info *qmfa = (qmfa_info*)faad_malloc(sizeof(qmfa_info));
/* x is implemented as double ringbuffer */
qmfa->x = (real_t*)faad_malloc(2 * channels * 10 * sizeof(real_t));
memset(qmfa->x, 0, 2 * channels * 10 * sizeof(real_t));
/* ringbuffer index */
qmfa->x_index = 0;
qmfa->channels = channels;
return qmfa;
}
void qmfa_end(qmfa_info *qmfa)
{
if (qmfa)
{
if (qmfa->x) faad_free(qmfa->x);
faad_free(qmfa);
}
}
void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
qmf_t X[MAX_NTSR][64], uint8_t offset, uint8_t kx)
@ -198,30 +174,6 @@ void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
}
}
qmfs_info *qmfs_init(uint8_t channels)
{
qmfs_info *qmfs = (qmfs_info*)faad_malloc(sizeof(qmfs_info));
/* v is a double ringbuffer */
qmfs->v = (real_t*)faad_malloc(2 * channels * 20 * sizeof(real_t));
memset(qmfs->v, 0, 2 * channels * 20 * sizeof(real_t));
qmfs->v_index = 0;
qmfs->channels = channels;
return qmfs;
}
void qmfs_end(qmfs_info *qmfs)
{
if (qmfs)
{
if (qmfs->v) faad_free(qmfs->v);
faad_free(qmfs);
}
}
#ifdef SBR_LOW_POWER
void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSR][64],

View file

@ -32,11 +32,6 @@
extern "C" {
#endif
qmfa_info *qmfa_init(uint8_t channels);
void qmfa_end(qmfa_info *qmfa);
qmfs_info *qmfs_init(uint8_t channels);
void qmfs_end(qmfs_info *qmfs);
void sbr_qmf_analysis_32(sbr_info *sbr, qmfa_info *qmfa, const real_t *input,
qmf_t X[MAX_NTSR][64], uint8_t offset, uint8_t kx);
void sbr_qmf_synthesis_32(sbr_info *sbr, qmfs_info *qmfs, qmf_t X[MAX_NTSR][64],

View file

@ -53,7 +53,6 @@
#include "ssr_fb.h"
#endif
/* static function declarations */
static uint8_t quant_to_spec(NeAACDecHandle hDecoder,
ic_stream *ics, int16_t *quant_data,
@ -284,6 +283,11 @@ static const uint16_t *const swb_offset_128_window[] ICONST_ATTR =
#define bit_set(A, B) ((A) & (1<<(B)))
/* static variables */
/* used by reconstruct_single_channel() and reconstruct_channel_pair() */
static real_t spec_coef1[FRAME_LEN] IBSS_ATTR MEM_ALIGN_ATTR;
static real_t spec_coef2[FRAME_LEN] IBSS_ATTR MEM_ALIGN_ATTR;
/* 4.5.2.3.4 */
/*
- determine the number of windows in a window_sequence named num_windows
@ -648,197 +652,21 @@ static uint8_t quant_to_spec(NeAACDecHandle hDecoder,
static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel,
uint8_t output_channels)
{
uint8_t mul = 1;
#ifdef MAIN_DEC
/* MAIN object type prediction */
if (hDecoder->object_type == MAIN)
{
/* allocate the state only when needed */
if (hDecoder->pred_stat[channel] == NULL)
{
hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state));
reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength);
}
}
#endif
#ifdef LTP_DEC
if (is_ltp_ot(hDecoder->object_type))
{
/* allocate the state only when needed */
if (hDecoder->lt_pred_stat[channel] == NULL)
{
hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t));
memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t));
}
}
#endif
if (hDecoder->time_out[channel] == NULL)
{
mul = 1;
#ifdef SBR_DEC
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0;
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
{
/* SBR requires 2 times as much output data */
mul = 2;
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
}
#endif
hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t));
}
#if (defined(PS_DEC) || defined(DRM_PS))
if (output_channels == 2)
{
if (hDecoder->time_out[channel+1] == NULL)
{
hDecoder->time_out[channel+1] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->time_out[channel+1], 0, mul*hDecoder->frameLength*sizeof(real_t));
}
}
#else
(void)output_channels; /*silence warning when PS disabled*/
#endif
if (hDecoder->fb_intermed[channel] == NULL)
{
hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t));
}
#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
{
if (hDecoder->ssr_overlap[channel] == NULL)
{
hDecoder->ssr_overlap[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->ssr_overlap[channel], 0, 2*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->prev_fmd[channel] == NULL)
{
uint16_t k;
hDecoder->prev_fmd[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
for (k = 0; k < 2*hDecoder->frameLength; k++)
hDecoder->prev_fmd[channel][k] = REAL_CONST(-1);
}
}
#endif
(void)output_channels;
(void)hDecoder;
(void)channel;
return 0;
}
static uint8_t allocate_channel_pair(NeAACDecHandle hDecoder,
uint8_t channel, uint8_t paired_channel)
{
uint8_t mul = 1;
#ifdef MAIN_DEC
/* MAIN object type prediction */
if (hDecoder->object_type == MAIN)
{
/* allocate the state only when needed */
if (hDecoder->pred_stat[channel] == NULL)
{
hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state));
reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength);
}
if (hDecoder->pred_stat[paired_channel] == NULL)
{
hDecoder->pred_stat[paired_channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state));
reset_all_predictors(hDecoder->pred_stat[paired_channel], hDecoder->frameLength);
}
}
#endif
#ifdef LTP_DEC
if (is_ltp_ot(hDecoder->object_type))
{
/* allocate the state only when needed */
if (hDecoder->lt_pred_stat[channel] == NULL)
{
hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t));
memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t));
}
if (hDecoder->lt_pred_stat[paired_channel] == NULL)
{
hDecoder->lt_pred_stat[paired_channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t));
memset(hDecoder->lt_pred_stat[paired_channel], 0, hDecoder->frameLength*4 * sizeof(int16_t));
}
}
#endif
if (hDecoder->time_out[channel] == NULL)
{
mul = 1;
#ifdef SBR_DEC
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0;
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
{
/* SBR requires 2 times as much output data */
mul = 2;
hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1;
}
#endif
hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->time_out[paired_channel] == NULL)
{
hDecoder->time_out[paired_channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->time_out[paired_channel], 0, mul*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->fb_intermed[channel] == NULL)
{
hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->fb_intermed[paired_channel] == NULL)
{
hDecoder->fb_intermed[paired_channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->fb_intermed[paired_channel], 0, hDecoder->frameLength*sizeof(real_t));
}
#ifdef SSR_DEC
if (hDecoder->object_type == SSR)
{
if (hDecoder->ssr_overlap[cpe->channel] == NULL)
{
hDecoder->ssr_overlap[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->ssr_overlap[cpe->channel], 0, 2*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->ssr_overlap[cpe->paired_channel] == NULL)
{
hDecoder->ssr_overlap[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
memset(hDecoder->ssr_overlap[cpe->paired_channel], 0, 2*hDecoder->frameLength*sizeof(real_t));
}
if (hDecoder->prev_fmd[cpe->channel] == NULL)
{
uint16_t k;
hDecoder->prev_fmd[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
for (k = 0; k < 2*hDecoder->frameLength; k++)
hDecoder->prev_fmd[cpe->channel][k] = REAL_CONST(-1);
}
if (hDecoder->prev_fmd[cpe->paired_channel] == NULL)
{
uint16_t k;
hDecoder->prev_fmd[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t));
for (k = 0; k < 2*hDecoder->frameLength; k++)
hDecoder->prev_fmd[cpe->paired_channel][k] = REAL_CONST(-1);
}
}
#endif
(void)paired_channel;
(void)hDecoder;
(void)channel;
return 0;
}
/* used by reconstruct_single_channel() and reconstruct_channel_pair() */
static real_t spec_coef1[1024] IBSS_ATTR MEM_ALIGN_ATTR;
static real_t spec_coef2[1024] IBSS_ATTR MEM_ALIGN_ATTR;
uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics,
element *sce, int16_t *spec_data)
{
@ -978,7 +806,8 @@ uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics,
if (hDecoder->sbr[ele] == NULL)
{
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index),
hDecoder->element_id[ele], ele,
2*get_sample_rate(hDecoder->sf_index),
hDecoder->downSampledSBR
#ifdef DRM
, 0
@ -1227,7 +1056,8 @@ uint8_t reconstruct_channel_pair(NeAACDecHandle hDecoder, ic_stream *ics1, ic_st
if (hDecoder->sbr[ele] == NULL)
{
hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index),
hDecoder->element_id[ele], ele,
2*get_sample_rate(hDecoder->sf_index),
hDecoder->downSampledSBR
#ifdef DRM
, 0

View file

@ -37,12 +37,13 @@ extern "C" {
#include "sbr_dec.h"
#endif
#define MAX_CHANNELS 64
#define MAX_SYNTAX_ELEMENTS 48
#define MAX_CHANNELS 2 /* Was 64, but we need to limit RAM usage */
#define MAX_SYNTAX_ELEMENTS 1 /* Was 48, but we need to limit RAM usage */
#define MAX_WINDOW_GROUPS 8
#define MAX_SFB 51
#define MAX_LTP_SFB 40
#define MAX_LTP_SFB_S 8
#define FRAME_LEN 1024
/* used to save the prediction state */
typedef struct {
@ -407,9 +408,6 @@ typedef struct
*/
uint8_t alloced_channels;
/* output data buffer */
void *sample_buffer;
uint8_t window_shape_prev[MAX_CHANNELS];
#ifdef LTP_DEC
uint16_t ltp_lag[MAX_CHANNELS];

View file

@ -558,7 +558,7 @@ void raw_data_block(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
/* Table 4.4.4 and */
/* Table 4.4.9 */
int16_t spec_data[1024] MEM_ALIGN_ATTR = {0};
int16_t spec_data[FRAME_LEN] MEM_ALIGN_ATTR = {0};
element sce;
static uint8_t single_lfe_channel_element(NeAACDecHandle hDecoder, bitfile *ld,
uint8_t channel, uint8_t *tag)
@ -603,8 +603,9 @@ static uint8_t single_lfe_channel_element(NeAACDecHandle hDecoder, bitfile *ld,
}
/* Table 4.4.5 */
int16_t spec_data1[1024] IBSS_ATTR MEM_ALIGN_ATTR;
int16_t spec_data2[1024] IBSS_ATTR MEM_ALIGN_ATTR;
int16_t spec_data1[FRAME_LEN] IBSS_ATTR MEM_ALIGN_ATTR;
int16_t spec_data2[FRAME_LEN] IBSS_ATTR MEM_ALIGN_ATTR;
element cpe;
static uint8_t channel_pair_element(NeAACDecHandle hDecoder, bitfile *ld,
uint8_t channels, uint8_t *tag)
@ -884,7 +885,7 @@ static uint8_t coupling_channel_element(NeAACDecHandle hDecoder, bitfile *ld)
element el_empty = {0};
ic_stream ics_empty = {0};
static int16_t sh_data[1024];
static int16_t sh_data[FRAME_LEN];
c = faad_getbits(ld, LEN_TAG
DEBUGVAR(1,900,"coupling_channel_element(): element_instance_tag"));
@ -1028,7 +1029,8 @@ static uint8_t fill_element(NeAACDecHandle hDecoder, bitfile *ld, drc_info *drc
if (!hDecoder->sbr[sbr_ele])
{
hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength,
hDecoder->element_id[sbr_ele], 2*get_sample_rate(hDecoder->sf_index),
hDecoder->element_id[sbr_ele], sbr_ele,
2*get_sample_rate(hDecoder->sf_index),
hDecoder->downSampledSBR
#ifdef DRM
, 0
@ -1170,8 +1172,8 @@ static void gain_control_data(bitfile *ld, ic_stream *ics)
#endif
#ifdef SCALABLE_DEC
int16_t spec_data1[1024] MEM_ALIGN_ATTR;
int16_t spec_data2[1024] MEM_ALIGN_ATTR;
int16_t spec_data1[FRAME_LEN] MEM_ALIGN_ATTR;
int16_t spec_data2[FRAME_LEN] MEM_ALIGN_ATTR;
/* Table 4.4.13 ASME */
void aac_scalable_main_element(NeAACDecHandle hDecoder, NeAACDecFrameInfo *hInfo,
bitfile *ld, program_config *pce, drc_info *drc)

View file

@ -28,13 +28,6 @@
CODEC_HEADER
/* Global buffers to be used in the mdct synthesis. This way the arrays can
* be moved to IRAM for some targets */
#define GB_BUF_SIZE 1024
static ALIGN real_t gb_time_buffer[2][GB_BUF_SIZE] IBSS_ATTR_FAAD_LARGE_IRAM;
static ALIGN real_t gb_fb_intermed[2][GB_BUF_SIZE] IBSS_ATTR_FAAD_LARGE_IRAM;
static void init_rm(RMContext *rmctx)
{
memcpy(rmctx, (void*)(( (intptr_t)ci->id3->id3v2buf + 3 ) &~ 3), sizeof(RMContext));
@ -49,7 +42,6 @@ enum codec_status codec_main(void)
NeAACDecHandle decoder;
size_t n;
void *ret;
int needed_bufsize;
unsigned int i;
unsigned char* buffer;
int err, consumed, pkt_offset, skipped = 0;
@ -103,34 +95,6 @@ next_track:
goto done;
}
/* Set pointer to be able to use IRAM an to avoid alloc in decoder. Must
* be called after NeAACDecOpen(). */
/* A buffer of framelength or 2*frameLenght size must be allocated for
* time_out. If frameLength is too big or SBR/forceUpSampling is active,
* we do not use the IRAM buffer and keep faad's internal allocation (see
* specrec.c). */
needed_bufsize = decoder->frameLength;
#ifdef SBR_DEC
if ((decoder->sbr_present_flag == 1) || (decoder->forceUpSampling == 1))
{
needed_bufsize *= 2;
}
#endif
if (needed_bufsize <= GB_BUF_SIZE)
{
decoder->time_out[0] = &gb_time_buffer[0][0];
decoder->time_out[1] = &gb_time_buffer[1][0];
}
/* A buffer of with frameLength elements must be allocated for fb_intermed.
* If frameLength is too big, we do not use the IRAM buffer and keep faad's
* internal allocation (see specrec.c). */
needed_bufsize = decoder->frameLength;
if (needed_bufsize <= GB_BUF_SIZE)
{
decoder->fb_intermed[0] = &gb_fb_intermed[0][0];
decoder->fb_intermed[1] = &gb_fb_intermed[1][0];
}
/* check for a mid-track resume and force a seek time accordingly */
if(resume_offset > rmctx.data_offset + DATA_HEADER_SIZE) {
resume_offset -= rmctx.data_offset + DATA_HEADER_SIZE;