Async  0.18.0
AsyncAudioDelayLine.h
Go to the documentation of this file.
00001 
00028 #ifndef ASYNC_AUDIO_DELAY_LINE_INCLUDED
00029 #define ASYNC_AUDIO_DELAY_LINE_INCLUDED
00030 
00031 
00032 /****************************************************************************
00033  *
00034  * System Includes
00035  *
00036  ****************************************************************************/
00037 
00038 
00039 
00040 /****************************************************************************
00041  *
00042  * Project Includes
00043  *
00044  ****************************************************************************/
00045 
00046 #include <AsyncAudioSink.h>
00047 #include <AsyncAudioSource.h>
00048 
00049 
00050 /****************************************************************************
00051  *
00052  * Local Includes
00053  *
00054  ****************************************************************************/
00055 
00056 
00057 
00058 /****************************************************************************
00059  *
00060  * Forward declarations
00061  *
00062  ****************************************************************************/
00063 
00064 
00065 
00066 /****************************************************************************
00067  *
00068  * Namespace
00069  *
00070  ****************************************************************************/
00071 
00072 namespace Async
00073 {
00074 
00075 
00076 /****************************************************************************
00077  *
00078  * Forward declarations of classes inside of the declared namespace
00079  *
00080  ****************************************************************************/
00081 
00082   
00083 
00084 /****************************************************************************
00085  *
00086  * Defines & typedefs
00087  *
00088  ****************************************************************************/
00089 
00090 
00091 
00092 /****************************************************************************
00093  *
00094  * Exported Global Variables
00095  *
00096  ****************************************************************************/
00097 
00098 
00099 
00100 /****************************************************************************
00101  *
00102  * Class definitions
00103  *
00104  ****************************************************************************/
00105 
00117 class AudioDelayLine : public Async::AudioSink, public Async::AudioSource
00118 {
00119   public:
00124     explicit AudioDelayLine(int length_ms);
00125   
00129     ~AudioDelayLine(void);
00130 
00140     void setFadeTime(int time_ms);
00141     
00153     void mute(bool do_mute, int time_ms=0);
00154     
00163     void clear(int time_ms=-1);
00164   
00174     int writeSamples(const float *samples, int count);
00175     
00184     void flushSamples(void);
00185 
00194     void resumeOutput(void);
00195     
00204     void allSamplesFlushed(void);
00205     
00206     
00207   protected:
00208     
00209   private:
00210     static const int DEFAULT_FADE_TIME = 10; // 10ms default fade time
00211 
00212     float       *buf;
00213     int         size;
00214     int         ptr;
00215     int         flush_cnt;
00216     bool        is_muted;
00217     int         mute_cnt;
00218     int         last_clear;
00219     float       *fade_gain;
00220     int         fade_len;
00221     int         fade_pos;
00222     int         fade_dir;
00223     
00224     AudioDelayLine(const AudioDelayLine&);
00225     AudioDelayLine& operator=(const AudioDelayLine&);
00226     void writeRemainingSamples(void);
00227 
00228     inline float currentFadeGain(void)
00229     {
00230       if (fade_gain == 0)
00231       {
00232         return 1.0f;
00233       }
00234       
00235       float gain = fade_gain[fade_pos];
00236       fade_pos += fade_dir;
00237       
00238       if ((fade_dir > 0) && (fade_pos >= fade_len-1))
00239       {
00240         fade_dir = 0;
00241         fade_pos = fade_len-1;
00242       }
00243       else if ((fade_dir < 0) && (fade_pos <= 0))
00244       {
00245         fade_dir = 0;
00246         fade_pos = 0;
00247       }
00248       
00249       return gain;
00250       
00251     } /* AudioDelayLine::currentFadeGain  */
00252 
00253 };  /* class AudioDelayLine */
00254 
00255 
00256 } /* namespace */
00257 
00258 #endif /* ASYNC_AUDIO_DELAY_LINE_INCLUDED */
00259 
00260 
00261 
00262 /*
00263  * This file has not been truncated
00264  */
00265