1 /***************************************************************************
2  *   Copyright (C) 2012 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 the dB to linear convertion base on a LUT
23 ****************************************************************************/
24 
25 #ifndef _DB_2_LINEAR
26 #define  _DB_2_LINEAR
27 
28 #include "dblut.h"
29 
30 //Converts a value from dB to Linear 1 Linear = 0 dB
dB2Lin(float dbIn)31 static inline float dB2Lin(float dbIn)
32 {
33   int index = (int)(DB2LIN_M*dbIn + DB2LIN_N);
34   index = index > 0 ? index : 0;
35   index = index > LUT_TOP_INDEX ? LUT_TOP_INDEX : index;
36   return dB2Lin_LUT[index];
37 }
38 
39 //Converts a value from Linear to dB 1 Linear = 0 dB
Lin2dB(float LinIn)40 static inline float Lin2dB(float LinIn)
41 {
42   int index = (int)(LIN2DB_M*LinIn + LIN2DB_N);
43   index = index > 0 ? index : 0;
44   index = index > LUT_TOP_INDEX ? LUT_TOP_INDEX : index;
45   return Lin2dB_LUT[index];
46 }
47 
48 
49 #endif