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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1829 - (show annotations) (download)
Fri Jan 30 19:22:36 2009 UTC (15 years, 2 months ago) by iliev
File size: 8818 byte(s)
* added (experimental) CoreAudio driver

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 * *
8 * This library is free software; you can redistribute it and/or modify *
9 * 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 * This library is distributed in the hope that it will be useful, *
14 * 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 * along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #include "AudioOutputDeviceFactory.h"
25
26 #include "../../common/global_private.h"
27
28 #if HAVE_ALSA
29 # include "AudioOutputDeviceAlsa.h"
30 #endif // HAVE_ALSA
31
32 #if HAVE_JACK
33 # include "AudioOutputDeviceJack.h"
34 #endif // HAVE_JACK
35
36 #if HAVE_ARTS
37 # include "AudioOutputDeviceArts.h"
38 #endif // HAVE_ARTS
39
40 #if HAVE_ASIO
41 # include "AudioOutputDeviceAsio.h"
42 #endif // HAVE_ASIO
43
44 #if HAVE_COREAUDIO
45 # include "AudioOutputDeviceCoreAudio.h"
46 #endif // HAVE_COREAUDIO
47
48 namespace LinuxSampler {
49
50 std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
51 std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
52
53 #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
65 #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 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterSampleRate);
70 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
71 /* Driver specific parameters */
72 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
73 #endif // HAVE_JACK
74
75 #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 #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 #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 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBuffers);
103 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceCoreAudio, ParameterBufferSize);
104 #endif // HAVE_COREAUDIO
105
106 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) {
107 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
108 //Let's see if we need to create parameters
109 std::map<String,DeviceCreationParameter*> thisDeviceParams;
110 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
111 if (pParamFactory) {
112 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
113 } else {
114 //No parameters are registered by the driver. Throw if any parameters were specified.
115 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
116 }
117 //Now create the device using those parameters
118 AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
119 //Now attach all parameters to the newely created device.
120 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
121 iter->second->Attach(pDevice);
122 }
123 return pDevice;
124 }
125
126 std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
127 std::vector<String> result;
128 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
129 while (iter != InnerFactories.end()) {
130 result.push_back(iter->first);
131 iter++;
132 }
133 return result;
134 }
135
136 String AudioOutputDeviceFactory::AvailableDriversAsString() {
137 std::vector<String> drivers = AvailableDrivers();
138 String result;
139 std::vector<String>::iterator iter = drivers.begin();
140 for (; iter != drivers.end(); iter++) {
141 if (result != "") result += ",";
142 result += *iter;
143 }
144 return result;
145 }
146
147 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
148 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
149 std::map<String,DeviceCreationParameter*> thisDeviceParams;
150 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
151 if (pParamFactory) {
152 thisDeviceParams = pParamFactory->CreateAllParams();
153 }
154 return thisDeviceParams;
155 }
156
157 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
158 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
159 if (!parameters.count(ParameterName)) throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
160 return parameters[ParameterName];
161 }
162
163 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
164 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
165 return InnerFactories[DriverName]->Description();
166 }
167
168 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
169 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
170 return InnerFactories[DriverName]->Version();
171 }
172
173 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC