Sprout/sprout/compost/utility/rosenberg.hpp

38 lines
1.4 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2016-02-25 09:48:28 +00:00
Copyright (c) 2011-2016 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
2012-12-06 17:31:16 +00:00
#ifndef SPROUT_COMPOST_UTILITY_ROSENBERG_HPP
#define SPROUT_COMPOST_UTILITY_ROSENBERG_HPP
#include <sprout/config.hpp>
#include <sprout/detail/pow.hpp>
#include <sprout/type_traits/float_promote.hpp>
namespace sprout {
namespace compost {
//
// rosenberg_value
2016-04-05 09:21:13 +00:00
// Rosenberg wave is asymmetric waveform,
// expansion period/reduction period of the glottis is 40%/16% of the cycle,
// tau1 is expansion period, tau2 is reduction period
2012-12-06 17:31:16 +00:00
//
template<typename T>
inline SPROUT_CONSTEXPR typename sprout::float_promote<T>::type
rosenberg_value(T x, T tau1, T tau2) {
typedef typename sprout::float_promote<T>::type type;
2012-12-07 15:23:45 +00:00
return x >= 0 && x <= tau1
2012-12-06 17:31:16 +00:00
? 3 * sprout::detail::pow2<type>(x / tau1) - 2 * sprout::detail::pow3<type>(x / tau1)
2012-12-07 15:23:45 +00:00
: x > tau1 && x <= tau1 + tau2
2012-12-06 17:31:16 +00:00
? 1 - sprout::detail::pow2<type>((x - tau1) / tau2)
: 0
;
}
} // namespace compost
} // namespace sprout
#endif // #ifndef SPROUT_COMPOST_UTILITY_ROSENBERG_HPP