2
Copyright ( C ) 2003 Arnold Krille <arnold@arnoldarts.de>
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.
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.
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.
21
#ifndef ARTS_DB2VOL_CALC_H
22
#define ARTS_DB2VOL_CALC_H
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))
38
Logarithmic/decimal valuation:
39
p = ampfactor ( linear )
40
db = dezibel ( logarithmic )
45
db = 6/ln( 2 ) * ln( p )
47
db = 6/lg( 2 ) * lg( p )
49
float amptodb( float p ) {
50
float db = _base*log10( p );
51
if ( db < dbmin ) db = dbmin;
52
if ( db > dbmax ) db = dbmax;
55
float dbtoamp( float db ) {
56
float amp = pow( 10, db/_base );
57
if ( amp <= pow( 10, dbmin/_base ) ) amp = 0;
60
/// With ndb = normalized dB (between 0 and 1)
61
float amptondb( float p ) {
62
return dbtondb( amptodb( p ) ); //- dbmin ) / ( dbmax - dbmin );
64
float ndbtoamp( float ndb ) {
65
return dbtoamp( ndb * ( dbmax - dbmin ) + dbmin );
67
/// Normalizes a dezibel value.
68
float dbtondb( float db ) {
69
return ( db - dbmin )/( dbmax - dbmin );
71
/// Normalizes a volume to a logarithmic value between 0 and 1.
72
float dbtovol( float db ) {
73
return ( db -dbmin )/( 0-dbmin );
75
/// Unnormalizes a dezibel value.
76
float ndbtodb( float ndb ) {
77
return ( ndb * ( dbmax-dbmin ) +dbmin );