CLAM-Development  1.4.0
AudioManager.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 #ifndef __AudioManager___
22 #define __AudioManager___
23 
24 #include <vector>
25 #include <string>
26 #include "Err.hxx"
27 
28 
29 namespace CLAM{
30 
31 class AudioDevice;
32 class AudioDeviceList;
33 class AudioIn;
34 class AudioOut;
35 
42 {
43  friend class AudioIn;
44  friend class AudioOut;
45  friend class AudioDeviceList;
46 private:
47  int mSampleRate, mLatency;
48  unsigned mInternalBuffersNumber;
49 
50  std::vector<AudioDevice*> mDevices;
51 
53  static std::vector<AudioDeviceList*>& DeviceLists(void);
54 
55  static AudioManager* _Current(bool set = 0,AudioManager* m = 0)
56  {
57  static AudioManager* sCurrent = 0;
58  if (set)
59  {
60  if (m)
61  {
62  if (sCurrent) throw Err("Can only have one AudioManager at a time");
63  }
64  sCurrent = m;
65  }
66  return sCurrent;
67  }
68 public:
69  typedef std::vector<AudioDevice*>::const_iterator device_iterator;
70  typedef std::vector<AudioDeviceList*>::const_iterator list_iterator;
71 
79  AudioManager(int sampleRate,int latency);
80 
82  ~AudioManager();
83 
85  {
86  AudioManager* p = _Current();
87 
88  if (p==0) throw Err("No AudioManager current");
89 
90  return *p;
91  }
92 
97  AudioDevice* FindDevice(const std::string& name);
98 
103  AudioDevice* FindOrCreateDevice(const std::string& name);
104 
106  void Start(void) throw(Err);
107 
111  int SampleRate(void) { return mSampleRate; }
112 
116  int Latency(void) { return mLatency; }
117 
120  void SetLatency(int latency) { mLatency = latency; }
121 
122 
127  AudioDeviceList* FindList(const std::string& arch = "default");
128 
133  list_iterator lists_begin() const {return DeviceLists().begin();}
134 
139  list_iterator lists_end() const {return DeviceLists().end();}
140 
144  device_iterator used_devices_begin() const {return mDevices.begin();}
148  device_iterator used_devices_end() const {return mDevices.end();}
149 
150 protected:
153  bool Register(AudioIn& in);
156  bool Register(AudioOut& out);
157 };
158 
159 };//CLAM
160 
161 #endif
162