shithub: aacdec

Download patch

ref: ed830d652600db23d798c63f4b8d6b658a9084c5
parent: 047e5aa00c4b30a0c320a1abe1b3ddaa34a51c70
author: menno <menno>
date: Wed Sep 24 04:05:45 EDT 2003

Reduced memory usage

--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: decoder.c,v 1.70 2003/09/23 08:12:29 menno Exp $
+** $Id: decoder.c,v 1.71 2003/09/24 08:05:44 menno Exp $
 **/
 
 #include "common.h"
@@ -34,7 +34,6 @@
 #include "decoder.h"
 #include "mp4.h"
 #include "syntax.h"
-#include "specrec.h"
 #include "tns.h"
 #include "pns.h"
 #include "is.h"
@@ -724,13 +723,6 @@
 #ifdef LTP_DEC
     real_t **lt_pred_stat;
 #endif
-#ifndef FIXED_POINT
-#if POW_TABLE_SIZE
-    real_t *pow2_table;
-#else
-    real_t *pow2_table;
-#endif
-#endif
     real_t **time_out;
 #ifdef SBR_DEC
     real_t **time_out2;
@@ -748,7 +740,6 @@
     void *sample_buffer;
     element *syntax_elements[MAX_SYNTAX_ELEMENTS];
     element **elements;
-    int16_t *spec_data[MAX_CHANNELS];
     real_t *spec_coef[MAX_CHANNELS];
 
     /* safety checks */
@@ -766,13 +757,6 @@
 #ifdef LTP_DEC
     lt_pred_stat = hDecoder->lt_pred_stat;
 #endif
-#ifndef FIXED_POINT
-#if POW_TABLE_SIZE
-    pow2_table = hDecoder->pow2_table;
-#else
-    pow2_table = NULL;
-#endif
-#endif
     window_shape_prev = hDecoder->window_shape_prev;
     time_out = hDecoder->time_out;
 #ifdef SBR_DEC
@@ -826,7 +810,7 @@
 
     /* decode the complete bitstream */
     elements = raw_data_block(hDecoder, hInfo, ld, syntax_elements,
-        spec_data, spec_coef, pce, drc);
+        spec_coef, pce, drc);
 
     ch_ele = hDecoder->fr_ch_ele;
     channels = hDecoder->fr_channels;
@@ -952,32 +936,7 @@
 
     sample_buffer = hDecoder->sample_buffer;
 
-    /* noiseless coding is done, the rest of the tools come now */
-    for (ch = 0; ch < channels; ch++)
-    {
-        ic_stream *ics;
 
-        /* find the syntax element to which this channel belongs */
-        if (syntax_elements[hDecoder->channel_element[ch]]->channel == ch)
-            ics = &(syntax_elements[hDecoder->channel_element[ch]]->ics1);
-        else if (syntax_elements[hDecoder->channel_element[ch]]->paired_channel == ch)
-            ics = &(syntax_elements[hDecoder->channel_element[ch]]->ics2);
-
-        /* inverse quantization */
-        inverse_quantization(spec_coef[ch], spec_data[ch], frame_len);
-
-        /* apply scalefactors */
-#ifdef FIXED_POINT
-        apply_scalefactors(hDecoder, ics, spec_coef[ch], frame_len);
-#else
-        apply_scalefactors(ics, spec_coef[ch], pow2_table, frame_len);
-#endif
-
-        /* deinterleave short block grouping */
-        if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
-            quant_to_spec(ics, spec_coef[ch], frame_len);
-    }
-
     /* Because for ms, is and pns both channels spectral coefficients are needed
        we have to restart running through all channels here.
     */
@@ -1224,7 +1183,6 @@
     for (ch = 0; ch < channels; ch++)
     {
         if (spec_coef[ch]) free(spec_coef[ch]);
-        if (spec_data[ch]) free(spec_data[ch]);
     }
 
     for (i = 0; i < ch_ele; i++)
@@ -1247,7 +1205,6 @@
     for (ch = 0; ch < channels; ch++)
     {
         if (spec_coef[ch]) free(spec_coef[ch]);
-        if (spec_data[ch]) free(spec_data[ch]);
     }
 
     for (i = 0; i < ch_ele; i++)
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: decoder.h,v 1.27 2003/09/09 18:09:51 menno Exp $
+** $Id: decoder.h,v 1.28 2003/09/24 08:05:44 menno Exp $
 **/
 
 #ifndef __DECODER_H__
@@ -120,16 +120,13 @@
 
 element *decode_sce_lfe(faacDecHandle hDecoder,
                         faacDecFrameInfo *hInfo, bitfile *ld,
-                        int16_t **spec_data, real_t **spec_coef,
-                        uint8_t id_syn_ele);
+                        real_t **spec_coef, uint8_t id_syn_ele);
 element *decode_cpe(faacDecHandle hDecoder,
                     faacDecFrameInfo *hInfo, bitfile *ld,
-                    int16_t **spec_data, real_t **spec_coef,
-                    uint8_t id_syn_ele);
+                    real_t **spec_coef, uint8_t id_syn_ele);
 element **raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
                          bitfile *ld, element **elements,
-                         int16_t **spec_data, real_t **spec_coef,
-                         program_config *pce, drc_info *drc);
+                         real_t **spec_coef, program_config *pce, drc_info *drc);
 
 #ifdef _WIN32
   #pragma pack(pop)
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: specrec.c,v 1.25 2003/09/09 18:09:52 menno Exp $
+** $Id: specrec.c,v 1.26 2003/09/24 08:05:44 menno Exp $
 **/
 
 /*
@@ -555,13 +555,8 @@
 };
 #endif
 
-#ifdef FIXED_POINT
 void apply_scalefactors(faacDecHandle hDecoder, ic_stream *ics, real_t *x_invquant,
                         uint16_t frame_len)
-#else
-void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
-                        uint16_t frame_len)
-#endif
 {
     uint8_t g, sfb;
     uint16_t top;
@@ -593,7 +588,7 @@
             top = ics->sect_sfb_offset[g][sfb+1];
 
 #ifndef FIXED_POINT
-            scale = get_scale_factor_gain(ics->scale_factors[g][sfb], pow2_table);
+            scale = get_scale_factor_gain(ics->scale_factors[g][sfb], hDecoder->pow2_table);
 #else
             exp = (ics->scale_factors[g][sfb] - 100) / 4;
             frac = (ics->scale_factors[g][sfb] - 100) % 4;
--- a/libfaad/specrec.h
+++ b/libfaad/specrec.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: specrec.h,v 1.14 2003/09/09 18:09:52 menno Exp $
+** $Id: specrec.h,v 1.15 2003/09/24 08:05:45 menno Exp $
 **/
 
 #ifndef __SPECREC_H__
@@ -37,13 +37,10 @@
 uint8_t window_grouping_info(faacDecHandle hDecoder, ic_stream *ics);
 void quant_to_spec(ic_stream *ics, real_t *spec_data, uint16_t frame_len);
 void inverse_quantization(real_t *x_invquant, int16_t *x_quant, uint16_t frame_len);
-#ifdef FIXED_POINT
 void apply_scalefactors(faacDecHandle hDecoder, ic_stream *ics, real_t *x_invquant,
                         uint16_t frame_len);
-#else
+#ifndef FIXED_POINT
 void build_tables(real_t *pow2_table);
-void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
-                        uint16_t frame_len);
 #endif
 
 #ifdef __cplusplus
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: syntax.c,v 1.54 2003/09/23 08:12:29 menno Exp $
+** $Id: syntax.c,v 1.55 2003/09/24 08:05:45 menno Exp $
 **/
 
 /*
@@ -262,8 +262,7 @@
 
 element *decode_sce_lfe(faacDecHandle hDecoder,
                         faacDecFrameInfo *hInfo, bitfile *ld,
-                        int16_t **spec_data, real_t **spec_coef,
-                        uint8_t id_syn_ele)
+                        real_t **spec_coef, uint8_t id_syn_ele)
 {
     element *ele;
     uint8_t channels = hDecoder->fr_channels;
@@ -279,7 +278,6 @@
         return NULL;
     }
 
-    spec_data[channels]   = (int16_t*)malloc(hDecoder->frameLength*sizeof(int16_t));
     spec_coef[channels]   = (real_t*)malloc(hDecoder->frameLength*sizeof(real_t));
 
     ele = (element*)malloc(sizeof(element));
@@ -289,7 +287,7 @@
     ele->paired_channel = -1;
 
     hInfo->error = single_lfe_channel_element(hDecoder, ele,
-        ld, spec_data[channels]);
+        ld, spec_coef[channels]);
 
     if (hDecoder->pce_set)
         hDecoder->internal_channel[hDecoder->pce.sce_channel[ele->element_instance_tag]] = channels;
@@ -309,8 +307,7 @@
 
 element *decode_cpe(faacDecHandle hDecoder,
                     faacDecFrameInfo *hInfo, bitfile *ld,
-                    int16_t **spec_data, real_t **spec_coef,
-                    uint8_t id_syn_ele)
+                    real_t **spec_coef, uint8_t id_syn_ele)
 {
     element *ele;
     uint8_t channels = hDecoder->fr_channels;
@@ -326,8 +323,6 @@
         return NULL;
     }
 
-    spec_data[channels]   = (int16_t*)malloc(hDecoder->frameLength*sizeof(int16_t));
-    spec_data[channels+1] = (int16_t*)malloc(hDecoder->frameLength*sizeof(int16_t));
     spec_coef[channels]   = (real_t*)malloc(hDecoder->frameLength*sizeof(real_t));
     spec_coef[channels+1] = (real_t*)malloc(hDecoder->frameLength*sizeof(real_t));
 
@@ -338,7 +333,7 @@
     ele->paired_channel = channels+1;
 
     hInfo->error = channel_pair_element(hDecoder, ele,
-        ld, spec_data[channels], spec_data[channels+1]);
+        ld, spec_coef[channels], spec_coef[channels+1]);
 
     if (hDecoder->pce_set)
     {
@@ -360,8 +355,7 @@
 
 element **raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo,
                          bitfile *ld, element **elements,
-                         int16_t **spec_data, real_t **spec_coef,
-                         program_config *pce, drc_info *drc)
+                         real_t **spec_coef, program_config *pce, drc_info *drc)
 {
     uint8_t id_syn_ele;
     uint8_t ch_ele = 0;
@@ -384,7 +378,7 @@
                 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
                 hDecoder->last_syn_ele = id_syn_ele;
                 elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                    hInfo, ld, spec_data, spec_coef, id_syn_ele);
+                    hInfo, ld, spec_coef, id_syn_ele);
                 if (hInfo->error > 0)
                     return elements;
                 break;
@@ -392,7 +386,7 @@
                 if (hDecoder->first_syn_ele == 25) hDecoder->first_syn_ele = id_syn_ele;
                 hDecoder->last_syn_ele = id_syn_ele;
                 elements[ch_ele++] = decode_cpe(hDecoder,
-                    hInfo, ld, spec_data, spec_coef, id_syn_ele);
+                    hInfo, ld, spec_coef, id_syn_ele);
                 if (hInfo->error > 0)
                     return elements;
                 break;
@@ -399,7 +393,7 @@
             case ID_LFE:
                 hDecoder->has_lfe++;
                 elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                    hInfo, ld, spec_data, spec_coef, id_syn_ele);
+                    hInfo, ld, spec_coef, id_syn_ele);
                 if (hInfo->error > 0)
                     return elements;
                 break;
@@ -442,67 +436,67 @@
         {
         case 1:
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             if (hInfo->error > 0)
                 return elements;
             break;
         case 2:
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             if (hInfo->error > 0)
                 return elements;
             break;
         case 3:
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             if (hInfo->error > 0)
                 return elements;
             break;
         case 4:
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             if (hInfo->error > 0)
                 return elements;
             break;
         case 5:
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             if (hInfo->error > 0)
                 return elements;
             break;
         case 6:
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_LFE);
+                hInfo, ld, spec_coef, ID_LFE);
             if (hInfo->error > 0)
                 return elements;
             break;
         case 7:
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_SCE);
+                hInfo, ld, spec_coef, ID_SCE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_cpe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_CPE);
+                hInfo, ld, spec_coef, ID_CPE);
             elements[ch_ele++] = decode_sce_lfe(hDecoder,
-                hInfo, ld, spec_data, spec_coef, ID_LFE);
+                hInfo, ld, spec_coef, ID_LFE);
             if (hInfo->error > 0)
                 return elements;
             break;
@@ -535,9 +529,11 @@
 /* Table 4.4.9 */
 static uint8_t single_lfe_channel_element(faacDecHandle hDecoder,
                                           element *sce, bitfile *ld,
-                                          int16_t *spec_data)
+                                          real_t *spec_coef)
 {
+    uint8_t retval = 0;
     ic_stream *ics = &(sce->ics1);
+    int16_t spec_data[1024];
 #ifdef DRM
     uint8_t result;
 
@@ -576,17 +572,36 @@
     } else
 #endif
 
-    return individual_channel_stream(hDecoder, sce, ld, ics, 0, spec_data);
+    retval = individual_channel_stream(hDecoder, sce, ld, ics, 0, spec_data);
+    if (retval > 0)
+        return retval;
+
+
+    /* noiseless coding is done, spectral reconstruction is done now */
+
+    /* inverse quantization */
+    inverse_quantization(spec_coef, spec_data, hDecoder->frameLength);
+
+    /* apply scalefactors */
+    apply_scalefactors(hDecoder, ics, spec_coef, hDecoder->frameLength);
+
+    /* deinterleave short block grouping */
+    if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
+        quant_to_spec(ics, spec_coef, hDecoder->frameLength);
+
+    return 0;
 }
 
 /* Table 4.4.5 */
 static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
-                                    bitfile *ld, int16_t *spec_data1,
-                                    int16_t *spec_data2)
+                                    bitfile *ld,
+                                    real_t *spec_coef1, real_t *spec_coef2)
 {
     uint8_t result;
     ic_stream *ics1 = &(cpe->ics1);
     ic_stream *ics2 = &(cpe->ics2);
+    int16_t spec_data1[1024];
+    int16_t spec_data2[1024];
 
 #ifdef DRM
     if (hDecoder->object_type != DRM_ER_LC)
@@ -694,10 +709,25 @@
                 return 2; /* pulse coding not allowed for short blocks */
             }
         }
-        return 0;
-    } else
+    }
 #endif
 
+    /* noiseless coding is done, spectral reconstruction is done now */
+
+    /* inverse quantization */
+    inverse_quantization(spec_coef1, spec_data1, hDecoder->frameLength);
+    inverse_quantization(spec_coef2, spec_data2, hDecoder->frameLength);
+
+    /* apply scalefactors */
+    apply_scalefactors(hDecoder, ics1, spec_coef1, hDecoder->frameLength);
+    apply_scalefactors(hDecoder, ics2, spec_coef2, hDecoder->frameLength);
+
+    /* deinterleave short block grouping */
+    if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE)
+        quant_to_spec(ics1, spec_coef1, hDecoder->frameLength);
+    if (ics2->window_sequence == EIGHT_SHORT_SEQUENCE)
+        quant_to_spec(ics2, spec_coef2, hDecoder->frameLength);
+
     return 0;
 }
 
@@ -1597,13 +1627,10 @@
                 {
                     sp = spectral_data + p;
 
-                    if (sect_cb < FIRST_PAIR_HCB)
+                    if ((result = huffman_spectral_data(sect_cb, ld, sp)) > 0)
+                        return result;
+                    if (sect_cb >= FIRST_PAIR_HCB)
                     {
-                        if ((result = huffman_spectral_data(sect_cb, ld, sp)) > 0)
-                            return result;
-                    } else {
-                        if ((result = huffman_spectral_data(sect_cb, ld, sp)) > 0)
-                            return result;
                         if ((result = huffman_spectral_data(sect_cb, ld, sp+2)) > 0)
                             return result;
                     }
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: syntax.h,v 1.35 2003/09/22 20:05:32 menno Exp $
+** $Id: syntax.h,v 1.36 2003/09/24 08:05:45 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -113,10 +113,10 @@
 /* static functions */
 static uint8_t single_lfe_channel_element(faacDecHandle hDecoder,
                                           element *sce, bitfile *ld,
-                                          int16_t *spec_data);
+                                          real_t *spec_coef);
 static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe,
-                                    bitfile *ld, int16_t *spec_data1,
-                                    int16_t *spec_data2);
+                                    bitfile *ld,
+                                    real_t *spec_coef1, real_t *spec_coef2);
 static uint8_t coupling_channel_element(faacDecHandle hDecoder, bitfile *ld);
 static uint16_t data_stream_element(faacDecHandle hDecoder, bitfile *ld);
 static uint8_t program_config_element(program_config *pce, bitfile *ld);