]> git.sesse.net Git - vlc/blob - modules/codec/a52old/decoder.c
* ./include/vlc_common.h, ./src/extras/libc.c: exported our custom libc
[vlc] / modules / codec / a52old / decoder.c
1 /*****************************************************************************
2  * decoder.c: core A52 decoder
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: decoder.c,v 1.1 2002/08/04 17:23:42 sam Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *          Michel Lespinasse <walken@zoy.org>
9  *          Aaron Holtzman <aholtzma@engr.uvic.ca>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <string.h>                                              /* memcpy() */
30
31 #include <vlc/vlc.h>
32 #include <vlc/decoder.h>
33
34 #include "imdct.h"
35 #include "downmix.h"
36 #include "adec.h"                                         /* a52dec_thread_t */
37
38 #include "internal.h"
39
40 static const float cmixlev_lut[4] = { 0.707, 0.595, 0.500, 0.707 };
41 static const float smixlev_lut[4] = { 0.707, 0.500, 0.0  , 0.500 };
42
43 int E_( a52_init )(a52dec_t * p_a52dec)
44 {
45     p_a52dec->mantissa.lfsr_state = 1;          /* dither_gen initialization */
46     E_( imdct_init )(p_a52dec->p_imdct) ;
47     
48     return 0;
49 }
50
51 int decode_frame (a52dec_t * p_a52dec, s16 * buffer)
52 {
53     int i;
54     
55     if (parse_bsi (p_a52dec))
56     {
57         msg_Warn( p_a52dec->p_fifo, "parse error" );
58         parse_auxdata (p_a52dec);
59         return 1;
60     }
61     
62     /* compute downmix parameters
63      * downmix to tow channels for now */
64     p_a52dec->dm_par.clev = 0.0;
65     p_a52dec->dm_par.slev = 0.0; 
66     p_a52dec->dm_par.unit = 1.0;
67     if (p_a52dec->bsi.acmod & 0x1)    /* have center */
68         p_a52dec->dm_par.clev = cmixlev_lut[p_a52dec->bsi.cmixlev];
69
70     if (p_a52dec->bsi.acmod & 0x4)    /* have surround channels */
71         p_a52dec->dm_par.slev = smixlev_lut[p_a52dec->bsi.surmixlev];
72
73     p_a52dec->dm_par.unit /= 1.0 + p_a52dec->dm_par.clev + p_a52dec->dm_par.slev;
74     p_a52dec->dm_par.clev *= p_a52dec->dm_par.unit;
75     p_a52dec->dm_par.slev *= p_a52dec->dm_par.unit;
76
77     for (i = 0; i < 6; i++) {
78         /* Initialize freq/time sample storage */
79         memset(p_a52dec->samples, 0, sizeof(float) * 256 * 
80                 (p_a52dec->bsi.nfchans + p_a52dec->bsi.lfeon));
81
82
83         if( p_a52dec->p_fifo->b_die || p_a52dec->p_fifo->b_error )
84         {        
85             return 1;
86         }
87  
88         if( parse_audblk( p_a52dec, i ) )
89         {
90             msg_Warn( p_a52dec->p_fifo, "audioblock error" );
91             parse_auxdata( p_a52dec );
92             return 1;
93         }
94
95         if( p_a52dec->p_fifo->b_die || p_a52dec->p_fifo->b_error )
96         {        
97             return 1;
98         }
99
100         if( exponent_unpack( p_a52dec ) )
101         {
102             msg_Warn( p_a52dec->p_fifo, "unpack error" );
103             parse_auxdata( p_a52dec );
104             return 1;
105         }
106
107         bit_allocate (p_a52dec);
108         mantissa_unpack (p_a52dec);
109
110         if( p_a52dec->p_fifo->b_die || p_a52dec->p_fifo->b_error )
111         {        
112             return 1;
113         }
114         
115         if  (p_a52dec->bsi.acmod == 0x2)
116         {
117             rematrix (p_a52dec);
118         }
119
120         imdct (p_a52dec, buffer);
121
122         buffer += 2 * 256;
123     }
124
125     parse_auxdata (p_a52dec);
126
127     return 0;
128 }
129