@@ -13,7 +13,7 @@ license that can be found in the LICENSE file or at
1313namespace daisysp
1414{
1515/* * Multimode audio looper
16- *
16+ *
1717* Modes are:
1818* - Normal
1919* - Onetime Dub
@@ -28,9 +28,9 @@ class Looper
2828 Looper () {}
2929 ~Looper () {}
3030
31- /* *
32- ** Normal Mode: Input is added to the existing loop infinitely while recording
33- **
31+ /* *
32+ ** Normal Mode: Input is added to the existing loop infinitely while recording
33+ **
3434 ** Onetime Dub Mode: Recording starts at the first sample of the buffer and is added
3535 ** to the existing buffer contents. Recording automatically stops after one full loop.
3636 **
@@ -58,6 +58,8 @@ class Looper
5858 reverse_ = false ;
5959 rec_queue_ = false ;
6060 win_idx_ = 0 ;
61+
62+ increment_size = 1.0 ;
6163 }
6264
6365 /* * Handles reading/writing to the Buffer depending on the mode. */
@@ -73,7 +75,11 @@ class Looper
7375 win_ = WindowVal (win_idx_ * kWindowFactor );
7476 switch (state_)
7577 {
76- case State::EMPTY: sig = 0 .0f ; break ;
78+ case State::EMPTY:
79+ sig = 0 .0f ;
80+ pos_ = 0 ;
81+ recsize_ = 0 ;
82+ break ;
7783 case State::REC_FIRST:
7884 sig = 0 .f ;
7985 Write (pos_, input * win_);
@@ -91,7 +97,7 @@ class Looper
9197 case State::PLAYING:
9298 sig = Read (pos_);
9399 /* * This is a way of 'seamless looping'
94- ** The first N samps after recording is done are recorded with the input faded out.
100+ ** The first N samps after recording is done are recorded with the input faded out.
95101 */
96102 if (win_idx_ < kWindowSamps - 1 )
97103 {
@@ -162,13 +168,13 @@ class Looper
162168 return sig;
163169 }
164170
165- /* * Effectively erases the buffer
171+ /* * Effectively erases the buffer
166172 ** Note: This does not actually change what is in the buffer */
167173 inline void Clear () { state_ = State::EMPTY; }
168174
169175 /* * Engages/Disengages the recording, depending on Mode.
170176 ** In all modes, the first time this is triggered a new loop will be started.
171- ** The second trigger will set the loop size, and begin playback of the loop.
177+ ** The second trigger will set the loop size, and begin playback of the loop.
172178 */
173179 inline void TrigRecord ()
174180 {
@@ -227,7 +233,22 @@ class Looper
227233 inline void SetHalfSpeed (bool state) { half_speed_ = state; }
228234 inline bool GetHalfSpeed () const { return half_speed_; }
229235
230- inline bool IsNearBeginning () { return near_beginning_; }
236+ inline bool IsNearBeginning () const { return near_beginning_; }
237+
238+ inline float GetIncrementSize () const
239+ {
240+ float inc = increment_size;
241+
242+ if (half_speed_)
243+ inc *= 0 .5f ;
244+
245+ return reverse_ ? -inc : inc;
246+ }
247+
248+ void SetIncrementSize (float increment) { increment_size = increment; }
249+
250+ inline float GetPos () const { return pos_; }
251+ inline size_t GetRecSize () const { return recsize_; }
231252
232253 private:
233254 /* * Constants */
@@ -240,13 +261,6 @@ class Looper
240261 static constexpr float kWindowFactor = (1 .f / kWindowSamps );
241262
242263 /* * Private Member Functions */
243- float GetIncrementSize ()
244- {
245- float inc = 1 .f ;
246- if (half_speed_)
247- inc = 0 .5f ;
248- return reverse_ ? -inc : inc;
249- }
250264
251265 /* * Initialize the buffer */
252266 void InitBuff () { std::fill (&buff_[0 ], &buff_[buffer_size_ - 1 ], 0 ); }
@@ -294,6 +308,7 @@ class Looper
294308 size_t recsize_;
295309 bool rec_queue_;
296310 bool near_beginning_;
311+ float increment_size;
297312};
298313
299314} // namespace daisysp
0 commit comments