/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceFactory.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1832 - (hide annotations) (download)
Thu Feb 5 17:48:54 2009 UTC (15 years, 2 months ago) by iliev
File size: 8907 byte(s)
* CoreAudio: Improved hardware detection
* CoreAudio: Added new driver parameter DEVICE
* CoreAudio: Restart the audio queue when the device
  is changed, for example when headphones are plugged

1 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1424 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 schoenebeck 200 * *
8 schoenebeck 838 * This library is free software; you can redistribute it and/or modify *
9 schoenebeck 200 * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13 schoenebeck 838 * This library is distributed in the hope that it will be useful, *
14 schoenebeck 200 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19 schoenebeck 838 * along with this library; if not, write to the Free Software *
20 schoenebeck 200 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #include "AudioOutputDeviceFactory.h"
25    
26 schoenebeck 1424 #include "../../common/global_private.h"
27    
28 schoenebeck 289 #if HAVE_ALSA
29     # include "AudioOutputDeviceAlsa.h"
30     #endif // HAVE_ALSA
31 schoenebeck 288
32 schoenebeck 289 #if HAVE_JACK
33     # include "AudioOutputDeviceJack.h"
34     #endif // HAVE_JACK
35    
36 schoenebeck 838 #if HAVE_ARTS
37     # include "AudioOutputDeviceArts.h"
38     #endif // HAVE_ARTS
39    
40 senoner 1481 #if HAVE_ASIO
41     # include "AudioOutputDeviceAsio.h"
42     #endif // HAVE_ASIO
43 iliev 1829
44     #if HAVE_COREAUDIO
45     # include "AudioOutputDeviceCoreAudio.h"
46     #endif // HAVE_COREAUDIO
47    
48 schoenebeck 200 namespace LinuxSampler {
49    
50     std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
51     std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
52    
53 schoenebeck 289 #if HAVE_ALSA
54     REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa);
55     /* Common parameters for now they'll have to be registered here. */
56     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive);
57     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate);
58     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels);
59     /* Driver specific parameters */
60     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard);
61     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments);
62     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize);
63     #endif // HAVE_ALSA
64 schoenebeck 288
65 schoenebeck 289 #if HAVE_JACK
66     REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);
67     /* Common parameters for now they'll have to be registered here. */
68     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);
69 schoenebeck 1604 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterSampleRate);
70 schoenebeck 289 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
71 schoenebeck 374 /* Driver specific parameters */
72     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
73 schoenebeck 289 #endif // HAVE_JACK
74    
75 schoenebeck 838 #if HAVE_ARTS
76     REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts);
77     /* Common parameters for now they'll have to be registered here. */
78     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive);
79     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate);
80     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels);
81     /* Driver specific parameters */
82     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName);
83     #endif // HAVE_ARTS
84    
85 senoner 1481 #if HAVE_ASIO
86     REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAsio);
87     /* Common parameters for now they'll have to be registered here. */
88     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterActive);
89     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterSampleRate);
90     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterChannels);
91     /* Driver specific parameters */
92     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterCard);
93     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterFragmentSize);
94     #endif // HAVE_ASIO
95    
96 iliev 1829 #if HAVE_COREAUDIO
97     REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceCoreAudio);
98     /* Common parameters for now they'll have to be registered here. */
99     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterActive);
100     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterSampleRate);
101     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterChannels);
102 iliev 1832 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterDevice);
103 iliev 1829 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBuffers);
104     REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBufferSize);
105     #endif // HAVE_COREAUDIO
106    
107 schoenebeck 880 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) {
108     if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
109 schoenebeck 200 //Let's see if we need to create parameters
110     std::map<String,DeviceCreationParameter*> thisDeviceParams;
111     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
112     if (pParamFactory) {
113     thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
114     } else {
115     //No parameters are registered by the driver. Throw if any parameters were specified.
116 schoenebeck 880 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
117 schoenebeck 200 }
118     //Now create the device using those parameters
119     AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
120     //Now attach all parameters to the newely created device.
121     for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
122     iter->second->Attach(pDevice);
123     }
124     return pDevice;
125     }
126    
127     std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
128     std::vector<String> result;
129     std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
130     while (iter != InnerFactories.end()) {
131     result.push_back(iter->first);
132     iter++;
133     }
134     return result;
135     }
136    
137     String AudioOutputDeviceFactory::AvailableDriversAsString() {
138     std::vector<String> drivers = AvailableDrivers();
139     String result;
140     std::vector<String>::iterator iter = drivers.begin();
141     for (; iter != drivers.end(); iter++) {
142     if (result != "") result += ",";
143     result += *iter;
144     }
145     return result;
146     }
147    
148 schoenebeck 880 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
149     if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
150 schoenebeck 200 std::map<String,DeviceCreationParameter*> thisDeviceParams;
151     DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
152     if (pParamFactory) {
153     thisDeviceParams = pParamFactory->CreateAllParams();
154     }
155     return thisDeviceParams;
156     }
157    
158 schoenebeck 880 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
159 schoenebeck 200 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
160 schoenebeck 880 if (!parameters.count(ParameterName)) throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
161 schoenebeck 200 return parameters[ParameterName];
162     }
163    
164 schoenebeck 880 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
165     if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
166 schoenebeck 200 return InnerFactories[DriverName]->Description();
167     }
168    
169 schoenebeck 880 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
170     if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
171 schoenebeck 200 return InnerFactories[DriverName]->Version();
172     }
173    
174     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC