]> git.sesse.net Git - vlc/blob - src/ac3_decoder/ac3_exponent.c
* Modification de l'input afin de spawner un d�codeur ac3 lorsqu'un tel flux
[vlc] / src / ac3_decoder / ac3_exponent.c
1 #include <unistd.h>                                              /* getpid() */
2
3 #include <stdio.h>                                           /* "intf_msg.h" */
4 #include <stdlib.h>                                      /* malloc(), free() */
5 #include <sys/soundcard.h>                               /* "audio_output.h" */
6 #include <sys/uio.h>                                            /* "input.h" */
7
8 #include "common.h"
9 #include "config.h"
10 #include "mtime.h"
11 #include "vlc_thread.h"
12 #include "debug.h"                                      /* "input_netlist.h" */
13
14 #include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
15
16 #include "input.h"                                           /* pes_packet_t */
17 #include "input_netlist.h"                         /* input_NetlistFreePES() */
18 #include "decoder_fifo.h"         /* DECODER_FIFO_(ISEMPTY|START|INCSTART)() */
19
20 #include "audio_output.h"
21
22 #include "ac3_decoder.h"
23 #include "ac3_exponent.h"
24
25 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 };
26 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 };
27 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 };
28
29 static __inline__ void exp_unpack_ch( u16 type, u16 expstr, u16 ngrps, u16 initial_exp, u16 exps[], u16 * dest )
30 {
31         u16 i,j;
32         s16 exp_acc;
33         /*
34         s16 exp_1,exp_2,exp_3;
35         */
36
37         if(expstr == EXP_REUSE)
38                 return;
39
40         /* Handle the initial absolute exponent */
41         exp_acc = initial_exp;
42         j = 0;
43
44         /* In the case of a fbw channel then the initial absolute values is 
45          * also an exponent */
46         if(type != UNPACK_CPL)
47                 dest[j++] = exp_acc;
48
49         /* Loop through the groups and fill the dest array appropriately */
50         for ( i = 0; i < ngrps; i++ )
51         {
52                 /*
53                 if ( exps[i] > 124 )
54                 {
55                         //FIXME set an error flag and mute the frame
56                         printf( "\n!! Invalid exponent !!\n" );
57                         exit( 1 );
58                 }
59                 */
60
61                 /*
62                 exp_1 = exps[i] / 25;
63                 exp_2 = (exps[i] - (exp_1 * 25)) / 5;
64                 exp_3 = exps[i] - (exp_1 * 25) - (exp_2 * 5) ;
65                 */
66
67                 switch ( expstr )
68                 {
69                         case EXP_D45:
70                                 exp_acc += (exps_1[exps[i]] - 2);
71                                 dest[j++] = exp_acc;
72                                 dest[j++] = exp_acc;
73                                 dest[j++] = exp_acc;
74                                 dest[j++] = exp_acc;
75                                 exp_acc += (exps_2[exps[i]] - 2);
76                                 dest[j++] = exp_acc;
77                                 dest[j++] = exp_acc;
78                                 dest[j++] = exp_acc;
79                                 dest[j++] = exp_acc;
80                                 exp_acc += (exps_3[exps[i]] - 2);
81                                 dest[j++] = exp_acc;
82                                 dest[j++] = exp_acc;
83                                 dest[j++] = exp_acc;
84                                 dest[j++] = exp_acc;
85                         break;
86
87                         case EXP_D25:
88                                 exp_acc += (exps_1[exps[i]] - 2);
89                                 dest[j++] = exp_acc;
90                                 dest[j++] = exp_acc;
91                                 exp_acc += (exps_2[exps[i]] - 2);
92                                 dest[j++] = exp_acc;
93                                 dest[j++] = exp_acc;
94                                 exp_acc += (exps_3[exps[i]] - 2);
95                                 dest[j++] = exp_acc;
96                                 dest[j++] = exp_acc;
97                         break;
98
99                         case EXP_D15:
100                                 exp_acc += (exps_1[exps[i]] - 2);
101                                 dest[j++] = exp_acc;
102                                 exp_acc += (exps_2[exps[i]] - 2);
103                                 dest[j++] = exp_acc;
104                                 exp_acc += (exps_3[exps[i]] - 2);
105                                 dest[j++] = exp_acc;
106                         break;
107                 }
108         }
109 }
110
111 void exponent_unpack( ac3dec_thread_t * p_ac3dec )
112 {
113         u16 i;
114
115         for(i=0; i< p_ac3dec->bsi.nfchans; i++)
116                 exp_unpack_ch(UNPACK_FBW, p_ac3dec->audblk.chexpstr[i], p_ac3dec->audblk.nchgrps[i], p_ac3dec->audblk.exps[i][0],
117                                 &p_ac3dec->audblk.exps[i][1], p_ac3dec->audblk.fbw_exp[i]);
118
119         if(p_ac3dec->audblk.cplinu)
120                 exp_unpack_ch(UNPACK_CPL, p_ac3dec->audblk.cplexpstr, p_ac3dec->audblk.ncplgrps, p_ac3dec->audblk.cplabsexp << 1,
121                                 p_ac3dec->audblk.cplexps, &p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant]);
122
123         if(p_ac3dec->bsi.lfeon)
124                 exp_unpack_ch(UNPACK_LFE, p_ac3dec->audblk.lfeexpstr, 2, p_ac3dec->audblk.lfeexps[0],
125                                 &p_ac3dec->audblk.lfeexps[1], p_ac3dec->audblk.lfe_exp);
126 }