swift
src
sound
dsp
SimpleGain.h
1
/*
2
* Gain Functions (header)
3
*
4
* File : SimpleGain.h
5
* Library : SimpleSource
6
* Version : 1.12
7
* Class :
8
*
9
* 2006, ChunkWare Music Software, OPEN-SOURCE
10
*
11
* Permission is hereby granted, free of charge, to any person obtaining a
12
* copy of this software and associated documentation files (the "Software"),
13
* to deal in the Software without restriction, including without limitation
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
* and/or sell copies of the Software, and to permit persons to whom the
16
* Software is furnished to do so, subject to the following conditions:
17
*
18
* The above copyright notice and this permission notice shall be included in
19
* all copies or substantial portions of the Software.
20
*
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
* DEALINGS IN THE SOFTWARE.
28
*/
29
30
31
#ifndef __SIMPLE_GAIN_H__
32
#define __SIMPLE_GAIN_H__
33
34
#include "SimpleHeader.h"
// common header
35
36
namespace
chunkware_simple
37
{
38
//-------------------------------------------------------------
39
// gain functions
40
//-------------------------------------------------------------
41
42
// linear -> dB conversion
43
static
INLINE
double
lin2dB(
double
lin ) {
44
static
const
double
LOG_2_DB = 8.6858896380650365530225783783321;
// 20 / ln( 10 )
45
return
log( lin ) * LOG_2_DB;
46
}
47
48
// dB -> linear conversion
49
static
INLINE
double
dB2lin(
double
dB ) {
50
static
const
double
DB_2_LOG = 0.11512925464970228420089957273422;
// ln( 10 ) / 20
51
return
exp( dB * DB_2_LOG );
52
}
53
54
}
// end namespace chunkware_simple
55
56
#endif
// end __SIMPLE_GAIN_H__
Generated on Mon Mar 24 2025 16:42:23 for swift by
1.9.1