Library of Assembled Shared Sources
db.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43/** @defgroup dB
44 * @brief collection of conversion functions for dB
45 */
46
47#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_DB_H
48#define LASS_GUARDIAN_OF_INCLUSION_NUM_DB_H
49
50#include "num_common.h"
51#include "num_traits.h"
52
53#define LASS_NUM_DB_10_OVER_LN10 4.3429448190325182765112891891661
54#define LASS_NUM_DB_20_OVER_LN10 8.6858896380650365530225783783321
55#define LASS_NUM_DB_LN10_OVER_10 0.23025850929940456840179914546844
56#define LASS_NUM_DB_LN10_OVER_20 0.11512925464970228420089957273422
57
58namespace lass
59{
60 namespace num
61 {
62 /** power to decibels: y = 10 * log10(x)
63 * @ingroup dB
64 */
65 template <typename T> inline T pow2dB(const T& power)
66 {
67 return T(LASS_NUM_DB_10_OVER_LN10) * num::log(power);
68 }
69
70 /** amplitude to decibels: y = 20 * log10(x)
71 * @ingroup dB
72 */
73 template <typename T> inline T amp2dB(const T& amplitude)
74 {
75 return T(LASS_NUM_DB_20_OVER_LN10) * num::log(amplitude);
76 }
77
78 /** decibels to power: y = num::pow(10, x / 10)
79 * @ingroup dB
80 */
81 template <typename T> inline T dB2pow(const T& decibels)
82 {
83 return num::exp(T(LASS_NUM_DB_LN10_OVER_10) * decibels);
84 }
85
86 /** decibels to amplitude: y = num::pow(10, x / 20)
87 * @ingroup dB
88 */
89 template <typename T> inline T dB2amp(const T& decibels)
90 {
91 return num::exp(T(LASS_NUM_DB_LN10_OVER_20) * decibels);
92 }
93
94 /** Converts an absolute acoustical pressure into decibels.
95 * @ingroup dB
96 */
97 template< typename T > T p2dB( const T& iValue );
98
99 /** Converts a absolute acoustical power into decibels.
100 * @ingroup dB
101 */
102 template< typename T > T W2dB( const T& iValue );
103
104 /** Converts an intensity into decibels.
105 * @ingroup dB.
106 * The intensity represents the intensity in all directions expressed in Watts/m^2,
107 * referenced to 10^-12.
108 */
109 template< typename T > T I2dB( const T& iValue );
110
111 /** Converts decibels into a pressure .
112 * @ingroup dB
113 */
114 template< typename T > T dB2p( const T& iValue );
115
116 /** Converts decibels into a power.
117 * @ingroup dB
118 */
119 template< typename T > T dB2W( const T& iValue );
120
121 /** Converts decibels into an intensity.
122 * @ingroup dB
123 * The intensity represents the intensity in all directions expressed in Watts/m^2,
124 * referenced to 10^-12
125 */
126 template< typename T > T dB2I( const T& iValue );
127 }
128}
129
130#include "db.inl"
131
132#endif
T dB2W(const T &iValue)
Converts decibels into a power.
Definition db.inl:102
T pow2dB(const T &power)
power to decibels: y = 10 * log10(x)
Definition db.h:65
T dB2pow(const T &decibels)
decibels to power: y = num::pow(10, x / 10)
Definition db.h:81
T dB2p(const T &iValue)
Converts decibels into a pressure .
Definition db.inl:95
T dB2I(const T &iValue)
Converts decibels into an intensity.
Definition db.inl:109
T amp2dB(const T &amplitude)
amplitude to decibels: y = 20 * log10(x)
Definition db.h:73
T W2dB(const T &iValue)
Converts a absolute acoustical power into decibels.
Definition db.inl:69
T I2dB(const T &iValue)
Converts an intensity into decibels.
Definition db.inl:82
T p2dB(const T &iValue)
Converts an absolute acoustical pressure into decibels.
Definition db.inl:56
T dB2amp(const T &decibels)
decibels to amplitude: y = num::pow(10, x / 20)
Definition db.h:89
numeric types and traits.
Definition basic_ops.h:70
Library for Assembled Shared Sources.
Definition config.h:53