]> git.sesse.net Git - vlc/blob - plugins/downmix/ac3_downmix_c.c
Some heavy changes today:
[vlc] / plugins / downmix / ac3_downmix_c.c
1 /*****************************************************************************
2  * ac3_downmix_c.c: ac3 downmix functions in C
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: ac3_downmix_c.c,v 1.4 2001/12/30 07:09:54 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 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <string.h>                                              /* memcpy() */
29
30 #include <videolan/vlc.h>
31
32 #include "ac3_downmix.h"
33
34 void _M( downmix_3f_2r_to_2ch ) (float *samples, dm_par_t *dm_par)
35 {
36     int i;
37     float *left, *right, *center, *left_sur, *right_sur;
38     float left_tmp, right_tmp;
39     
40     left      = samples;
41     center    = samples + 256;
42     right     = samples + 256*2;
43     left_sur  = samples + 256*3;
44     right_sur = samples + 256*4;
45
46     for (i=0; i < 256; i++) {
47         left_tmp = dm_par->unit * *left + dm_par->clev * *center + dm_par->slev * *left_sur++;
48         right_tmp = dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
49         *left++ = left_tmp;
50         *center++ = right_tmp;
51     }
52 }
53
54 void _M( downmix_2f_2r_to_2ch ) (float *samples, dm_par_t *dm_par)
55 {
56     int i;
57     float *left, *right, *left_sur, *right_sur;
58     float left_tmp, right_tmp;
59                
60     left = &samples[0];
61     right = &samples[256];
62     left_sur = &samples[512];
63     right_sur = &samples[768];
64
65     for (i = 0; i < 256; i++) {
66         left_tmp = dm_par->unit * *left  + dm_par->slev * *left_sur++;
67         right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
68         *left++ = left_tmp;
69         *right++ = right_tmp;
70     }
71 }
72
73 void _M( downmix_3f_1r_to_2ch ) (float *samples, dm_par_t *dm_par)
74 {
75     int i;
76     float *left, *right, *center, *right_sur;
77     float left_tmp, right_tmp;
78
79     left = &samples[0];
80     right = &samples[512];
81     center = &samples[256];
82     right_sur = &samples[768];
83
84     for (i = 0; i < 256; i++) {
85         left_tmp = dm_par->unit * *left  + dm_par->clev * *center  - dm_par->slev * *right_sur;
86         right_tmp= dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
87         *left++ = left_tmp;
88         *center++ = right_tmp;
89     }
90 }
91
92
93 void _M( downmix_2f_1r_to_2ch ) (float *samples, dm_par_t *dm_par)
94 {
95     int i;
96     float *left, *right, *right_sur;
97     float left_tmp, right_tmp;
98
99     left = &samples[0];
100     right = &samples[256];
101     right_sur = &samples[512];
102
103     for (i = 0; i < 256; i++) {
104         left_tmp = dm_par->unit * *left  - dm_par->slev * *right_sur;
105         right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
106         *left++ = left_tmp;
107         *right++ = right_tmp;
108     }
109 }
110
111
112 void _M( downmix_3f_0r_to_2ch ) (float *samples, dm_par_t *dm_par)
113 {
114     int i;
115     float *left, *right, *center;
116     float left_tmp, right_tmp;
117
118     left = &samples[0];
119     center = &samples[256];
120     right = &samples[512];
121
122     for (i = 0; i < 256; i++) {
123         left_tmp = dm_par->unit * *left  + dm_par->clev * *center;
124         right_tmp= dm_par->unit * *right++ + dm_par->clev * *center;
125         *left++ = left_tmp;
126         *center++ = right_tmp;
127     }
128 }
129
130
131 void _M( stream_sample_2ch_to_s16 ) (s16 *out_buf, float *left, float *right)
132 {
133     int i;
134     for (i=0; i < 256; i++) {
135         *out_buf++ = (s16) (*left++);
136         *out_buf++ = (s16) (*right++);
137     }
138 }
139
140
141 void _M( stream_sample_1ch_to_s16 ) (s16 *out_buf, float *center)
142 {
143     int i;
144     float tmp;
145
146     for (i=0; i < 256; i++) {
147         *out_buf++ = tmp = (s16) (0.7071f * *center++);
148         *out_buf++ = tmp;
149     }
150 }
151