00001 00028 #ifndef ASYNC_AUDIO_SOURCE_INCLUDED 00029 #define ASYNC_AUDIO_SOURCE_INCLUDED 00030 00031 00032 /**************************************************************************** 00033 * 00034 * System Includes 00035 * 00036 ****************************************************************************/ 00037 00038 #include <cassert> 00039 00040 00041 /**************************************************************************** 00042 * 00043 * Project Includes 00044 * 00045 ****************************************************************************/ 00046 00047 00048 00049 /**************************************************************************** 00050 * 00051 * Local Includes 00052 * 00053 ****************************************************************************/ 00054 00055 00056 00057 /**************************************************************************** 00058 * 00059 * Forward declarations 00060 * 00061 ****************************************************************************/ 00062 00063 00064 00065 /**************************************************************************** 00066 * 00067 * Namespace 00068 * 00069 ****************************************************************************/ 00070 00071 namespace Async 00072 { 00073 00074 00075 /**************************************************************************** 00076 * 00077 * Forward declarations of classes inside of the declared namespace 00078 * 00079 ****************************************************************************/ 00080 00081 class AudioSink; 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 00114 class AudioSource 00115 { 00116 public: 00120 AudioSource(void) 00121 : m_sink(0), m_sink_managed(false), m_handler(0), is_flushing(false) 00122 { 00123 } 00124 00128 virtual ~AudioSource(void); 00129 00137 bool registerSink(AudioSink *sink, bool managed=false); 00138 00142 void unregisterSink(void); 00143 00148 bool isRegistered(void) const { return m_sink != 0; } 00149 00155 AudioSink *sink(void) const { return m_sink; } 00156 00165 bool sinkManaged(void) const { return m_sink_managed; } 00166 00174 void handleAllSamplesFlushed(void) 00175 { 00176 is_flushing = false; 00177 allSamplesFlushed(); 00178 } 00179 00188 virtual void resumeOutput(void) 00189 { 00190 assert(m_handler != 0); 00191 m_handler->resumeOutput(); 00192 } 00193 00194 00195 protected: 00205 virtual void allSamplesFlushed(void) 00206 { 00207 assert(m_handler != 0); 00208 m_handler->handleAllSamplesFlushed(); 00209 } 00210 00211 /* 00212 * @brief Write samples to the connected sink 00213 * @param samples The buffer containing the samples to write 00214 * @param len The number of samples in the buffer 00215 * @return Return the number of samples that was taken care of 00216 * 00217 * This function is used by the inheriting class to write samples to 00218 * the connected sink, if any. If there is no connected sink, the samples 00219 * will be thrown away. This function will return the number of samples 00220 * that was taken care of. Samples that was not taken care of should 00221 * normally be written again to the sink. 00222 */ 00223 int sinkWriteSamples(const float *samples, int len); 00224 00225 /* 00226 * @brief Tell the sink to flush any buffered samples 00227 * 00228 * This function is used by the inheriting class to tell the connected 00229 * sink to flush its buffered samples. When the sink have flushed all its 00230 * samples it will call the allSamplesFlushed function in this class. 00231 * If there is no registered sink the allSamplesFlushed function will be 00232 * called right away. 00233 */ 00234 void sinkFlushSamples(void); 00235 00245 bool setHandler(AudioSource *handler); 00246 00247 /* 00248 * @brief Return the handler 00249 * @return Returns the handler previously set with setHandler or 0 00250 * if none have been set 00251 */ 00252 AudioSource *handler(void) const { return m_handler; } 00253 00257 void clearHandler(void); 00258 00259 00260 private: 00261 AudioSink *m_sink; 00262 bool m_sink_managed; 00263 AudioSource *m_handler; 00264 bool m_auto_unreg_source; 00265 bool is_flushing; 00266 00267 bool registerSinkInternal(AudioSink *sink, bool managed, bool reg); 00268 void unregisterSinkInternal(bool is_being_destroyed); 00269 00270 }; /* class AudioSource */ 00271 00272 00273 } /* namespace */ 00274 00275 #endif /* ASYNC_AUDIO_SOURCE_INCLUDED */ 00276 00277 00278 00279 /* 00280 * This file has not been truncated 00281 */ 00282