1 /***************************************************************************
2 * Copyright (C) 2011 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 a VU meter implementation
23 ****************************************************************************/
24
25 #include "vu.h"
26 //#include <stdio.h>
27 #include <stdlib.h>
28
29 //Constant to dBu conversion is sqrt(2)
30 #define CONSTANT_VU 1.4142136
31
32 //Initialize the VU meter
VuInit(double rate)33 Vu *VuInit(double rate)
34 {
35 Vu *vu = (Vu *)malloc(sizeof(Vu));
36
37 vu->vu_value = 0.0;
38 vu->vu_max = 0.0;
39
40 vu->m_min = (1.0 / 256);
41 vu->m_decay = exp( -1.0 / rate);
42
43 return vu;
44 }
45
46 //Destroy a Vu instance
VuClean(Vu * vu)47 void VuClean(Vu *vu){
48 free(vu);
49 }
50