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 $
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 *****************************************************************************/
27 #include "int_types.h"
29 #include "ac3_decoder.h"
30 #include "ac3_internal.h"
32 #include "ac3_downmix.h"
33 void __inline__ downmix_3f_2r_to_2ch_c (float *samples, dm_par_t *dm_par)
36 float *left, *right, *center, *left_sur, *right_sur;
37 float left_tmp, right_tmp;
40 center = samples + 256;
41 right = samples + 256*2;
42 left_sur = samples + 256*3;
43 right_sur = samples + 256*4;
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++;
49 *center++ = right_tmp;
53 void __inline__ downmix_2f_2r_to_2ch_c (float *samples, dm_par_t *dm_par)
56 float *left, *right, *left_sur, *right_sur;
57 float left_tmp, right_tmp;
60 right = &samples[256];
61 left_sur = &samples[512];
62 right_sur = &samples[768];
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++;
72 void __inline__ downmix_3f_1r_to_2ch_c (float *samples, dm_par_t *dm_par)
75 float *left, *right, *center, *right_sur;
76 float left_tmp, right_tmp;
79 right = &samples[512];
80 center = &samples[256];
81 right_sur = &samples[768];
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++;
87 *center++ = right_tmp;
92 void __inline__ downmix_2f_1r_to_2ch_c (float *samples, dm_par_t *dm_par)
95 float *left, *right, *right_sur;
96 float left_tmp, right_tmp;
99 right = &samples[256];
100 right_sur = &samples[512];
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++;
106 *right++ = right_tmp;
111 void __inline__ downmix_3f_0r_to_2ch_c (float *samples, dm_par_t *dm_par)
114 float *left, *right, *center;
115 float left_tmp, right_tmp;
118 center = &samples[256];
119 right = &samples[512];
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;
125 *center++ = right_tmp;
130 void __inline__ stream_sample_2ch_to_s16_c (s16 *out_buf, float *left, float *right)
133 for (i=0; i < 256; i++) {
134 *out_buf++ = (s16) (*left++ * NORM);
135 *out_buf++ = (s16) (*right++ * NORM);
140 void __inline__ stream_sample_1ch_to_s16_c (s16 *out_buf, float *center)
145 for (i=0; i < 256; i++) {
146 *out_buf++ = tmp = (s16) (0.7071f * *center++ * NORM);