1 // simdfied unit conversion functions
2 // Copyright (C) 2010 Tim Blechmann
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program 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
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; see the file COPYING. If not, write to
16 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 // Boston, MA 02111-1307, USA.
19 #ifndef SIMD_UNIT_CONVERSION_HPP
20 #define SIMD_UNIT_CONVERSION_HPP
22 #include "simd_unary_arithmetic.hpp"
23 #include "simd_math.hpp"
25 #if defined(__GNUC__) && defined(NDEBUG)
26 #define always_inline inline __attribute__((always_inline))
28 #define always_inline inline
36 template <typename FloatType
>
37 always_inline FloatType
operator()(const FloatType
& arg
) const
39 return log2_()(fabs_()(arg
));
45 template <typename FloatType
>
46 always_inline FloatType
operator()(const FloatType
& midi
) const
48 return (FloatType
)440. * pow_()(FloatType(2.),
49 (midi
- FloatType(69.)) * FloatType(0.083333333333));
55 template <typename FloatType
>
56 always_inline FloatType
operator()(const FloatType
& freq
) const
58 return abs_log2()(freq
* FloatType(0.0022727272727)) * FloatType(12.) + FloatType(69.);
64 template <typename FloatType
>
65 always_inline FloatType
operator()(const FloatType
& midi
) const
67 return pow_()(FloatType(2.), midi
* FloatType(0.083333333333));
73 template <typename FloatType
>
74 always_inline FloatType
operator()(const FloatType
& ratio
) const
76 return FloatType(12.) * log2_()(ratio
);
82 template <typename FloatType
>
83 always_inline FloatType
operator()(const FloatType
& note
) const
85 return FloatType(440.) * pow_()(FloatType(2.), note
- FloatType(4.75));
92 template <typename FloatType
>
93 always_inline FloatType
operator()(const FloatType
& freq
) const
95 return abs_log2()(freq
* FloatType(0.0022727272727)) + FloatType(4.75);
101 template <typename FloatType
>
102 always_inline FloatType
operator()(const FloatType
& amp
) const
104 return log10_()(fabs_()(amp
)) * FloatType(20.);
110 template <typename FloatType
>
111 always_inline FloatType
operator()(const FloatType
& db
) const
113 return pow_()(FloatType(10.), db
* FloatType(0.05));
120 NOVA_SIMD_DEFINE_UNARY_WRAPPER(midi2freq
, detail::midi2freq
)
121 NOVA_SIMD_DEFINE_UNARY_WRAPPER(freq2midi
, detail::freq2midi
)
123 NOVA_SIMD_DEFINE_UNARY_WRAPPER(midi2ratio
, detail::midi2ratio
)
124 NOVA_SIMD_DEFINE_UNARY_WRAPPER(ratio2midi
, detail::ratio2midi
)
126 NOVA_SIMD_DEFINE_UNARY_WRAPPER(oct2freq
, detail::oct2freq
)
127 NOVA_SIMD_DEFINE_UNARY_WRAPPER(freq2oct
, detail::freq2oct
)
129 NOVA_SIMD_DEFINE_UNARY_WRAPPER(amp2db
, detail::amp2db
)
130 NOVA_SIMD_DEFINE_UNARY_WRAPPER(db2amp
, detail::db2amp
)
136 #endif /* SIMD_UNIT_CONVERSION_HPP */