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.2 2001/11/28 15:08:05 massiot 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() */
38
#include "ac3_downmix.h"
40
void _M( downmix_3f_2r_to_2ch ) (float *samples, dm_par_t *dm_par)
43
float *left, *right, *center, *left_sur, *right_sur;
44
float left_tmp, right_tmp;
47
center = samples + 256;
48
right = samples + 256*2;
49
left_sur = samples + 256*3;
50
right_sur = samples + 256*4;
52
for (i=0; i < 256; i++) {
53
left_tmp = dm_par->unit * *left + dm_par->clev * *center + dm_par->slev * *left_sur++;
54
right_tmp = dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
56
*center++ = right_tmp;
60
void _M( downmix_2f_2r_to_2ch ) (float *samples, dm_par_t *dm_par)
63
float *left, *right, *left_sur, *right_sur;
64
float left_tmp, right_tmp;
67
right = &samples[256];
68
left_sur = &samples[512];
69
right_sur = &samples[768];
71
for (i = 0; i < 256; i++) {
72
left_tmp = dm_par->unit * *left + dm_par->slev * *left_sur++;
73
right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
79
void _M( downmix_3f_1r_to_2ch ) (float *samples, dm_par_t *dm_par)
82
float *left, *right, *center, *right_sur;
83
float left_tmp, right_tmp;
86
right = &samples[512];
87
center = &samples[256];
88
right_sur = &samples[768];
90
for (i = 0; i < 256; i++) {
91
left_tmp = dm_par->unit * *left + dm_par->clev * *center - dm_par->slev * *right_sur;
92
right_tmp= dm_par->unit * *right++ + dm_par->clev * *center + dm_par->slev * *right_sur++;
94
*center++ = right_tmp;
99
void _M( downmix_2f_1r_to_2ch ) (float *samples, dm_par_t *dm_par)
102
float *left, *right, *right_sur;
103
float left_tmp, right_tmp;
106
right = &samples[256];
107
right_sur = &samples[512];
109
for (i = 0; i < 256; i++) {
110
left_tmp = dm_par->unit * *left - dm_par->slev * *right_sur;
111
right_tmp= dm_par->unit * *right + dm_par->slev * *right_sur++;
113
*right++ = right_tmp;
118
void _M( downmix_3f_0r_to_2ch ) (float *samples, dm_par_t *dm_par)
121
float *left, *right, *center;
122
float left_tmp, right_tmp;
125
center = &samples[256];
126
right = &samples[512];
128
for (i = 0; i < 256; i++) {
129
left_tmp = dm_par->unit * *left + dm_par->clev * *center;
130
right_tmp= dm_par->unit * *right++ + dm_par->clev * *center;
132
*center++ = right_tmp;
137
void _M( stream_sample_2ch_to_s16 ) (s16 *out_buf, float *left, float *right)
140
for (i=0; i < 256; i++) {
141
*out_buf++ = (s16) (*left++);
142
*out_buf++ = (s16) (*right++);
147
void _M( stream_sample_1ch_to_s16 ) (s16 *out_buf, float *center)
152
for (i=0; i < 256; i++) {
153
*out_buf++ = tmp = (s16) (0.7071f * *center++);