1 /***************************************************************************
2  *   Copyright (C) 2015 by Pere Ràfols Soler                               *
3  *   sapista2@gmail.com                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 
21 /***************************************************************************
22 This file contains Mid/Side stereo signals convertion methods
23 ****************************************************************************/
24 
25 #ifndef  MIDSIDE_H
26   #define MIDSIDE_H
27 
28 #define MS_DUAL_CHANNEL 0
29 #define MS_L_MID_MODE 1
30 #define MS_R_SIDE_MODE 2
31 
32 //Converts a LR stereo signal to a mid/side signal. M is stored in L pointer and S in R pointer
LR2MS(double * inL_M,double * inR_S,double enable)33 inline void LR2MS(double *inL_M, double *inR_S, double enable)
34 {
35   double M = 0.5*(*inL_M + *inR_S);
36   double S = 0.5*(*inL_M - *inR_S);
37   *inL_M = enable*M + (1.0 - enable)*(*inL_M);
38   *inR_S = enable*S + (1.0 - enable)*(*inR_S);
39 }
40 
41 //Converts a M/S stereo signal to a LR signal. L is stored in M pointer and R in S pointer
MS2LR(double * inM_L,double * inS_R,double enable)42 inline void MS2LR(double *inM_L, double *inS_R, double enable)
43 {
44   double L = (*inM_L + *inS_R);
45   double R = (*inM_L - *inS_R);
46   *inM_L = enable*L + (1.0 - enable)*(*inM_L);
47   *inS_R = enable*R + (1.0 - enable)*(*inS_R);
48 }
49 
50 #endif