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.3 2001/12/09 17:01:36 sam Exp $
7 * Authors: Renaud Dartus <reno@videolan.org>
8 * Aaron Holtzman <aholtzma@engr.uvic.ca>
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.
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.
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 *****************************************************************************/
25 #define MODULE_NAME downmix
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
33 #include <string.h> /* memcpy() */
37 #include "ac3_downmix.h"
39 void _M( downmix_3f_2r_to_2ch ) (float *samples, dm_par_t *dm_par)
42 float *left, *right, *center, *left_sur, *right_sur;
43 float left_tmp, right_tmp;
46 center = samples + 256;
47 right = samples + 256*2;
48 left_sur = samples + 256*3;
49 right_sur = samples + 256*4;
51 for (i=0; i < 256; i++) {
52 left_tmp = dm_par->unit * *left + dm_par->clev * *center + dm_par->slev * *left_sur++;
53 right_tmp = dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
55 *center++ = right_tmp;
59 void _M( downmix_2f_2r_to_2ch ) (float *samples, dm_par_t *dm_par)
62 float *left, *right, *left_sur, *right_sur;
63 float left_tmp, right_tmp;
66 right = &samples[256];
67 left_sur = &samples[512];
68 right_sur = &samples[768];
70 for (i = 0; i < 256; i++) {
71 left_tmp = dm_par->unit * *left + dm_par->slev * *left_sur++;
72 right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
78 void _M( downmix_3f_1r_to_2ch ) (float *samples, dm_par_t *dm_par)
81 float *left, *right, *center, *right_sur;
82 float left_tmp, right_tmp;
85 right = &samples[512];
86 center = &samples[256];
87 right_sur = &samples[768];
89 for (i = 0; i < 256; i++) {
90 left_tmp = dm_par->unit * *left + dm_par->clev * *center - dm_par->slev * *right_sur;
91 right_tmp= dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
93 *center++ = right_tmp;
98 void _M( downmix_2f_1r_to_2ch ) (float *samples, dm_par_t *dm_par)
101 float *left, *right, *right_sur;
102 float left_tmp, right_tmp;
105 right = &samples[256];
106 right_sur = &samples[512];
108 for (i = 0; i < 256; i++) {
109 left_tmp = dm_par->unit * *left - dm_par->slev * *right_sur;
110 right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
112 *right++ = right_tmp;
117 void _M( downmix_3f_0r_to_2ch ) (float *samples, dm_par_t *dm_par)
120 float *left, *right, *center;
121 float left_tmp, right_tmp;
124 center = &samples[256];
125 right = &samples[512];
127 for (i = 0; i < 256; i++) {
128 left_tmp = dm_par->unit * *left + dm_par->clev * *center;
129 right_tmp= dm_par->unit * *right++ + dm_par->clev * *center;
131 *center++ = right_tmp;
136 void _M( stream_sample_2ch_to_s16 ) (s16 *out_buf, float *left, float *right)
139 for (i=0; i < 256; i++) {
140 *out_buf++ = (s16) (*left++);
141 *out_buf++ = (s16) (*right++);
146 void _M( stream_sample_1ch_to_s16 ) (s16 *out_buf, float *center)
151 for (i=0; i < 256; i++) {
152 *out_buf++ = tmp = (s16) (0.7071f * *center++);