]> git.sesse.net Git - vlc/blobdiff - src/ac3_decoder/ac3_exponent.c
* Fixed a nonsense in configure.in preventing to build sdl.so.
[vlc] / src / ac3_decoder / ac3_exponent.c
index c6154a04908331a811bd716f307604885e6389fa..0cfc457fa22dba034351b7fb4fb9b52fc9aa5dc7 100644 (file)
-#include <unistd.h>                                              /* getpid() */
+/*****************************************************************************
+ * ac3_exponent.c: ac3 exponent calculations
+ *****************************************************************************
+ * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: ac3_exponent.c,v 1.23 2001/04/20 12:14:34 reno Exp $
+ *
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ *          Michel Lespinasse <walken@zoy.org>
+ *          Aaron Holtzman <aholtzma@engr.uvic.ca>
+ *
+ * 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, USA.
+ *****************************************************************************/
+#include "defs.h"
+
+#include <string.h>                                    /* memcpy(), memset() */
 
-#include <stdio.h>                                           /* "intf_msg.h" */
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <sys/soundcard.h>                               /* "audio_output.h" */
-#include <sys/uio.h>                                            /* "input.h" */
-
-#include "common.h"
 #include "config.h"
+#include "common.h"
+#include "threads.h"
 #include "mtime.h"
-#include "vlc_thread.h"
-#include "debug.h"                                      /* "input_netlist.h" */
 
-#include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
-
-#include "input.h"                                           /* pes_packet_t */
-#include "input_netlist.h"                         /* input_NetlistFreePES() */
-#include "decoder_fifo.h"         /* DECODER_FIFO_(ISEMPTY|START|INCSTART)() */
+#include "stream_control.h"
+#include "input_ext-dec.h"
 
 #include "audio_output.h"
 
 #include "ac3_decoder.h"
-#include "ac3_exponent.h"
+#include "ac3_decoder_thread.h"
+
+#include "intf_msg.h"
 
-static const s16 exps_1[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
-static const s16 exps_2[128] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0, 0, 0 };
-static const s16 exps_3[128] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2 };
+#include "ac3_internal.h"
 
-static __inline__ void exp_unpack_ch( u16 type, u16 expstr, u16 ngrps, u16 initial_exp, u16 exps[], u16 * dest )
+static const s16 exps_1[128] =
+{
+    -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
+    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+     2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+     0, 0, 0
+};
+
+static const s16 exps_2[128] =
 {
-       u16 i,j;
-       s16 exp_acc;
-       /*
-       s16 exp_1,exp_2,exp_3;
-       */
-
-       if(expstr == EXP_REUSE)
-               return;
-
-       /* Handle the initial absolute exponent */
-       exp_acc = initial_exp;
-       j = 0;
-
-       /* In the case of a fbw channel then the initial absolute values is 
-        * also an exponent */
-       if(type != UNPACK_CPL)
-               dest[j++] = exp_acc;
-
-       /* Loop through the groups and fill the dest array appropriately */
-       for ( i = 0; i < ngrps; i++ )
-       {
-               /*
-               if ( exps[i] > 124 )
-               {
-                       //FIXME set an error flag and mute the frame
-                       printf( "\n!! Invalid exponent !!\n" );
-                       exit( 1 );
-               }
-               */
-
-               /*
-               exp_1 = exps[i] / 25;
-               exp_2 = (exps[i] - (exp_1 * 25)) / 5;
-               exp_3 = exps[i] - (exp_1 * 25) - (exp_2 * 5) ;
-               */
-
-               switch ( expstr )
-               {
-                       case EXP_D45:
-                               exp_acc += (exps_1[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               exp_acc += (exps_2[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               exp_acc += (exps_3[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                       break;
-
-                       case EXP_D25:
-                               exp_acc += (exps_1[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               exp_acc += (exps_2[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                               exp_acc += (exps_3[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               dest[j++] = exp_acc;
-                       break;
-
-                       case EXP_D15:
-                               exp_acc += (exps_1[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               exp_acc += (exps_2[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                               exp_acc += (exps_3[exps[i]] - 2);
-                               dest[j++] = exp_acc;
-                       break;
-               }
-       }
+    -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
+    -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
+    -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
+    -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
+    -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
+     0, 0, 0
+};
+
+static const s16 exps_3[128] =
+{
+    -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
+    -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
+    -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
+    -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
+    -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
+     0, 0, 0
+};
+
+#define UNPACK_FBW 1 
+#define UNPACK_CPL 2 
+#define UNPACK_LFE 4
+
+static __inline__ int exp_unpack_ch (ac3dec_t * p_ac3dec, u16 type,
+                                     u16 expstr, u16 ngrps, u16 initial_exp,
+                                     u16 exps[], u16 * dest)
+{
+    u16 i,j;
+    s16 exp_acc;
+
+    if  (expstr == EXP_REUSE)
+    {
+        return 0;
+    }
+
+    /* Handle the initial absolute exponent */
+    exp_acc = initial_exp;
+    j = 0;
+
+    /* In the case of a fbw channel then the initial absolute values is
+     * also an exponent */
+    if (type != UNPACK_CPL)
+    {
+        dest[j++] = exp_acc;
+    }
+
+    /* Loop through the groups and fill the dest array appropriately */
+    switch (expstr)
+    {
+    case EXP_D15:        /* 1 */
+        for (i = 0; i < ngrps; i++)
+        {
+            if (exps[i] > 124)
+            {
+                intf_ErrMsg ( "ac3dec error: invalid exponent" );
+                return 1;
+            }
+            exp_acc += (exps_1[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            exp_acc += (exps_2[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            exp_acc += (exps_3[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+        }
+        break;
+
+    case EXP_D25:        /* 2 */
+        for (i = 0; i < ngrps; i++)
+        {
+            if (exps[i] > 124)
+            {
+                intf_ErrMsg ( "ac3dec error: invalid exponent" );
+                return 1;
+            }
+            exp_acc += (exps_1[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            exp_acc += (exps_2[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            exp_acc += (exps_3[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+        }
+        break;
+
+    case EXP_D45:        /* 3 */
+        for (i = 0; i < ngrps; i++)
+        {
+            if (exps[i] > 124)
+            {
+                intf_ErrMsg ( "ac3dec error: invalid exponent" );
+                return 1;
+            }
+            exp_acc += (exps_1[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            exp_acc += (exps_2[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            exp_acc += (exps_3[exps[i]] /*- 2*/);
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+            dest[j++] = exp_acc;
+        }
+        break;
+    }
+
+    return 0;
 }
 
-void exponent_unpack( ac3dec_thread_t * p_ac3dec )
+int exponent_unpack (ac3dec_t * p_ac3dec)
 {
-       u16 i;
-
-       for(i=0; i< p_ac3dec->bsi.nfchans; i++)
-               exp_unpack_ch(UNPACK_FBW, p_ac3dec->audblk.chexpstr[i], p_ac3dec->audblk.nchgrps[i], p_ac3dec->audblk.exps[i][0],
-                               &p_ac3dec->audblk.exps[i][1], p_ac3dec->audblk.fbw_exp[i]);
-
-       if(p_ac3dec->audblk.cplinu)
-               exp_unpack_ch(UNPACK_CPL, p_ac3dec->audblk.cplexpstr, p_ac3dec->audblk.ncplgrps, p_ac3dec->audblk.cplabsexp << 1,
-                               p_ac3dec->audblk.cplexps, &p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant]);
-
-       if(p_ac3dec->bsi.lfeon)
-               exp_unpack_ch(UNPACK_LFE, p_ac3dec->audblk.lfeexpstr, 2, p_ac3dec->audblk.lfeexps[0],
-                               &p_ac3dec->audblk.lfeexps[1], p_ac3dec->audblk.lfe_exp);
+    u16 i;
+
+    for (i = 0; i < p_ac3dec->bsi.nfchans; i++)
+    {
+        if (exp_unpack_ch (p_ac3dec, UNPACK_FBW, p_ac3dec->audblk.chexpstr[i],
+                           p_ac3dec->audblk.nchgrps[i],
+                           p_ac3dec->audblk.exps[i][0],
+                           &p_ac3dec->audblk.exps[i][1],
+                           p_ac3dec->audblk.fbw_exp[i]))
+        {
+            return 1;
+        }
+    }
+
+    if (p_ac3dec->audblk.cplinu)
+    {
+        if (exp_unpack_ch (p_ac3dec, UNPACK_CPL, p_ac3dec->audblk.cplexpstr,
+                           p_ac3dec->audblk.ncplgrps,
+                           p_ac3dec->audblk.cplabsexp << 1,
+                           p_ac3dec->audblk.cplexps,
+                           &p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant]))
+        {
+            return 1;
+        }
+    }
+
+    if (p_ac3dec->bsi.lfeon)
+    {
+        if (exp_unpack_ch (p_ac3dec, UNPACK_LFE, p_ac3dec->audblk.lfeexpstr,
+                           2, p_ac3dec->audblk.lfeexps[0],
+                           &p_ac3dec->audblk.lfeexps[1],
+                           p_ac3dec->audblk.lfe_exp))
+        {
+            return 1;
+        }
+    }
+
+    return 0;
 }
+