SoundPlayThread.h
Go to the documentation of this file.00001 
00002 #ifndef INCLUDED_SoundPlayThread_h_
00003 #define INCLUDED_SoundPlayThread_h_
00004 
00005 #include "IPC/CallbackThread.h"
00006 
00007 #ifdef __linux__
00008 #include <alsa/asoundlib.h>
00009 #endif
00010 
00011 class SoundPlayThread {
00012 public:
00013   SoundPlayThread() : initSuccess(false),
00014 #ifdef __APPLE__
00015     context(NULL)
00016 #else
00017     poller(&SoundPlayThread::poll,*this,TimeET(0L),TimeET(10L),true,CallbackPollThread::STOP_FALSE),
00018                       
00019                       lock(), pcm_handle(NULL), buffer_size(0), period_size(0), frame_size(0), buf(NULL)
00020 #endif
00021   {
00022     openSystem();
00023   }
00024   virtual ~SoundPlayThread() {
00025     if(initSuccess)
00026       closeSystem();
00027   }
00028   
00029   void reset();
00030   
00031 protected:
00032   void openSystem();
00033   void closeSystem();
00034   
00035   bool initSuccess;
00036   
00037 #ifdef __APPLE__
00038   struct SoundPlayContext * context;
00039 #else
00040   virtual bool poll();
00041   CallbackPollThread poller;
00042   
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050   Thread::Lock lock;
00051 
00052   snd_pcm_t * pcm_handle;
00053 
00054   snd_pcm_uframes_t buffer_size;
00055   snd_pcm_uframes_t period_size;
00056   unsigned int frame_size;
00057 
00058   char * buf;
00059 
00060 #endif
00061   
00062 private:
00063   SoundPlayThread(const SoundPlayThread& l); 
00064   SoundPlayThread& operator=(const SoundPlayThread& l); 
00065 };
00066 
00067 
00068 
00069 
00070 
00071 
00072 #endif