sequencer
dry_wet.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <utility>
6 
7 namespace sequencer::audio
8 {
9  inline std::pair< float, float > operator*( float a, std::pair< float, float > p )
10  {
11  p.first *= a;
12  p.second *= a;
13  return p;
14  }
15 
16  inline std::pair< float, float > operator+( float a, std::pair< float, float > p )
17  {
18  p.first += a;
19  p.second += a;
20  return p;
21  }
22 
23  template < class T >
24  constexpr T compute_dry_ratio( T x ) noexcept
25  {
26  return x > T( 0.5 ) ? T( 1 ) : 2 * x;
27  }
28 
29  template < class T >
30  constexpr T compute_wet_ratio( T x ) noexcept
31  {
32  return x < T( 0.5 ) ? T( 1 ) : 2 * ( T( 1 ) - x );
33  }
34 
35  template < class F, bool use_input = false >
36  class dry_wet_t : public F
37  {
38  public:
39  using F::F;
40 
41  auto operator()( float x ) noexcept
42  {
43  const auto dry_ratio = compute_dry_ratio( ratio_.load() );
44  const auto wet_ratio = compute_wet_ratio( ratio_.load() );
45  return dry_ratio * ( use_input ? x : 1.0 ) + wet_ratio * F::operator()( x );
46  }
47 
48  void set_dry_wet_ratio( float ratio ) noexcept
49  {
50  ratio_ = ratio;
51  }
52 
53  private:
54  copyable_atomic< float > ratio_{0.0};
55  };
56 } // namespace sequencer::audio
constexpr T compute_wet_ratio(T x) noexcept
Definition: dry_wet.hpp:30
const auto F
Definition: note.hpp:40
T load(std::memory_order order=std::memory_order_seq_cst) const noexcept
Definition: copyable_atomic.hpp:35
std::pair< float, float > operator+(float a, std::pair< float, float > p)
Definition: dry_wet.hpp:16
Definition: delay.hpp:12
void set_dry_wet_ratio(float ratio) noexcept
Definition: dry_wet.hpp:48
auto operator()(float x) noexcept
Definition: dry_wet.hpp:41
std::pair< float, float > operator*(float a, std::pair< float, float > p)
Definition: dry_wet.hpp:9
Definition: dry_wet.hpp:36
constexpr T compute_dry_ratio(T x) noexcept
Definition: dry_wet.hpp:24