VCTR
Loading...
Searching...
No Matches
Decibels.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::detail
24{
25template <is::constant C>
26struct InvertedConstant
27{
28 static constexpr double value = 1.0 / double (C::value);
29};
30
31#if VCTR_USE_GCEM
32template <is::constant C>
33struct Log10ToLog2Constant
34{
35 static constexpr double value = double (C::value) / gcem::log2 (10.0);
36};
37
38template <is::constant C>
39struct InvertedLog10ToLog2Constant
40{
41 static constexpr double value = gcem::log2 (10.0) / double (C::value);
42};
43#endif
44} // namespace vctr::detail
45
46namespace vctr::expressions
47{
48
49template <size_t extent, class SrcType, class DecibelConstant, class MinDb>
50using MagToDb = ClampByConstant<extent,
51 MultiplyVecByConstant<extent,
52 Log10<extent, SrcType>,
53 DecibelConstant>,
54 MinDb,
55 DisabledConstant>;
56
57template <size_t extent, class SrcType, class DecibelConstant>
58using DBToMag = PowConstantBase<extent,
59 MultiplyVecByConstant<extent,
60 SrcType,
61 ::vctr::detail::InvertedConstant<DecibelConstant>>,
62 Constant<10>>;
63
64#if VCTR_USE_GCEM
65template <size_t extent, class SrcType, class DecibelConstant, class MinDb>
66using FastMagToDb = ClampByConstant<extent,
67 MultiplyVecByConstant<extent,
68 FastLog2<extent, SrcType>,
69 ::vctr::detail::Log10ToLog2Constant<DecibelConstant>>,
70 MinDb,
71 DisabledConstant>;
72
73template <size_t extent, class SrcType, class DecibelConstant>
74using FastDbToMag = FastExp2<extent,
75 MultiplyVecByConstant<extent,
76 SrcType,
77 ::vctr::detail::InvertedLog10ToLog2Constant<DecibelConstant>>>;
78#endif
79
80} // namespace vctr::expressions
81
82namespace vctr
83{
84
89struct dBFS : Constant<20> {};
90
95struct dBVoltage : Constant<20> {};
96
101struct dBPower : Constant<10> {};
102
113template <is::constant DecibelConstant, auto minDb = -100>
115
125template <is::constant DecibelConstant>
127
128#if VCTR_USE_GCEM
141template <is::constant DecibelConstant, auto minDb = -100>
142constexpr inline ExpressionChainBuilderWithRuntimeArgs<expressions::FastMagToDb, detail::RuntimeArgChain<std::tuple<>, std::tuple<>, std::tuple<>>, DecibelConstant, Constant<minDb>> fastMagToDb;
143
156template <is::constant DecibelConstant>
157constexpr inline ExpressionChainBuilderWithRuntimeArgs<expressions::FastDbToMag, detail::RuntimeArgChain<std::tuple<>, std::tuple<>, std::tuple<>>, DecibelConstant> fastDbToMag;
158#endif
159
160} // namespace vctr
Constrains the type to be a class that defines a static const value field.
Definition: GenericConcepts.h:114
constexpr ExpressionChainBuilderWithRuntimeArgs< expressions::MagToDb, detail::RuntimeArgChain< std::tuple<>, std::tuple<>, std::tuple<> >, DecibelConstant, Constant< minDb > > magToDb
Converts the source magnitude into a decibel representation.
Definition: Decibels.h:114
constexpr ExpressionChainBuilderWithRuntimeArgs< expressions::DBToMag, detail::RuntimeArgChain< std::tuple<>, std::tuple<>, std::tuple<> >, DecibelConstant > dbToMag
Converts the source decibel values into their magnitude representation.
Definition: Decibels.h:126
The main namespace of the VCTR project.
Definition: Array.h:24
A helper struct to pass a constant as argument wrapped in a struct with a single public static conste...
Definition: ExpressionChainBuilder.h:104
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:157
Decibel constant dbFS to be passed to dbToMag or magToDb.
Definition: Decibels.h:89
Decibel constant dbPower to be passed to dbToMag or magToDb.
Definition: Decibels.h:101
Decibel constant dbVoltage to be passed to dbToMag or magToDb.
Definition: Decibels.h:95