Mozzi  version v2.0
sound synthesis library for Arduino
ReverbTank.h
1 /*
2  * ReverbTank.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2013-2024 Tim Barrass and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
12 #ifndef REVERBTANK_H
13 #define REVERBTANK_H
14 
15 #include "AudioDelay.h"
32 class
33  ReverbTank {
34 
35 public:
46  int8_t early_reflection1 = 37,
47  int8_t early_reflection2 = 77,
48  int8_t early_reflection3 = 127,
49  int8_t loop1_delay=117,
50  uint8_t loop2_delay=255,
51  int8_t feedback_level = 85):
52  _early_reflection1(early_reflection1),_early_reflection2(early_reflection3),_early_reflection3(early_reflection3),
53  _feedback_level(feedback_level)
54  {
55  aLoopDel1.set(loop1_delay);
56  aLoopDel2.set(loop2_delay);
57  }
58 
59 
65  int next(int input){
66  static int recycle1, recycle2;
67 
68  // early reflections
69  int asig = aLoopDel0.next(input, _early_reflection1);
70  asig += aLoopDel0.read(_early_reflection2);
71  asig += aLoopDel0.read(_early_reflection3);
72  asig >>= 2;
73 
74  // recirculating delays
75  int8_t feedback_sig1 = (int8_t) min(max(((recycle1 * _feedback_level)>>7),-128),127); // feedback clipped
76  int8_t feedback_sig2 = (int8_t) min(max(((recycle2 * _feedback_level)>>7),-128),127); // feedback clipped
77  int sig3 = aLoopDel1.next(asig+feedback_sig1);
78  int sig4 = aLoopDel2.next(asig+feedback_sig2);
79  recycle1 = sig3 + sig4;
80  recycle2 = sig3 - sig4;
81 
82  return recycle1;
83  }
84 
85 
91  void setEarlyReflections(int8_t early_reflection1, int8_t early_reflection2, int8_t early_reflection3){
92  _early_reflection1=early_reflection1;
93  _early_reflection2=early_reflection2;
94  _early_reflection3=early_reflection3;
95  }
96 
97 
102  void setLoopDelays(int8_t loop1_delay, uint8_t loop2_delay){
103  aLoopDel1.set(loop1_delay);
104  aLoopDel2.set(loop2_delay);
105  }
106 
110  void setFeebackLevel(int8_t feedback_level){
111  _feedback_level=feedback_level;
112  }
113 
114 
115 private:
116  int8_t _early_reflection1;
117  int8_t _early_reflection2;
118  int8_t _early_reflection3;
119 
120  int8_t _feedback_level;
121 
122  AudioDelay <128> aLoopDel0; // 128/16384 seconds * 340.29 m/s speed of sound = 3.5 metres
123  AudioDelay <128,int> aLoopDel1;
124  AudioDelay <256,int> aLoopDel2; // 7 metres
125 
126 };
127 
133 #endif // #ifndef REVERBTANK_H
A reverb which sounds like the inside of a tin can.
Definition: ReverbTank.h:33
void setLoopDelays(int8_t loop1_delay, uint8_t loop2_delay)
Set the loop delay times in terms of delay cells.
Definition: ReverbTank.h:102
ReverbTank(int8_t early_reflection1=37, int8_t early_reflection2=77, int8_t early_reflection3=127, int8_t loop1_delay=117, uint8_t loop2_delay=255, int8_t feedback_level=85)
Constructor.
Definition: ReverbTank.h:45
int next(int input)
Process the next audio sample and return the reverbed signal.
Definition: ReverbTank.h:65
void setEarlyReflections(int8_t early_reflection1, int8_t early_reflection2, int8_t early_reflection3)
Set the early reflection times in terms of delay cells.
Definition: ReverbTank.h:91
void setFeebackLevel(int8_t feedback_level)
Set the feedback level for the recirculating delays.
Definition: ReverbTank.h:110