Async  0.18.0
AsyncAudioDelayLine.h
Go to the documentation of this file.
1 
28 #ifndef ASYNC_AUDIO_DELAY_LINE_INCLUDED
29 #define ASYNC_AUDIO_DELAY_LINE_INCLUDED
30 
31 
32 /****************************************************************************
33  *
34  * System Includes
35  *
36  ****************************************************************************/
37 
38 
39 
40 /****************************************************************************
41  *
42  * Project Includes
43  *
44  ****************************************************************************/
45 
46 #include <AsyncAudioSink.h>
47 #include <AsyncAudioSource.h>
48 
49 
50 /****************************************************************************
51  *
52  * Local Includes
53  *
54  ****************************************************************************/
55 
56 
57 
58 /****************************************************************************
59  *
60  * Forward declarations
61  *
62  ****************************************************************************/
63 
64 
65 
66 /****************************************************************************
67  *
68  * Namespace
69  *
70  ****************************************************************************/
71 
72 namespace Async
73 {
74 
75 
76 /****************************************************************************
77  *
78  * Forward declarations of classes inside of the declared namespace
79  *
80  ****************************************************************************/
81 
82 
83 
84 /****************************************************************************
85  *
86  * Defines & typedefs
87  *
88  ****************************************************************************/
89 
90 
91 
92 /****************************************************************************
93  *
94  * Exported Global Variables
95  *
96  ****************************************************************************/
97 
98 
99 
100 /****************************************************************************
101  *
102  * Class definitions
103  *
104  ****************************************************************************/
105 
118 {
119  public:
124  explicit AudioDelayLine(int length_ms);
125 
129  ~AudioDelayLine(void);
130 
140  void setFadeTime(int time_ms);
141 
153  void mute(bool do_mute, int time_ms=0);
154 
163  void clear(int time_ms=-1);
164 
174  int writeSamples(const float *samples, int count);
175 
184  void flushSamples(void);
185 
194  void resumeOutput(void);
195 
204  void allSamplesFlushed(void);
205 
206 
207  protected:
208 
209  private:
210  static const int DEFAULT_FADE_TIME = 10; // 10ms default fade time
211 
212  float *buf;
213  int size;
214  int ptr;
215  int flush_cnt;
216  bool is_muted;
217  int mute_cnt;
218  int last_clear;
219  float *fade_gain;
220  int fade_len;
221  int fade_pos;
222  int fade_dir;
223 
225  AudioDelayLine& operator=(const AudioDelayLine&);
226  void writeRemainingSamples(void);
227 
228  inline float currentFadeGain(void)
229  {
230  if (fade_gain == 0)
231  {
232  return 1.0f;
233  }
234 
235  float gain = fade_gain[fade_pos];
236  fade_pos += fade_dir;
237 
238  if ((fade_dir > 0) && (fade_pos >= fade_len-1))
239  {
240  fade_dir = 0;
241  fade_pos = fade_len-1;
242  }
243  else if ((fade_dir < 0) && (fade_pos <= 0))
244  {
245  fade_dir = 0;
246  fade_pos = 0;
247  }
248 
249  return gain;
250 
251  } /* AudioDelayLine::currentFadeGain */
252 
253 }; /* class AudioDelayLine */
254 
255 
256 } /* namespace */
257 
258 #endif /* ASYNC_AUDIO_DELAY_LINE_INCLUDED */
259 
260 
261 
262 /*
263  * This file has not been truncated
264  */
265