~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to arts/gui/kde/dbvolcalc.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (  C ) 2003 Arnold Krille <arnold@arnoldarts.de>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Library General Public
 
6
    License as published by the Free Software Foundation;
 
7
    version 2 of the License.
 
8
 
 
9
    This library is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    Library General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to
 
16
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
    Boston, MA 02111-1307, USA.
 
18
 
 
19
*/
 
20
 
 
21
#ifndef ARTS_DB2VOL_CALC_H
 
22
#define ARTS_DB2VOL_CALC_H
 
23
 
 
24
#include <math.h>
 
25
 
 
26
class dB2VolCalc {
 
27
private:
 
28
        float _base;
 
29
public:
 
30
        dB2VolCalc( float _dbmin, float _dbmax )
 
31
          : _base( 6/log10( double(2) ) ) // Depends on what you measure: intensity(10), pressure(20), old artscontrol(6/lg2 (near 20))
 
32
          , dbmax( _dbmax )
 
33
          , dbmin( _dbmin )
 
34
        {}
 
35
 
 
36
        float dbmax, dbmin;
 
37
        /**
 
38
                Logarithmic/decimal valuation:
 
39
                p = ampfactor ( linear )
 
40
                db = dezibel ( logarithmic )
 
41
                p = 10^( d/10 )
 
42
                db = 10*lg( p )
 
43
 
 
44
                artscontrol was using
 
45
                        db = 6/ln( 2 ) * ln( p )
 
46
                which would be
 
47
                        db = 6/lg( 2 ) * lg( p )
 
48
        */
 
49
        float amptodb( float p ) {
 
50
                float db = _base*log10( p );
 
51
                if ( db < dbmin ) db = dbmin;
 
52
                if ( db > dbmax ) db = dbmax;
 
53
                return db;
 
54
        }
 
55
        float dbtoamp( float db ) {
 
56
                float amp = pow( 10, db/_base );
 
57
                if ( amp <= pow( 10, dbmin/_base ) ) amp = 0;
 
58
                return amp;
 
59
        }
 
60
        /// With ndb = normalized dB (between 0 and 1)
 
61
        float amptondb( float p ) {
 
62
                return  dbtondb( amptodb( p ) ); //- dbmin ) / ( dbmax - dbmin );
 
63
        }
 
64
        float ndbtoamp( float ndb ) {
 
65
                return dbtoamp( ndb * ( dbmax - dbmin ) + dbmin );
 
66
        }
 
67
        /// Normalizes a dezibel value.
 
68
        float dbtondb( float db ) {
 
69
                return ( db - dbmin )/( dbmax - dbmin );
 
70
        }
 
71
        /// Normalizes a volume to a logarithmic value between 0 and 1.
 
72
        float dbtovol( float db ) {
 
73
                return ( db -dbmin )/( 0-dbmin );
 
74
        }
 
75
        /// Unnormalizes a dezibel value.
 
76
        float ndbtodb( float ndb ) {
 
77
                return ( ndb * ( dbmax-dbmin ) +dbmin );
 
78
        }
 
79
};
 
80
 
 
81
#endif
 
82
// vim: sw=4 ts=4