ref: b1d957de163081057eac05c26d502f6c28fc6dc8
parent: 5f078c13f02d9d3cbfd562d29b72a490a58822f0
author: menno <menno>
date: Sat Apr 20 10:45:13 EDT 2002
Added beginning of SBR decoding (definately not compilable yet :)
--- /dev/null
+++ b/libfaad/common.c
@@ -1,0 +1,32 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: common.c,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+/* just some common functions that could be used anywhere */
+
+#include "common.h"
+
+#define LOG2 0.30102999566398
+
+
+uint32_t int_log2(uint32_t val)
+{
+ return (uint32_t)(log((real_t)val)/LOG2 + 0.5);
+}
--- a/libfaad/common.h
+++ b/libfaad/common.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: common.h,v 1.6 2002/04/07 21:26:04 menno Exp $
+** $Id: common.h,v 1.7 2002/04/20 14:45:13 menno Exp $
**/
#ifndef __COMMON_H__
@@ -168,6 +168,11 @@
#include <math.h>
#endif
+
+
+/* common functions */
+uint32_t int_log2(uint32_t val);
+
#ifdef __cplusplus
}
--- a/libfaad/libfaad.dsp
+++ b/libfaad/libfaad.dsp
@@ -437,6 +437,10 @@
# End Source File
# Begin Source File
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
SOURCE=.\data.c
# End Source File
# Begin Source File
@@ -493,6 +497,18 @@
# End Source File
# Begin Source File
+SOURCE=.\sbr_huff.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_qmf.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_syntax.c
+# End Source File
+# Begin Source File
+
SOURCE=.\specrec.c
# End Source File
# Begin Source File
@@ -602,6 +618,18 @@
# Begin Source File
SOURCE=.\pulse.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_huff.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_qmf.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\sbr_syntax.h
# End Source File
# Begin Source File
--- /dev/null
+++ b/libfaad/sbr_huff.c
@@ -1,0 +1,27 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: sbr_huff.c,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+#include "common.h"
+
+#ifdef SBR
+
+
+#endif
--- /dev/null
+++ b/libfaad/sbr_huff.h
@@ -1,0 +1,38 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: sbr_huff.h,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+#ifdef SBR
+
+#ifndef __SBR_HUFF_H__
+#define __SBR_HUFF_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#endif /* SBR */
\ No newline at end of file
--- /dev/null
+++ b/libfaad/sbr_qmf.c
@@ -1,0 +1,213 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: sbr_qmf.c,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+#include "common.h"
+
+#ifdef SBR
+
+void sbr_qmf_analysis()
+{
+ uint8_t l;
+
+ /* qmf subsample l */
+ for (l = 0; l < 32; l++)
+ {
+ uint8_t k;
+ uint16_t n;
+
+ /* shift input buffer x */
+ for (n = 320 - 1; n <= 0; n++)
+ {
+ x[n] = x[n - 32];
+ }
+
+ /* add new samples to input buffer x */
+ for (n = 32 - 1; n <= 0; n++)
+ {
+ x[n] = input_sample;
+ }
+
+ /* window by 320 coefficients to produce array z */
+ for (n = 0; n < 320; n++)
+ {
+ z[n] = x[n] * qmf_c[2*n];
+ }
+
+ /* summation to create array u */
+ for (n = 0; n < 64; n++)
+ {
+ uint8_t j;
+
+ u[n] = 0.0;
+ for (j = 0; j < 4; j++)
+ {
+ u[n] += z[n + j * 64];
+ }
+ }
+
+ /* calculate 32 subband samples by introducing Xlow */
+ for (k = 0; k < 32; k++)
+ {
+ Xlow[k][l] = 0.0;
+ for (n = 0; n < 64; n++)
+ {
+ Xlow[k][l] += u[n] * 2 * exp(i*M_PI/64 * (k + 0.5) * (2*n - 0.5));
+ }
+ }
+ }
+}
+
+void sbr_qmf_analysis()
+{
+}
+
+static real_t qmf_c[] = {
+ 0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, -0.0004875227,
+ -0.0004893791, -0.0005040714, -0.0005226564, -0.0005466565, -0.0005677802,
+ -0.0005870930, -0.0006132747, -0.0006312493, -0.0006540333, -0.0006777690,
+ -0.0006941614, -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598,
+ -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869, -0.0007803664,
+ -0.0007801449, -0.0007757977, -0.0007630793, -0.0007530001, -0.0007319357,
+ -0.0007215391, -0.0006917937, -0.0006650415, -0.0006341594, -0.0005946118,
+ -0.0005564576, -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175,
+ -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, 0.0000134949,
+ 0.0001094383, 0.0002043017, 0.0002949531, 0.0004026540, 0.0005107388,
+ 0.0006239376, 0.0007458025, 0.0008608443, 0.0009885988, 0.0011250155,
+ 0.0012577884, 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265,
+ 0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616, 0.0026201758,
+ 0.0027870464, 0.0029469447, 0.0031125420, 0.0032739613, 0.0034418874,
+ 0.0036008268, 0.0037603922, 0.0039207432, 0.0040819753, 0.0042264269,
+ 0.0043730719, 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603,
+ 0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, 0.0054196775,
+ 0.0054876040, 0.0055475714, 0.0055938023, 0.0056220643, 0.0056455196,
+ 0.0056389199, 0.0056266114, 0.0055917128, 0.0055404363, 0.0054753783,
+ 0.0053838975, 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469,
+ 0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408, 0.0035401246,
+ 0.0032091885, 0.0028446757, 0.0024508540, 0.0020274176, 0.0015784682,
+ 0.0010902329, 0.0005832264, 0.0000276045, -0.0005464280, -0.0011568135,
+ -0.0018039472, -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596,
+ -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, -0.0091325329,
+ -0.0101150215, -0.0111315548, -0.0121849995, 0.0132718220, 0.0143904666,
+ 0.0155405553, 0.0167324712, 0.0179433381, 0.0191872431, 0.0204531793,
+ 0.0217467550, 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429,
+ 0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081, 0.0344620948,
+ 0.0359697560, 0.0374812850, 0.0390053679, 0.0405349170, 0.0420649094,
+ 0.0436097542, 0.0451488405, 0.0466843027, 0.0482165720, 0.0497385755,
+ 0.0512556155, 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450,
+ 0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, 0.0639715898,
+ 0.0652247106, 0.0664367512, 0.0676075985, 0.0687043828, 0.0697630244,
+ 0.0707628710, 0.0717002673, 0.0725682583, 0.0733620255, 0.0741003642,
+ 0.0747452558, 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170,
+ 0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924, 0.0765050718,
+ 0.0761748321, 0.0757305756, 0.0751576255, 0.0744664394, 0.0736406005,
+ 0.0726774642, 0.0715826364, 0.0703533073, 0.0689664013, 0.0674525021,
+ 0.0657690668, 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691,
+ 0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, 0.0434768782,
+ 0.0401458278, 0.0366418116, 0.0329583930, 0.0290824006, 0.0250307561,
+ 0.0207997072, 0.0163701258, 0.0117623832, 0.0069636862, 0.0019765601,
+ -0.0032086896, -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288,
+ -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176, -0.0583705326,
+ -0.0654409853, -0.0726943300, -0.0801372934, -0.0877547536, -0.0955533352,
+ -0.1035329531, -0.1116826931, -0.1200077984, -0.1285002850, -0.1371551761,
+ -0.1459766491, -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548,
+ -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, -0.2320690870,
+ -0.2423016884, -0.2526480309, -0.2631053299, -0.2736634040, -0.2843214189,
+ -0.2950716717, -0.3059098575, -0.3168278913, -0.3278113727, -0.3388722693,
+ -0.3499914122, 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761,
+ 0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754, 0.4515996535,
+ 0.4629308085, 0.4742453214, 0.4855253091, 0.4967708254, 0.5079817500,
+ 0.5191234970, 0.5302240895, 0.5412553448, 0.5522051258, 0.5630789140,
+ 0.5738524131, 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932,
+ 0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, 0.6655139880,
+ 0.6749663190, 0.6842353293, 0.6933282376, 0.7022388719, 0.7109410426,
+ 0.7194462634, 0.7277448900, 0.7358211758, 0.7436827863, 0.7513137456,
+ 0.7587080760, 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120,
+ 0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004, 0.8138191270,
+ 0.8185776004, 0.8230419890, 0.8272275347, 0.8311038457, 0.8346937361,
+ 0.8379717337, 0.8409541392, 0.8436238281, 0.8459818469, 0.8480315777,
+ 0.8497805198, 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573,
+ 0.8537385600, 0.8535720573, 0.8531020949, 0.8523047035, 0.8511971524,
+ 0.8497805198, 0.8480315777, 0.8459818469, 0.8436238281, 0.8409541392,
+ 0.8379717337, 0.8346937361, 0.8311038457, 0.8272275347, 0.8230419890,
+ 0.8185776004, 0.8138191270, 0.8087695004, 0.8034485751, 0.7978466413,
+ 0.7919735841, 0.7858353120, 0.7794287519, 0.7727780881, 0.7658674865,
+ 0.7587080760, 0.7513137456, 0.7436827863, 0.7358211758, 0.7277448900,
+ 0.7194462634, 0.7109410426, 0.7022388719, 0.6933282376, 0.6842353293,
+ 0.6749663190, 0.6655139880, 0.6559016302, 0.6461269695, 0.6361980107,
+ 0.6261242695, 0.6159109932, 0.6055783538, 0.5951123086, 0.5845403235,
+ 0.5738524131, 0.5630789140, 0.5522051258, 0.5412553448, 0.5302240895,
+ 0.5191234970, 0.5079817500, 0.4967708254, 0.4855253091, 0.4742453214,
+ 0.4629308085, 0.4515996535, 0.4402553754, 0.4289119920, 0.4175696896,
+ 0.4062317676, 0.3949211761, 0.3836350013, 0.3723795546, -0.3611589903,
+ -0.3499914122, -0.3388722693, -0.3278113727, -0.3168278913, -0.3059098575,
+ -0.2950716717, -0.2843214189, -0.2736634040, -0.2631053299, -0.2526480309,
+ -0.2423016884, -0.2320690870, -0.2219652696, -0.2119735853, -0.2021250176,
+ -0.1923966745, -0.1828172548, -0.1733808172, -0.1640958855, -0.1549607071,
+ -0.1459766491, -0.1371551761, -0.1285002850, -0.1200077984, -0.1116826931,
+ -0.1035329531, -0.0955533352, -0.0877547536, -0.0801372934, -0.0726943300,
+ -0.0654409853, -0.0583705326, -0.0514804176, -0.0447806821, -0.0382776572,
+ -0.0319531274, -0.0258227288, -0.0198834129, -0.0141288827, -0.0085711749,
+ -0.0032086896, 0.0019765601, 0.0069636862, 0.0117623832, 0.0163701258,
+ 0.0207997072, 0.0250307561, 0.0290824006, 0.0329583930, 0.0366418116,
+ 0.0401458278, 0.0434768782, 0.0466303305, 0.0495978676, 0.0524093821,
+ 0.0550460034, 0.0575152691, 0.0598166570, 0.0619602779, 0.0639444805,
+ 0.0657690668, 0.0674525021, 0.0689664013, 0.0703533073, 0.0715826364,
+ 0.0726774642, 0.0736406005, 0.0744664394, 0.0751576255, 0.0757305756,
+ 0.0761748321, 0.0765050718, 0.0767204924, 0.0768230011, 0.0768173975,
+ 0.0767093490, 0.0764992170, 0.0761992479, 0.0758008358, 0.0753137336,
+ 0.0747452558, 0.0741003642, 0.0733620255, 0.0725682583, 0.0717002673,
+ 0.0707628710, 0.0697630244, 0.0687043828, 0.0676075985, 0.0664367512,
+ 0.0652247106, 0.0639715898, 0.0626857808, 0.0613455171, 0.0599837480,
+ 0.0585915683, 0.0571616450, 0.0557173648, 0.0542452768, 0.0527630746,
+ 0.0512556155, 0.0497385755, 0.0482165720, 0.0466843027, 0.0451488405,
+ 0.0436097542, 0.0420649094, 0.0405349170, 0.0390053679, 0.0374812850,
+ 0.0359697560, 0.0344620948, 0.0329754081, 0.0315017608, 0.0300502657,
+ 0.0286072173, 0.0271859429, 0.0257875847, 0.0244160992, 0.0230680169,
+ 0.0217467550, 0.0204531793, 0.0191872431, 0.0179433381, 0.0167324712,
+ 0.0155405553, 0.0143904666, -0.0132718220, -0.0121849995, -0.0111315548,
+ -0.0101150215, -0.0091325329, -0.0081798233, -0.0072615816, -0.0063792293,
+ -0.0055337211, -0.0047222596, -0.0039401124, -0.0031933778, -0.0024826723,
+ -0.0018039472, -0.0011568135, -0.0005464280, 0.0000276045, 0.0005832264,
+ 0.0010902329, 0.0015784682, 0.0020274176, 0.0024508540, 0.0028446757,
+ 0.0032091885, 0.0035401246, 0.0038456408, 0.0041251642, 0.0043801861,
+ 0.0046039530, 0.0048109469, 0.0049839687, 0.0051382275, 0.0052715758,
+ 0.0053838975, 0.0054753783, 0.0055404363, 0.0055917128, 0.0056266114,
+ 0.0056389199, 0.0056455196, 0.0056220643, 0.0055938023, 0.0055475714,
+ 0.0054876040, 0.0054196775, 0.0053471681, 0.0052461166, 0.0051407353,
+ 0.0050393022, 0.0049137603, 0.0047932560, 0.0046606460, 0.0045209852,
+ 0.0043730719, 0.0042264269, 0.0040819753, 0.0039207432, 0.0037603922,
+ 0.0036008268, 0.0034418874, 0.0032739613, 0.0031125420, 0.0029469447,
+ 0.0027870464, 0.0026201758, 0.0024625616, 0.0023017254, 0.0021461583,
+ 0.0019841140, 0.0018348265, 0.0016868083, 0.0015443219, 0.0013902494,
+ 0.0012577884, 0.0011250155, 0.0009885988, 0.0008608443, 0.0007458025,
+ 0.0006239376, 0.0005107388, 0.0004026540, 0.0002949531, 0.0002043017,
+ 0.0001094383, 0.0000134949, -0.0000617334, -0.0001446380, -0.0002098337,
+ -0.0002896981, -0.0003501175, -0.0004095121, -0.0004606325, -0.0005145572,
+ -0.0005564576, -0.0005946118, -0.0006341594, -0.0006650415, -0.0006917937,
+ -0.0007215391, -0.0007319357, -0.0007530001, -0.0007630793, -0.0007757977,
+ -0.0007801449, -0.0007803664, -0.0007779869, -0.0007834332, -0.0007724848,
+ -0.0007681371, -0.0007490598, -0.0007440941, -0.0007255043, -0.0007157736,
+ -0.0006941614, -0.0006777690, -0.0006540333, -0.0006312493, -0.0006132747,
+ -0.0005870930, -0.0005677802, -0.0005466565, -0.0005226564, -0.0005040714,
+ -0.0004893791, -0.0004875227, -0.0004947518, -0.0005617692, -0.000552528
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+++ b/libfaad/sbr_qmf.h
@@ -1,0 +1,39 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: sbr_qmf.h,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+#ifdef SBR
+
+#ifndef __SBR_QMF_H__
+#define __SBR_QMF_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static real_t qmf_c[];
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
+#endif /* SBR */
\ No newline at end of file
--- /dev/null
+++ b/libfaad/sbr_syntax.c
@@ -1,0 +1,568 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: sbr_syntax.c,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+/*
+ This is the initial support for MPEG-4 AAC+SBR
+
+ All data is taken from the Working Draft Text for Backward Compatible
+ Bandwidth Extension for General Audio Coding (N4611)
+*/
+
+
+#include "common.h"
+
+#ifdef SBR
+
+#include "sbr_syntax.h"
+#include "sbr_huff.h"
+#include "bits.h"
+#include "analysis.h"
+
+/* table 2 */
+uint8_t sbr_bitstream(bitfile *ld, sbr_info *sbr, uint8_t id_aac,
+ uint8_t bs_extension_type)
+{
+ sbr->bs_crc_flag = faad_get1bit(ld
+ DEBUGVAR(1,200,"sbr_bitstream(): bs_crc_flag"));
+ if (sbr->bs_crc_flag)
+ {
+ sbr->bs_sbr_crc_bits = faad_getbits(ld, 7
+ DEBUGVAR(1,201,"sbr_bitstream(): bs_sbr_crc_bits"));
+ }
+
+ if (bs_extension_type == SBR_HDR)
+ {
+ sbr_header(sbr, id_aac);
+ sbr_data(sbr, id_aac);
+ } else if (bs_extension_type == SBR_STD) {
+ sbr_data(sbr, id_aac);
+ }
+}
+
+/* table 3 */
+static void sbr_header(bitfile *ld, sbr_info *sbr, uint8_t id_aac)
+{
+ sbr->bs_protocol_version = faad_getbits(ld, 2
+ DEBUGVAR(1,202,"sbr_header(): bs_protocol_version"));
+ sbr->bs_amp_res = faad_get1bit(ld
+ DEBUGVAR(1,203,"sbr_header(): bs_amp_res"));
+ sbr->bs_start_freq = faad_getbits(ld, 4
+ DEBUGVAR(1,204,"sbr_header(): bs_start_freq"));
+ sbr->bs_stop_freq = faad_getbits(ld, 4
+ DEBUGVAR(1,205,"sbr_header(): bs_stop_freq"));
+ sbr->bs_xover_band = faad_getbits(ld, 3
+ DEBUGVAR(1,206,"sbr_header(): bs_xover_band"));
+ faad_getbits(ld, 3
+ DEBUGVAR(1,207,"sbr_header(): bs_reserved"));
+ sbr->bs_header_extra_1 = faad_get1bit(ld
+ DEBUGVAR(1,208,"sbr_header(): bs_header_extra_1"));
+ sbr->bs_header_extra_2 = faad_get1bit(ld
+ DEBUGVAR(1,209,"sbr_header(): bs_header_extra_2"));
+
+ if (id_aac == ID_SCE)
+ {
+ faad_getbits(ld, 2
+ DEBUGVAR(1,210,"sbr_header(): bs_reserved"));
+ }
+
+ if (sbr->bs_header_extra_1)
+ {
+ sbr->bs_freq_scale = faad_getbits(ld, 2
+ DEBUGVAR(1,211,"sbr_header(): bs_freq_scale"));
+ sbr->bs_alter_scale = faad_get1bit(ld
+ DEBUGVAR(1,212,"sbr_header(): bs_alter_scale"));
+ sbr->bs_noise_bands = faad_getbits(ld, 2
+ DEBUGVAR(1,213,"sbr_header(): bs_noise_bands"));
+ }
+ if (sbr->bs_header_extra_2)
+ {
+ sbr->bs_limiter_bands = faad_getbits(ld, 2
+ DEBUGVAR(1,214,"sbr_header(): bs_limiter_bands"));
+ sbr->bs_limiter_gains = faad_getbits(ld, 2
+ DEBUGVAR(1,215,"sbr_header(): bs_limiter_gains"));
+ sbr->bs_interpol_freq = faad_get1bit(ld
+ DEBUGVAR(1,216,"sbr_header(): bs_interpol_freq"));
+ sbr->bs_smoothing_mode = faad_get1bit(ld
+ DEBUGVAR(1,217,"sbr_header(): bs_smoothing_mode"));
+ faad_get1bit(ld
+ DEBUGVAR(1,218,"sbr_header(): bs_reserved"));
+ }
+}
+
+/* table 4 */
+static void sbr_data(bitfile *ld, sbr_info *sbr, uint8_t id_aac)
+{
+ sbr->bs_samplerate_mode = faad_get1bit(ld
+ DEBUGVAR(1,219,"sbr_data(): bs_samplerate_mode"));
+
+ switch (id_aac)
+ {
+ case ID_SCE:
+ sbr_single_channel_element(sbr);
+ break;
+ case ID_CPE:
+ sbr_channel_pair_element(sbr);
+ break;
+ }
+}
+
+/* table 5 */
+static void sbr_single_channel_element(bitfile *ld, sbr_info *sbr)
+{
+ faad_get1bit(ld
+ DEBUGVAR(1,220,"sbr_single_channel_element(): bs_reserved"));
+
+ sbr_grid(sbr, 0);
+ sbr_dtdf(sbr, 0);
+ invf_mode(sbr, 0);
+
+ faad_getbits(ld, 2
+ DEBUGVAR(1,221,"sbr_single_channel_element(): bs_reserved"));
+
+ sbr_envelope(sbr, 0, 0);
+ sbr_noise(sbr, 0, 0);
+
+ faad_get1bit(ld
+ DEBUGVAR(1,222,"sbr_single_channel_element(): bs_reserved"));
+
+ faad_get1bit(ld
+ DEBUGVAR(1,222,"sbr_single_channel_element(): bs_reserved"));
+
+ sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld
+ DEBUGVAR(1,223,"sbr_single_channel_element(): bs_add_harmonic_flag[0]"));
+ if (sbr->bs_add_harmonic_flag[0])
+ sinusoidal_coding(sbr, 0);
+
+ sbr->bs_extended_data[0] = faad_get1bit(ld
+ DEBUGVAR(1,224,"sbr_single_channel_element(): bs_extended_data[0]"));
+ if (sbr->bs_extended_data[0])
+ {
+ cnt = faad_getbits(ld, 4
+ DEBUGVAR(1,225,"sbr_single_channel_element(): bs_extension_size"));
+ if (cnt == 15)
+ {
+ cnt += faad_getbits(ld, 8
+ DEBUGVAR(1,226,"sbr_single_channel_element(): bs_esc_count"));
+ }
+
+ nr_bits_left = 8 * cnt;
+ while (nr_bits_left > 7)
+ {
+ sbr->bs_extension_id = faad_getbits(ld, 2
+ DEBUGVAR(1,227,"sbr_single_channel_element(): bs_extension_id"));
+ nr_bits_left -= 2;
+ sbr_extension(sbr, 0, nr_bits_left);
+ }
+ }
+}
+
+/* table 6 */
+static void sbr_channel_pair_element(bitfile *ld, sbr_info *sbr)
+{
+ sbr->bs_coupling = faad_get1bit(ld
+ DEBUGVAR(1,228,"sbr_channel_pair_element(): bs_coupling"));
+
+ if (sbr->bs_coupling)
+ {
+ sbr_grid(sbr, 0);
+ sbr_dtdf(sbr, 0);
+ sbr_dtdf(sbr, 1);
+ invf_mode(sbr, 0);
+
+ faad_getbits(ld, 2
+ DEBUGVAR(1,229,"sbr_channel_pair_element(): bs_reserved"));
+
+ sbr_envelope(sbr, 0, 1);
+ sbr_noise(sbr, 0, 1);
+ sbr_envelope(sbr, 1, 1);
+ sbr_noise(sbr, 1, 1);
+
+ faad_getbits(ld, 2
+ DEBUGVAR(1,230,"sbr_channel_pair_element(): bs_reserved"));
+
+ sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld
+ DEBUGVAR(1,231,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]"));
+ if (sbr->bs_add_harmonic_flag[0])
+ sinusoidal_coding(sbr, 0);
+
+ sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld
+ DEBUGVAR(1,232,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]"));
+ if (sbr->bs_add_harmonic_flag[1])
+ sinusoidal_coding(sbr, 1);
+
+ sbr->bs_extended_data[0] = faad_get1bit(ld
+ DEBUGVAR(1,233,"sbr_channel_pair_element(): bs_extended_data[0]"));
+ if (bs_extended_data[0])
+ {
+ cnt = faad_getbits(ld, 4
+ DEBUGVAR(1,234,"sbr_channel_pair_element(): bs_extension_size"));
+ if (cnt == 15)
+ {
+ cnt += faad_getbits(ld, 8
+ DEBUGVAR(1,235,"sbr_channel_pair_element(): bs_esc_count"));
+ }
+
+ nr_bits_left = 8 * cnt;
+ while (nr_bits_left > 7)
+ {
+ sbr->bs_extension_id = faad_getbits(ld, 2
+ DEBUGVAR(1,236,"sbr_channel_pair_element(): bs_extension_id"));
+ nr_bits_left -= 2;
+ sbr_extension(sbr, 0, nr_bits_left);
+ }
+ }
+ } else {
+ sbr_grid(sbr, 0);
+ sbr_grid(sbr, 1);
+ sbr_dtdf(sbr, 0);
+ sbr_dtdf(sbr, 1);
+ invf_mode(sbr, 0);
+ invf_mode(sbr, 1);
+
+ faad_getbits(ld, 4
+ DEBUGVAR(1,237,"sbr_channel_pair_element(): bs_reserved"));
+
+ sbr_envelope(sbr, 0, 0);
+ sbr_envelope(sbr, 1, 0);
+ sbr_noise(sbr, 0, 0);
+ sbr_noise(sbr, 1, 0);
+
+ faad_getbits(ld, 2
+ DEBUGVAR(1,238,"sbr_channel_pair_element(): bs_reserved"));
+
+ sbr->bs_add_harmonic_flag[0] = faad_get1bit(ld
+ DEBUGVAR(1,239,"sbr_channel_pair_element(): bs_add_harmonic_flag[0]"));
+ if (bs_add_harmonic_flag[0])
+ sinusoidal_coding(sbr, 0);
+
+ sbr->bs_add_harmonic_flag[1] = faad_get1bit(ld
+ DEBUGVAR(1,240,"sbr_channel_pair_element(): bs_add_harmonic_flag[1]"));
+ if (bs_add_harmonic_flag[1])
+ sinusoidal_coding(sbr, 1);
+
+ sbr->bs_extended_data[0] = faad_get1bit(ld
+ DEBUGVAR(1,241,"sbr_channel_pair_element(): bs_extended_data[0]"));
+ if (bs_extended_data[0])
+ {
+ cnt = faad_getbits(ld, 4
+ DEBUGVAR(1,242,"sbr_channel_pair_element(): bs_extension_size"));
+ if (cnt == 15)
+ {
+ cnt += faad_getbits(ld, 8
+ DEBUGVAR(1,243,"sbr_channel_pair_element(): bs_esc_count"));
+ }
+
+ nr_bits_left = 8 * cnt;
+ while (nr_bits_left > 7)
+ {
+ sbr->bs_extension_id = faad_getbits(ld, 2
+ DEBUGVAR(1,244,"sbr_channel_pair_element(): bs_extension_id"));
+ nr_bits_left -= 2;
+ sbr_extension(sbr, 0, nr_bits_left);
+ }
+ }
+
+ sbr->bs_extended_data[1] = faad_get1bit(ld
+ DEBUGVAR(1,245,"sbr_channel_pair_element(): bs_extended_data[1]"));
+ if (bs_extended_data[1])
+ {
+ cnt = faad_getbits(ld, 4
+ DEBUGVAR(1,246,"sbr_channel_pair_element(): bs_extension_size"));
+ if (cnt == 15)
+ {
+ cnt += faad_getbits(ld, 8
+ DEBUGVAR(1,247,"sbr_channel_pair_element(): bs_esc_count"));
+ }
+
+ nr_bits_left = 8 * cnt;
+ while (nr_bits_left > 7)
+ {
+ sbr->bs_extension_id = faad_getbits(ld, 2
+ DEBUGVAR(1,248,"sbr_channel_pair_element(): bs_extension_id"));
+ nr_bits_left -= 2;
+ sbr_extension(sbr, 1, nr_bits_left);
+ }
+ }
+ }
+}
+
+/* table 7 */
+static void sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch)
+{
+ sbr->bs_frame_class = faad_getbits(ld, 2
+ DEBUGVAR(1,248,"sbr_grid(): bs_frame_class"));
+
+ switch (sbr->bs_frame_class)
+ {
+ case FIXFIX:
+ uint8_t bs_num_env_raw = faad_getbits(ld, 2
+ DEBUGVAR(1,249,"sbr_grid(): bs_num_env_raw"));
+
+ sbr->bs_num_env[ch] = min(1 << bs_num_env_raw, 5);
+ if (sbr->bs_num_env[ch] == 1)
+ sbr->bs_amp_res = 0;
+
+ temp = faad_get1bit(ld
+ DEBUGVAR(1,250,"sbr_grid(): bs_freq_res_flag"));
+ for (env = 0; env < sbr->bs_num_env[ch]; env++)
+ bs_freq_res[ch][env] = temp;
+ break;
+
+ case FIXVAR:
+ sbr->bs_abs_bord[ch] = faad_getbits(ld, 3
+ DEBUGVAR(1,251,"sbr_grid(): bs_abs_bord")) + NO_TIME_SLOTS;
+ sbr->bs_num_env[ch] = faad_getbits(ld, 2
+ DEBUGVAR(1,252,"sbr_grid(): bs_num_env")) + 1;
+
+ for (rel = 0; rel < sbr->bs_num_env[ch]-1; rel++)
+ {
+ bs_rel_bord[ch][rel] = 2 * faad_getbits(ld, 2
+ DEBUGVAR(1,253,"sbr_grid(): bs_rel_bord")) + 2;
+ }
+ bs_ptr_bits = int_log2(bs_num_env[ch] + 1);
+ sbr->bs_pointer[ch] = faad_getbits(ld, bs_ptr_bits
+ DEBUGVAR(1,254,"sbr_grid(): bs_pointer"));
+
+ for (env = 0; env < sbr->bs_num_env[ch]; env++)
+ {
+ sbr->bs_freq_res[ch][sbr->bs_num_env[ch] - env - 1] = faad_get1bit(ld
+ DEBUGVAR(1,255,"sbr_grid(): bs_freq_res"));
+ }
+ break;
+
+ case VARFIX:
+ sbr->bs_abs_bord[ch] = faad_getbits(ld, 3
+ DEBUGVAR(1,256,"sbr_grid(): bs_abs_bord"));
+ sbr->bs_num_env[ch] = faad_getbits(ld, 2
+ DEBUGVAR(1,257,"sbr_grid(): bs_num_env")) + 1;
+
+ for (rel = 0; rel < sbr->bs_num_env[ch]-1; rel++)
+ {
+ sbr->bs_rel_bord[ch][rel] = 2 * faad_getbits(ld, 2
+ DEBUGVAR(1,258,"sbr_grid(): bs_rel_bord")) + 2;
+ }
+ ptr_bits = int_log2(bs_num_env[ch] + 1);
+ sbr->bs_pointer[ch] = faad_getbits(ld, bs_ptr_bits
+ DEBUGVAR(1,259,"sbr_grid(): bs_pointer"));
+
+ for (env = 0; env < sbr->bs_num_env[ch]; env++)
+ {
+ sbr->bs_freq_res[ch][env] = faad_get1bit(ld
+ DEBUGVAR(1,260,"sbr_grid(): bs_freq_res"));
+ }
+ break;
+
+ case VARVAR:
+ sbr->bs_abs_bord_0[ch] = faad_getbits(ld, 3
+ DEBUGVAR(1,261,"sbr_grid(): bs_abs_bord_0"));
+ sbr->bs_abs_bord_1[ch] = faad_getbits(ld, 3
+ DEBUGVAR(1,262,"sbr_grid(): bs_abs_bord_1")) + NO_TIME_SLOTS;
+ bs_num_rel_0[ch] = faad_getbits(ld, 2
+ DEBUGVAR(1,263,"sbr_grid(): bs_num_rel_0"));
+ bs_num_rel_1[ch] = faad_getbits(ld, 2
+ DEBUGVAR(1,264,"sbr_grid(): bs_num_rel_1"));
+ sbr->bs_num_env[ch] = bs_num_rel_0[ch] + bs_num_rel_1[ch] + 1;
+
+ for (rel = 0; rel < bs_num_rel_0[ch]; rel++)
+ {
+ sbr->bs_rel_bord_0[ch][rel] = 2 * faad_getbits(ld, 2
+ DEBUGVAR(1,265,"sbr_grid(): bs_rel_bord")) + 2;
+ }
+ for(rel = 0; rel < bs_num_rel_1[ch]; rel++)
+ {
+ sbr->bs_rel_bord_1[ch][rel] = 2 * faad_getbits(ld, 2
+ DEBUGVAR(1,266,"sbr_grid(): bs_rel_bord")) + 2;
+ }
+ bs_ptr_bits = int_log2(bs_num_rel_0[ch] + bs_num_rel_1[ch] + 2);
+ sbr->bs_pointer[ch] = faad_getbits(ld, bs_ptr_bits
+ DEBUGVAR(1,267,"sbr_grid(): bs_pointer"));
+
+ for (env = 0; env < sbr->bs_num_env[ch]; env++)
+ {
+ sbr->bs_freq_res[ch][env] = faad_get1bit(ld
+ DEBUGVAR(1,268,"sbr_grid(): bs_freq_res"));
+ }
+ break;
+ }
+
+ if (sbr->bs_num_env[ch] > 1)
+ sbr->bs_num_noise[ch] = 2;
+ else
+ sbr->bs_num_noise[ch] = 1;
+}
+
+/* table 8 */
+static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch)
+{
+ uint8_t i;
+
+ for (i = 0; i < sbr->bs_num_env[ch]; i++)
+ {
+ sbr->bs_df_env[ch][i] = faad_get1bit(ld
+ DEBUGVAR(1,269,"sbr_dtdf(): bs_df_env"));
+ }
+
+ for (i = 0; i < sbr->bs_num_noise[ch]; i++)
+ {
+ sbr->bs_df_noise[ch][i] = faad_get1bit(ld
+ DEBUGVAR(1,270,"sbr_dtdf(): bs_df_noise"));
+ }
+}
+
+/* table 9 */
+static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch)
+{
+ uint8_t n;
+
+ for (n = 0; n < sbr->num_noise_bands[ch]; n++)
+ {
+ sbr->bs_invf_mode_vec[ch][n] = faad_getbits(ld, 2
+ DEBUGVAR(1,271,"invf_mode(): bs_invf_mode_vec"));
+ }
+}
+
+/* table 10 */
+static void sbr_envelope(bitfile *ld, sbr_info *sbr, uint8_t ch)
+{
+ if (sbr->bs_coupling)
+ {
+ if (ch)
+ {
+ if (sbr->bs_amp_res)
+ {
+ t_huff = t_huffman_env_bal_3_0dB;
+ f_huff = f_huffman_env_bal_3_0dB;
+ } else {
+ t_huff = t_huffman_env_bal_1_5dB;
+ f_huff = f_huffman_env_bal_1_5dB;
+ }
+ } else {
+ if (sbr->bs_amp_res)
+ {
+ t_huff = t_huffman_env_3_0dB;
+ f_huff = f_huffman_env_3_0dB;
+ } else {
+ t_huff = t_huffman_env_1_5dB;
+ f_huff = f_huffman_env_1_5dB;
+ }
+ }
+ } else {
+ if (sbr->bs_amp_res)
+ {
+ t_huff = t_huffman_env_3_0dB;
+ f_huff = f_huffman_env_3_0dB;
+ } else {
+ t_huff = t_huffman_env_1_5dB;
+ f_huff = f_huffman_env_1_5dB;
+ }
+ }
+
+ for (env = 0; env < sbr->bs_num_env[ch]; env++)
+ {
+ if (sbr->bs_df_env[ch][env] == 0)
+ {
+ if (sbr->bs_coupling && ch)
+ {
+ if (sbr->bs_amp_res)
+ {
+ sbr->bs_data_env[ch][env][0] = faad_getbits(ld, 5
+ DEBUGVAR(1,272,"sbr_envelope(): bs_data_env"));
+ } else {
+ sbr->bs_data_env[ch][env][0] = faad_getbits(ld, 6
+ DEBUGVAR(1,273,"sbr_envelope(): bs_data_env"));
+ }
+ } else {
+ if (bs_amp_res)
+ {
+ sbr->bs_data_env[ch][env][0] = faad_getbits(ld, 6
+ DEBUGVAR(1,274,"sbr_envelope(): bs_data_env"));
+ } else {
+ sbr->bs_data_env[ch][env][0] = faad_getbits(ld, 7
+ DEBUGVAR(1,275,"sbr_envelope(): bs_data_env"));
+ }
+ for (band = 1; band < num_env_bands[bs_freq_res[ch][env]]; band++)
+ {
+ sbr->bs_data_env[ch][env][band] = huff_dec(f_huff, bs_codeword);
+ }
+ }
+ } else {
+ for (band = 0; band < sbr->num_env_bands[bs_freq_res[ch][env]]; band++)
+ sbr->bs_data_env[ch][env][band] = huff_dec(t_huff, bs_codeword);
+ }
+ }
+}
+
+/* table 11 */
+static void sbr_noise(bitfile *ld, sbr_info *sbr, uint8_t ch)
+{
+ if (sbr->bs_coupling)
+ {
+ if (ch) {
+ t_huff = t_huffman_noise_bal_3_0dB;
+ f_huff = f_huffman_noise_bal_3_0dB;
+ } else {
+ t_huff = t_huffman_noise_3_0dB;
+ f_huff = f_huffman_noise_3_0dB;
+ }
+ } else {
+ t_huff = t_huffman_noise_3_0dB;
+ f_huff = f_huffman_noise_3_0dB;
+ }
+
+ for(noise = 0; noise < sbr->bs_num_noise[ch]; noise++)
+ {
+ if(sbr->bs_df_noise[ch][noise] == 0)
+ {
+ if (sbr->bs_coupling && ch)
+ {
+ sbr->bs_data_noise[ch][noise][0] = faad_getbits(ld, 5
+ DEBUGVAR(1,276,"sbr_noise(): bs_data_noise"));
+ } else {
+ sbr->bs_data_noise[ch][noise][0] = faad_getbits(ld, 5
+ DEBUGVAR(1,277,"sbr_noise(): bs_data_noise"));
+ }
+ for (band = 1; band < sbr->num_noise_bands[ch]; band++)
+ {
+ sbr->bs_data_noise[ch][noise][band] = huff_dec(f_huff, bs_codeword);
+ }
+ } else {
+ for (band = 0; band < sbr->num_noise_bands[ch]; band++)
+ {
+ sbr->bs_data_noise[ch][noise][band] = huff_dec(t_huff, bs_codeword);
+ }
+ }
+ }
+}
+
+/* table 12 */
+static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch)
+{
+ uint8_t n;
+
+ for (n = 0; n < num_high_res[ch]; n++)
+ {
+ sbr->bs_add_harmonic[ch][n] = faad_get1bit(ld
+ DEBUGVAR(1,278,"sinusoidal_coding(): bs_add_harmonic"));
+ }
+}
+
+
+#endif /* SBR */
\ No newline at end of file
--- /dev/null
+++ b/libfaad/sbr_syntax.h
@@ -1,0 +1,62 @@
+/*
+** FAAD - Freeware Advanced Audio Decoder
+** Copyright (C) 2002 M. Bakker
+**
+** 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.
+**
+** $Id: sbr_syntax.h,v 1.1 2002/04/20 14:45:13 menno Exp $
+**/
+
+#ifdef SBR
+
+#ifndef __SBR_SYNTAX_H__
+#define __SBR_SYNTAX_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SBR_STD 12
+#define SBR_HDR 13
+
+#define FIXFIX 0
+#define FIXVAR 1
+#define VARFIX 2
+#define VARVAR 3
+
+typedef struct
+{
+ uint8_t dummy;
+} sbr_info;
+
+uint8_t sbr_bitstream(bitfile *ld, sbr_info *sbr, uint8_t id_aac,
+ uint8_t bs_extension_type);
+static void sbr_header(bitfile *ld, sbr_info *sbr, uint8_t id_aac);
+static void sbr_data(bitfile *ld, sbr_info *sbr, uint8_t id_aac);
+static void sbr_single_channel_element(bitfile *ld, sbr_info *sbr);
+static void sbr_channel_pair_element(bitfile *ld, sbr_info *sbr);
+static void sbr_grid(bitfile *ld, sbr_info *sbr, uint8_t ch);
+static void sbr_dtdf(bitfile *ld, sbr_info *sbr, uint8_t ch);
+static void invf_mode(bitfile *ld, sbr_info *sbr, uint8_t ch);
+static void sbr_envelope(bitfile *ld, sbr_info *sbr, uint8_t ch);
+static void sbr_noise(bitfile *ld, sbr_info *sbr, uint8_t ch);
+static void sinusoidal_coding(bitfile *ld, sbr_info *sbr, uint8_t ch);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __SBR_SYNTAX_H__ */
+
+#endif /* SBR */
\ No newline at end of file
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: syntax.c,v 1.11 2002/04/18 18:08:07 menno Exp $
+** $Id: syntax.c,v 1.12 2002/04/20 14:45:13 menno Exp $
**/
/*
@@ -37,6 +37,9 @@
#include "data.h"
#include "pulse.h"
#include "analysis.h"
+#ifdef SBR
+#include "sbr_syntax.h"
+#endif
/* Table 4.4.1 */
@@ -408,9 +411,17 @@
}
/* Table 4.4.11 */
-uint8_t fill_element(bitfile *ld, drc_info *drc)
+uint8_t fill_element(bitfile *ld, drc_info *drc
+#ifdef SBR
+ ,uint8_t next_ele_id
+#endif
+ )
{
uint16_t count;
+#ifdef SBR
+ uint8_t bs_extension_type;
+ uint32_t btot;
+#endif
count = (uint16_t)faad_getbits(ld, 4
DEBUGVAR(1,65,"fill_element(): count"));
@@ -420,10 +431,43 @@
DEBUGVAR(1,66,"fill_element(): extra count")) - 1;
}
- while (count > 0)
+#ifdef SBR
+ bs_extension_type = (uint8_t)faad_showbits(ld, 4);
+
+ if (bs_extension_type == SBR_HDR || bs_extension_type == SBR_STD)
{
- count -= extension_payload(ld, drc, count);
+ uint16_t i;
+ uint16_t bytes, bits;
+
+ /* flush the extension type and the fill nibble */
+ faad_flushbits(ld, 8);
+
+ btot = faad_get_processed_bits(ld);
+
+ /* SBR bitstream reading function */
+ sbr_bitstream(next_ele_id, bs_extension_type);
+
+ btot = faad_get_processed_bits(ld) - btot;
+
+ /* there might still be some fill bits left to read */
+ bits = (8*(count-1) - btot) % 8;
+ bytes = ((8*(count-1) - btot) - bits) / 8;
+
+ if (bits > 0)
+ faad_flushbits(ld, bits);
+ for (i = 0; i < bytes; i++)
+ {
+ faad_flushbits(ld, 8);
+ }
+ } else {
+#endif
+ while (count > 0)
+ {
+ count -= extension_payload(ld, drc, count);
+ }
+#ifdef SBR
}
+#endif
return 0;
}
@@ -591,6 +635,13 @@
* decode_scale_factors()
* decodes the scalefactors from the bitstream
*/
+/*
+ * All scalefactors (and also the stereo positions and pns energies) are
+ * transmitted using Huffman coded DPCM relative to the previous active
+ * scalefactor (respectively previous stereo position or previous pns energy,
+ * see subclause 4.6.2 and 4.6.3). The first active scalefactor is
+ * differentially coded relative to the global gain.
+ */
static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld)
{
uint8_t g, sfb;
@@ -653,13 +704,6 @@
return 0;
}
-/*
- All scalefactors (and also the stereo positions and pns energies) are
- transmitted using Huffman coded DPCM relative to the previous active
- scalefactor (respectively previous stereo position or previous pns energy,
- see subclause 4.6.2 and 4.6.3). The first active scalefactor is
- differentially coded relative to the global gain.
-*/
/* Table 4.4.26 */
static uint8_t scale_factor_data(ic_stream *ics, bitfile *ld
#ifdef ERROR_RESILIENCE
@@ -689,10 +733,9 @@
length_of_rvlc_sf = faad_getbits(ld, bits
DEBUGVAR(1,151,"scale_factor_data(): length_of_rvlc_sf"));
- /* check how many bits are used in decoing the scalefactors
+ /* check how many bits are used in decoding the scalefactors
A better solution would be to read length_of_rvlc_sf ahead
in a buffer and use that to decode the scale factors
- There's work ahead :-)
*/
bits_used = faad_get_processed_bits(ld);
decode_scale_factors(ics, ld);
@@ -700,7 +743,7 @@
/* return an error if the number of decoded bits is not correct
FAAD should be able to recover from this, for example by
- setting all scalefactors to 0 (muting the frame)
+ setting all scalefactors to 0 (e.g. muting the frame)
*/
if (bits_used != length_of_rvlc_sf)
return 8;
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: syntax.h,v 1.6 2002/02/25 19:58:33 menno Exp $
+** $Id: syntax.h,v 1.7 2002/04/20 14:45:13 menno Exp $
**/
#ifndef __SYNTAX_H__
@@ -272,7 +272,11 @@
int16_t *spec_data2, uint8_t sf_index, uint8_t object_type);
uint16_t data_stream_element(bitfile *ld);
uint8_t program_config_element(program_config *pce, bitfile *ld);
-uint8_t fill_element(bitfile *ld, drc_info *drc);
+uint8_t fill_element(bitfile *ld, drc_info *drc
+#ifdef SBR
+ ,uint8_t next_ele_id
+#endif
+ );
uint8_t adts_frame(adts_header *adts, bitfile *ld);
void get_adif_header(adif_header *adif, bitfile *ld);