]> git.sesse.net Git - vlc/blob - src/ac3_decoder/ac3_downmix_c.c
* Header cleaning: filled all empty authors fields, added CVS $Id stuff.
[vlc] / src / ac3_decoder / ac3_downmix_c.c
1 /*****************************************************************************
2  * ac3_downmix_c.c: ac3 downmix functions
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: ac3_downmix_c.c,v 1.3 2001/03/21 13:42:34 sam Exp $
6  *
7  * Authors: Renaud Dartus <reno@videolan.org>
8  *          Aaron Holtzman <aholtzma@engr.uvic.ca>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #include "defs.h"
26
27 #include "int_types.h"
28
29 #include "ac3_decoder.h"
30 #include "ac3_internal.h"
31
32 #include "ac3_downmix.h"
33 void __inline__ downmix_3f_2r_to_2ch_c (float *samples, dm_par_t *dm_par)
34 {
35         int i;
36         float *left, *right, *center, *left_sur, *right_sur;
37         float left_tmp, right_tmp;
38     
39     left      = samples;
40     center    = samples + 256;
41     right     = samples + 256*2;
42     left_sur  = samples + 256*3;
43     right_sur = samples + 256*4;
44
45         for (i=0; i < 256; i++) {
46         left_tmp = dm_par->unit * *left + dm_par->clev * *center + dm_par->slev * *left_sur++;
47         right_tmp = dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
48                 *left++ = left_tmp;
49                 *center++ = right_tmp;
50         }
51 }
52
53 void __inline__ downmix_2f_2r_to_2ch_c (float *samples, dm_par_t *dm_par)
54 {
55         int i;
56         float *left, *right, *left_sur, *right_sur;
57         float left_tmp, right_tmp;
58                
59         left = &samples[0];
60         right = &samples[256];
61         left_sur = &samples[512];
62         right_sur = &samples[768];
63
64         for (i = 0; i < 256; i++) {
65                 left_tmp = dm_par->unit * *left  + dm_par->slev * *left_sur++;
66                 right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
67                 *left++ = left_tmp;
68                 *right++ = right_tmp;
69         }
70 }
71
72 void __inline__ downmix_3f_1r_to_2ch_c (float *samples, dm_par_t *dm_par)
73 {
74         int i;
75         float *left, *right, *center, *right_sur;
76         float left_tmp, right_tmp;
77
78         left = &samples[0];
79         right = &samples[512];
80         center = &samples[256];
81         right_sur = &samples[768];
82
83         for (i = 0; i < 256; i++) {
84                 left_tmp = dm_par->unit * *left  + dm_par->clev * *center  - dm_par->slev * *right_sur;
85                 right_tmp= dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
86                 *left++ = left_tmp;
87                 *center++ = right_tmp;
88         }
89 }
90
91
92 void __inline__ downmix_2f_1r_to_2ch_c (float *samples, dm_par_t *dm_par)
93 {
94         int i;
95         float *left, *right, *right_sur;
96         float left_tmp, right_tmp;
97
98         left = &samples[0];
99         right = &samples[256];
100         right_sur = &samples[512];
101
102         for (i = 0; i < 256; i++) {
103                 left_tmp = dm_par->unit * *left  - dm_par->slev * *right_sur;
104                 right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
105                 *left++ = left_tmp;
106                 *right++ = right_tmp;
107         }
108 }
109
110
111 void __inline__ downmix_3f_0r_to_2ch_c (float *samples, dm_par_t *dm_par)
112 {
113         int i;
114         float *left, *right, *center;
115         float left_tmp, right_tmp;
116
117         left = &samples[0];
118         center = &samples[256];
119         right = &samples[512];
120
121         for (i = 0; i < 256; i++) {
122                 left_tmp = dm_par->unit * *left  + dm_par->clev * *center;
123                 right_tmp= dm_par->unit * *right++ + dm_par->clev * *center;
124                 *left++ = left_tmp;
125                 *center++ = right_tmp;
126         }
127 }
128
129
130 void __inline__ stream_sample_2ch_to_s16_c (s16 *out_buf, float *left, float *right)
131 {
132         int i;
133         for (i=0; i < 256; i++) {
134                 *out_buf++ = (s16) (*left++  * NORM);
135                 *out_buf++ = (s16) (*right++ * NORM);
136         }
137 }
138
139
140 void __inline__ stream_sample_1ch_to_s16_c (s16 *out_buf, float *center)
141 {
142         int i;
143         float tmp;
144
145         for (i=0; i < 256; i++) {
146                 *out_buf++ = tmp = (s16) (0.7071f * *center++ * NORM);
147                 *out_buf++ = tmp;
148         }
149 }