ac3_rematrix.c 2.77 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * ac3_rematrix.c: ac3 audio rematrixing
 *****************************************************************************
 * Copyright (C) 1999, 2000 VideoLAN
Henri Fallon's avatar
 
Henri Fallon committed
5
 * $Id: ac3_rematrix.c,v 1.1 2001/11/13 12:09:17 henri Exp $
6
 *
7 8
 * Authors: Michel Kaempf <maxx@via.ecp.fr>
 *          Aaron Holtzman <aholtzma@engr.uvic.ca>
9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
14
 * 
15 16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
19
 *
20 21 22
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
24 25 26 27

/*****************************************************************************
 * Preamble
 *****************************************************************************/
28
#include "defs.h"
29

Sam Hocevar's avatar
 
Sam Hocevar committed
30 31
#include <string.h>                                              /* memcpy() */

32 33 34 35 36 37 38 39
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"

#include "stream_control.h"
#include "input_ext-dec.h"

Sam Hocevar's avatar
 
Sam Hocevar committed
40 41
#include "ac3_imdct.h"
#include "ac3_downmix.h"
42 43
#include "ac3_decoder.h"

Michel Lespinasse's avatar
 
Michel Lespinasse committed
44
struct rematrix_band_s {
45 46
    u32 start;
    u32 end;
47 48
};

49
static const struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
50

Sam Hocevar's avatar
 
Sam Hocevar committed
51
static __inline__ u32 min_value (u32 a, u32 b)
52
{
Michel Lespinasse's avatar
 
Michel Lespinasse committed
53
    return (a < b ? a : b);
54 55
}

56
/* This routine simply does stereo rematixing for the 2 channel
57
 * stereo mode */
Michel Lespinasse's avatar
 
Michel Lespinasse committed
58
void rematrix (ac3dec_t * p_ac3dec)
59
{
60 61 62 63 64
    u32 num_bands;
    u32 start;
    u32 end;
    u32 i,j;
    float left,right;
65

Michel Lespinasse's avatar
 
Michel Lespinasse committed
66
    if (p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2)
67 68 69 70 71
        num_bands = 4;
    else if (p_ac3dec->audblk.cplbegf > 0)
        num_bands = 3;
    else
        num_bands = 2;
72

Michel Lespinasse's avatar
 
Michel Lespinasse committed
73 74
    for (i=0;i < num_bands; i++) {
        if (!p_ac3dec->audblk.rematflg[i])
75
            continue;
76

77
        start = rematrix_band[i].start;
Sam Hocevar's avatar
 
Sam Hocevar committed
78
        end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
79

Michel Lespinasse's avatar
 
Michel Lespinasse committed
80
        for (j=start;j < end; j++) {
81 82 83 84
            left  = 0.5f * ( *(p_ac3dec->samples+j) + *(p_ac3dec->samples+256+j) );
            right = 0.5f * ( *(p_ac3dec->samples+j) - *(p_ac3dec->samples+256+j) );
            *(p_ac3dec->samples+j) = left;
            *(p_ac3dec->samples+256+j) = right;
85 86
        }
    }
87
}
Sam Hocevar's avatar
 
Sam Hocevar committed
88