shithub: aacdec

Download patch

ref: 7f3a73551ab8b2018fba0f0f4811778549c0e944
parent: dcebb7ecc54d95970cf9e6667c8dbe985a396751
author: menno <menno>
date: Mon Jan 19 16:49:53 EST 2004

DRM PS bitstream decoding

--- a/libfaad/Makefile.am
+++ b/libfaad/Makefile.am
@@ -1,7 +1,7 @@
 lib_LTLIBRARIES = libfaad.la
 include_HEADERS = ../include/faad.h
 
-libfaad_la_SOURCES = bits.c cfft.c decoder.c drc.c \
+libfaad_la_SOURCES = bits.c cfft.c decoder.c drc.c drm_dec.c \
 error.c filtbank.c \
 ic_predict.c is.c lt_predict.c mdct.c mp4.c ms.c output.c pns.c \
 pulse.c specrec.c syntax.c tns.c hcr.c huffman.c \
@@ -9,7 +9,7 @@
 sbr_dct.c sbr_e_nf.c sbr_fbt.c sbr_hfadj.c sbr_hfgen.c \
 sbr_huff.c sbr_qmf.c sbr_syntax.c sbr_tf_grid.c sbr_dec.c \
 analysis.h bits.h cfft.h cfft_tab.h common.h \
-decoder.h drc.h error.h fixed.h filtbank.h \
+decoder.h drc.h drm_dec.h error.h fixed.h filtbank.h \
 huffman.h ic_predict.h iq_table.h is.h kbd_win.h lt_predict.h mdct.h mp4.h \
 ms.h output.h pns.h pulse.h rvlc.h sine_win.h ssr.h ssr_fb.h ssr_ipqf.h \
 ssr_win.h specrec.h syntax.h structs.h tns.h \
--- /dev/null
+++ b/libfaad/drm_dec.c
@@ -1,0 +1,222 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR and PS decoding
+** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through [email protected].
+**
+** $Id: drm_dec.c,v 1.1 2004/01/19 21:49:53 menno Exp $
+**/
+
+#include "common.h"
+
+#ifdef DRM
+
+#include "drm_dec.h"
+#include "bits.h"
+
+/* constants */
+#define NUM_SA_BANDS 8
+#define NUM_PAN_BANDS 20
+
+
+/* type definitaions */
+typedef const int8_t (*drm_ps_huff_tab)[2];
+
+
+/* binary search huffman tables */
+static const int8_t f_huffman_sa[][2] = {
+    { /*0*/ -15, 1 },             /* index 0: 1 bits: x */
+    { 2, 3 },                     /* index 1: 2 bits: 1x */
+    { /*7*/ -8, 4 },              /* index 2: 3 bits: 10x */
+    { 5, 6 },                     /* index 3: 3 bits: 11x */
+    { /*1*/ -14, /*-1*/ -16 },    /* index 4: 4 bits: 101x */
+    { /*-2*/ -17, 7 },            /* index 5: 4 bits: 110x */
+    { 8, 9 },                     /* index 6: 4 bits: 111x */
+    { /*2*/ -13, /*-3*/ -18 },    /* index 7: 5 bits: 1101x */
+    { /*3*/ -12, 10 },            /* index 8: 5 bits: 1110x */
+    { 11, 12 },                   /* index 9: 5 bits: 1111x */
+    { /*4*/ -11, /*5*/ -10 },     /* index 10: 6 bits: 11101x */
+    { /*-4*/ -19, /*-5*/ -20 },   /* index 11: 6 bits: 11110x */
+    { /*6*/ -9, 13 },             /* index 12: 6 bits: 11111x */
+    { /*-7*/ -22, /*-6*/ -21 }    /* index 13: 7 bits: 111111x */
+};
+
+static const int8_t t_huffman_sa[][2] = {
+    { /*0*/ -15, 1 },             /* index 0: 1 bits: x */
+    { 2, 3 },                     /* index 1: 2 bits: 1x */
+    { /*-1*/ -16, /*1*/ -14 },    /* index 2: 3 bits: 10x */
+    { 4, 5 },                     /* index 3: 3 bits: 11x */
+    { /*-2*/ -17, /*2*/ -13 },    /* index 4: 4 bits: 110x */
+    { 6, 7 },                     /* index 5: 4 bits: 111x */
+    { /*-3*/ -18, /*3*/ -12 },    /* index 6: 5 bits: 1110x */
+    { 8, 9 },                     /* index 7: 5 bits: 1111x */
+    { /*-4*/ -19, /*4*/ -11 },    /* index 8: 6 bits: 11110x */
+    { 10, 11 },                   /* index 9: 6 bits: 11111x */
+    { /*-5*/ -20, /*5*/ -10 },    /* index 10: 7 bits: 111110x */
+    { /*-6*/ -21, 12 },           /* index 11: 7 bits: 111111x */
+    { /*-7*/ -22, 13 },           /* index 12: 8 bits: 1111111x */
+    { /*6*/ -9, /*7*/ -8 }        /* index 13: 9 bits: 11111111x */
+};
+
+static const int8_t f_huffman_pan[][2] = {
+    { /*0*/ -15, 1 },             /* index 0: 1 bits: x */
+    { /*-1*/ -16, 2 },            /* index 1: 2 bits: 1x */
+    { /*1*/ -14, 3 },             /* index 2: 3 bits: 11x */
+    { 4, 5 },                     /* index 3: 4 bits: 111x */
+    { /*-2*/ -17, /*2*/ -13 },    /* index 4: 5 bits: 1110x */
+    { 6, 7 },                     /* index 5: 5 bits: 1111x */
+    { /*-3*/ -18, /*3*/ -12 },    /* index 6: 6 bits: 11110x */
+    { 8, 9 },                     /* index 7: 6 bits: 11111x */
+    { /*-4*/ -19, /*4*/ -11 },    /* index 8: 7 bits: 111110x */
+    { 10, 11 },                   /* index 9: 7 bits: 111111x */
+    { /*-5*/ -20, /*5*/ -10 },    /* index 10: 8 bits: 1111110x */
+    { 12, 13 },                   /* index 11: 8 bits: 1111111x */
+    { /*-6*/ -21, /*6*/ -9 },     /* index 12: 9 bits: 11111110x */
+    { /*-7*/ -22, 14 },           /* index 13: 9 bits: 11111111x */
+    { /*7*/ -8, 15 },             /* index 14: 10 bits: 111111111x */
+    { 16, 17 },                   /* index 15: 11 bits: 1111111111x */
+    { /*-8*/ -23, /*8*/ -7 },     /* index 16: 12 bits: 11111111110x */
+    { 18, 19 },                   /* index 17: 12 bits: 11111111111x */
+    { /*-10*/ -25, 20 },          /* index 18: 13 bits: 111111111110x */
+    { 21, 22 },                   /* index 19: 13 bits: 111111111111x */
+    { /*-9*/ -24, /*9*/ -6 },     /* index 20: 14 bits: 1111111111101x */
+    { /*10*/ -5, 23 },            /* index 21: 14 bits: 1111111111110x */
+    { 24, 25 },                   /* index 22: 14 bits: 1111111111111x */
+    { /*-13*/ -28, /*-11*/ -26 }, /* index 23: 15 bits: 11111111111101x */
+    { /*11*/ -4, /*13*/ -2 },     /* index 24: 15 bits: 11111111111110x */
+    { 26, 27 },                   /* index 25: 15 bits: 11111111111111x */
+    { /*-14*/ -29, /*-12*/ -27 }, /* index 26: 16 bits: 111111111111110x */
+    { /*12*/ -3, /*14*/ -1 }      /* index 27: 16 bits: 111111111111111x */
+};
+
+static const int8_t t_huffman_pan[][2] = {
+    { /*0*/ -15, 1 },             /* index 0: 1 bits: x */
+    { /*-1*/ -16, 2 },            /* index 1: 2 bits: 1x */
+    { /*1*/ -14, 3 },             /* index 2: 3 bits: 11x */
+    { /*-2*/ -17, 4 },            /* index 3: 4 bits: 111x */
+    { /*2*/ -13, 5 },             /* index 4: 5 bits: 1111x */
+    { /*-3*/ -18, 6 },            /* index 5: 6 bits: 11111x */
+    { /*3*/ -12, 7 },             /* index 6: 7 bits: 111111x */
+    { /*-4*/ -19, 8 },            /* index 7: 8 bits: 1111111x */
+    { /*4*/ -11, 9 },             /* index 8: 9 bits: 11111111x */
+    { 10, 11 },                   /* index 9: 10 bits: 111111111x */
+    { /*-5*/ -20, /*5*/ -10 },    /* index 10: 11 bits: 1111111110x */
+    { 12, 13 },                   /* index 11: 11 bits: 1111111111x */
+    { /*-6*/ -21, /*6*/ -9 },     /* index 12: 12 bits: 11111111110x */
+    { 14, 15 },                   /* index 13: 12 bits: 11111111111x */
+    { /*-7*/ -22, /*7*/ -8 },     /* index 14: 13 bits: 111111111110x */
+    { 16, 17 },                   /* index 15: 13 bits: 111111111111x */
+    { /*-8*/ -23, /*8*/ -7 },     /* index 16: 14 bits: 1111111111110x */
+    { 18, 19 },                   /* index 17: 14 bits: 1111111111111x */
+    { /*-10*/ -25, /*10*/ -5 },   /* index 18: 15 bits: 11111111111110x */
+    { 20, 21 },                   /* index 19: 15 bits: 11111111111111x */
+    { /*-9*/ -24, /*9*/ -6 },     /* index 20: 16 bits: 111111111111110x */
+    { 22, 23 },                   /* index 21: 16 bits: 111111111111111x */
+    { 24, 25 },                   /* index 22: 17 bits: 1111111111111110x */
+    { 26, 27 },                   /* index 23: 17 bits: 1111111111111111x */
+    { /*-14*/ -29, /*-13*/ -28 }, /* index 24: 18 bits: 11111111111111100x */
+    { /*-12*/ -27, /*-11*/ -26 }, /* index 25: 18 bits: 11111111111111101x */
+    { /*11*/ -4, /*12*/ -3 },     /* index 26: 18 bits: 11111111111111110x */
+    { /*13*/ -2, /*14*/ -1 }      /* index 27: 18 bits: 11111111111111111x */
+};
+
+
+/* static function declarations */
+static void drm_ps_sa_element(drm_ps_info *ps, bitfile *ld);
+static void drm_ps_pan_element(drm_ps_info *ps, bitfile *ld);
+static int8_t huff_dec(bitfile *ld, drm_ps_huff_tab huff);
+
+
+uint16_t drm_ps_data(drm_ps_info *ps, bitfile *ld)
+{
+    uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
+
+    ps->bs_enable_sa = faad_get1bit(ld);
+    if (ps->bs_enable_sa)
+    {
+        drm_ps_sa_element(ps, ld);
+    }
+
+    ps->bs_enable_pan = faad_get1bit(ld);
+    if (ps->bs_enable_pan)
+    {
+        drm_ps_pan_element(ps, ld);
+    }
+
+    bits = (uint16_t)faad_get_processed_bits(ld) - bits;
+
+    return bits;
+}
+
+static void drm_ps_sa_element(drm_ps_info *ps, bitfile *ld)
+{
+    drm_ps_huff_tab huff;
+    uint8_t band;
+
+    ps->bs_sa_dt_flag = faad_get1bit(ld);
+    if (ps->bs_sa_dt_flag)
+    {
+        huff = t_huffman_sa;
+    } else {
+        huff = f_huffman_sa;
+    }
+
+    for (band = 0; band < NUM_SA_BANDS; band++)
+    {
+        ps->bs_sa_data[band] = huff_dec(ld, huff);
+    }
+}
+
+static void drm_ps_pan_element(drm_ps_info *ps, bitfile *ld)
+{
+    drm_ps_huff_tab huff;
+    uint8_t band;
+
+    ps->bs_pan_dt_flag = faad_get1bit(ld);
+    if (ps->bs_pan_dt_flag)
+    {
+        huff = t_huffman_pan;
+    } else {
+        huff = f_huffman_pan;
+    }
+
+    for (band = 0; band < NUM_PAN_BANDS; band++)
+    {
+        ps->bs_pan_data[band] = huff_dec(ld, huff);
+    }
+}
+
+/* binary search huffman decoding */
+static int8_t huff_dec(bitfile *ld, drm_ps_huff_tab huff)
+{
+    uint8_t bit;
+    int16_t index = 0;
+
+    while (index >= 0)
+    {
+        bit = (uint8_t)faad_get1bit(ld);
+        index = huff[index][bit];
+    }
+
+    return index + 15;
+}
+
+#endif
--- /dev/null
+++ b/libfaad/drm_dec.h
@@ -1,0 +1,58 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+**  
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+** 
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+** 
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software 
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through [email protected].
+**
+** $Id: drm_dec.h,v 1.1 2004/01/19 21:49:53 menno Exp $
+**/
+
+#ifndef __DRM_DEC_H__
+#define __DRM_DEC_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "bits.h"
+
+#define DRM_PARAMETRIC_STEREO 0
+
+typedef struct
+{
+    uint8_t bs_enable_sa;
+    uint8_t bs_enable_pan;
+
+    uint8_t bs_sa_dt_flag;
+    uint8_t bs_pan_dt_flag;
+
+    int8_t bs_sa_data[8];
+    int8_t bs_pan_data[20];
+} drm_ps_info;
+
+uint16_t drm_ps_data(drm_ps_info *ps, bitfile *ld);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
--- a/libfaad/libfaad.dsp
+++ b/libfaad/libfaad.dsp
@@ -40,8 +40,8 @@
 # PROP Output_Dir "Release"
 # PROP Intermediate_Dir "Release"
 # PROP Target_Dir ""
-MTL=midl.exe
 F90=df.exe
+MTL=midl.exe
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 # ADD CPP /nologo /G6 /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /c
 # ADD BASE RSC /l 0x413 /d "NDEBUG"
@@ -49,7 +49,7 @@
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
-LIB32=link.exe -lib
+LIB32=xilink6.exe -lib
 # ADD BASE LIB32 /nologo
 # ADD LIB32 /nologo
 
@@ -65,8 +65,8 @@
 # PROP Output_Dir "Debug"
 # PROP Intermediate_Dir "Debug"
 # PROP Target_Dir ""
-MTL=midl.exe
 F90=df.exe
+MTL=midl.exe
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 # ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 # ADD BASE RSC /l 0x413 /d "_DEBUG"
@@ -74,7 +74,7 @@
 BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
-LIB32=link.exe -lib
+LIB32=xilink6.exe -lib
 # ADD BASE LIB32 /nologo
 # ADD LIB32 /nologo
 
@@ -109,6 +109,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\drm_dec.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\error.c
 # End Source File
 # Begin Source File
@@ -314,6 +318,10 @@
 # Begin Source File
 
 SOURCE=.\drc.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\drm_dec.h
 # End Source File
 # Begin Source File
 
--- a/libfaad/sbr_dec.h
+++ b/libfaad/sbr_dec.h
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through [email protected].
 **
-** $Id: sbr_dec.h,v 1.19 2004/01/16 20:20:32 menno Exp $
+** $Id: sbr_dec.h,v 1.20 2004/01/19 21:49:53 menno Exp $
 **/
 
 #ifndef __SBR_DEC_H__
@@ -35,6 +35,9 @@
 #ifdef PS_DEC
 #include "ps_dec.h"
 #endif
+#ifdef DRM
+#include "drm_dec.h"
+#endif
 
 /* MAX_NTSRHFG: maximum of number_time_slots * rate + HFGen. 16*2+8 */
 #define MAX_NTSRHFG 40
@@ -155,6 +158,7 @@
 	int8_t lcstereo_flag;
 	uint8_t bs_dataextra;
     uint8_t Is_DRM_SBR;
+    drm_ps_info drm_ps;
 #endif
 
 	uint8_t numTimeSlotsRate;
--- a/libfaad/sbr_syntax.c
+++ b/libfaad/sbr_syntax.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through [email protected].
 **
-** $Id: sbr_syntax.c,v 1.22 2004/01/16 20:20:32 menno Exp $
+** $Id: sbr_syntax.c,v 1.23 2004/01/19 21:49:53 menno Exp $
 **/
 
 #include "common.h"
@@ -40,6 +40,9 @@
 #ifdef PS_DEC
 #include "ps_dec.h"
 #endif
+#ifdef DRM
+#include "drm_dec.h"
+#endif
 #include "analysis.h"
 
 /* static function declarations */
@@ -686,16 +689,15 @@
 static uint16_t sbr_extension(bitfile *ld, sbr_info *sbr,
                               uint8_t bs_extension_id, uint16_t num_bits_left)
 {
-#ifdef DRM
-    if (sbr->Is_DRM_SBR)
-        return 0;
-#endif
-
     switch (bs_extension_id)
     {
 #ifdef PS_DEC
     case EXTENSION_ID_PS:
         return ps_data(&(sbr->ps), ld);
+#endif
+#ifdef DRM
+    case DRM_PARAMETRIC_STEREO:
+        return drm_ps_data(&(sbr->drm_ps), ld);
 #endif
     default:
         sbr->bs_extension_data = (uint8_t)faad_getbits(ld, 6