AudioManager.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 #ifndef __AudioManager___
00022 #define __AudioManager___
00023 
00024 #include <vector>
00025 #include <string>
00026 #include "Err.hxx"
00027 
00028 
00029 namespace CLAM{
00030 
00031 class AudioDevice;
00032 class AudioDeviceList;
00033 class AudioIn;
00034 class AudioOut;
00035 
00041 class AudioManager
00042 {
00043         friend class AudioIn;
00044         friend class AudioOut;
00045         friend class AudioDeviceList;
00046 private:
00047         int mSampleRate, mLatency;
00048         unsigned mInternalBuffersNumber;
00049 
00050         std::vector<AudioDevice*> mDevices;
00051 
00053         static std::vector<AudioDeviceList*>& DeviceLists(void);
00054         
00055         static AudioManager* _Current(bool set = 0,AudioManager* m = 0)
00056         {
00057                 static AudioManager* sCurrent = 0;
00058                 if (set)
00059                 {
00060                         if (m)
00061                         {
00062                                 if (sCurrent) throw Err("Can only have one AudioManager at a time");
00063                         }
00064                         sCurrent = m;
00065                 }
00066                 return sCurrent;
00067         }
00068 public:
00069         typedef std::vector<AudioDevice*>::const_iterator device_iterator;
00070         typedef std::vector<AudioDeviceList*>::const_iterator list_iterator;
00071 
00079         AudioManager(int sampleRate,int latency);
00080 
00082         ~AudioManager();
00083 
00084         static AudioManager& Current()
00085         {
00086                 AudioManager* p = _Current();
00087                 
00088                 if (p==0) throw Err("No AudioManager current");
00089                 
00090                 return *p;
00091         }
00092 
00097         AudioDevice* FindDevice(const std::string& name);
00098 
00103         AudioDevice* FindOrCreateDevice(const std::string& name);
00104 
00106         void Start(void) throw(Err);
00107 
00111         int SampleRate(void) { return mSampleRate; }
00112 
00116         int Latency(void) { return mLatency; }
00117 
00120         void SetLatency(int latency) { mLatency = latency; }
00121 
00122 
00127         AudioDeviceList* FindList(const std::string& arch = "default");
00128 
00133         list_iterator lists_begin() const {return DeviceLists().begin();}
00134 
00139         list_iterator lists_end() const {return DeviceLists().end();}
00140 
00144         device_iterator used_devices_begin() const {return mDevices.begin();}
00148         device_iterator used_devices_end() const {return mDevices.end();}
00149 
00150 protected:
00153         bool Register(AudioIn& in);
00156         bool Register(AudioOut& out);
00157 };
00158 
00159 };//CLAM
00160 
00161 #endif
00162 
Generated by  doxygen 1.6.3