/[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 1604 - (show annotations) (download)
Mon Dec 31 15:33:54 2007 UTC (16 years, 3 months ago) by schoenebeck
File size: 8096 byte(s)
* bugfix: JACK audio driver did not offer a device parameter
  "SAMPLERATE" as opposed to the LSCP specs which requires
  all audio drivers to provide it

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 namespace LinuxSampler {
44
45 std::map<String, AudioOutputDeviceFactory::InnerFactory*> AudioOutputDeviceFactory::InnerFactories;
46 std::map<String, DeviceParameterFactory*> AudioOutputDeviceFactory::ParameterFactories;
47
48 #if HAVE_ALSA
49 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa);
50 /* Common parameters for now they'll have to be registered here. */
51 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive);
52 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate);
53 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels);
54 /* Driver specific parameters */
55 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard);
56 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments);
57 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize);
58 #endif // HAVE_ALSA
59
60 #if HAVE_JACK
61 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceJack);
62 /* Common parameters for now they'll have to be registered here. */
63 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterActive);
64 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterSampleRate);
65 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterChannels);
66 /* Driver specific parameters */
67 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceJack, ParameterName);
68 #endif // HAVE_JACK
69
70 #if HAVE_ARTS
71 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceArts);
72 /* Common parameters for now they'll have to be registered here. */
73 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterActive);
74 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterSampleRate);
75 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterChannels);
76 /* Driver specific parameters */
77 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceArts, ParameterName);
78 #endif // HAVE_ARTS
79
80 #if HAVE_ASIO
81 REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAsio);
82 /* Common parameters for now they'll have to be registered here. */
83 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterActive);
84 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterSampleRate);
85 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterChannels);
86 /* Driver specific parameters */
87 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterCard);
88 REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAsio, ParameterFragmentSize);
89 #endif // HAVE_ASIO
90
91 AudioOutputDevice* AudioOutputDeviceFactory::Create(String DriverName, std::map<String,String> Parameters) throw (Exception) {
92 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
93 //Let's see if we need to create parameters
94 std::map<String,DeviceCreationParameter*> thisDeviceParams;
95 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
96 if (pParamFactory) {
97 thisDeviceParams = pParamFactory->CreateAllParams(Parameters);
98 } else {
99 //No parameters are registered by the driver. Throw if any parameters were specified.
100 if (Parameters.size() != 0) throw Exception("Driver '" + DriverName + "' does not have any parameters.");
101 }
102 //Now create the device using those parameters
103 AudioOutputDevice* pDevice = InnerFactories[DriverName]->Create(thisDeviceParams);
104 //Now attach all parameters to the newely created device.
105 for (std::map<String,DeviceCreationParameter*>::iterator iter = thisDeviceParams.begin(); iter != thisDeviceParams.end(); iter++) {
106 iter->second->Attach(pDevice);
107 }
108 return pDevice;
109 }
110
111 std::vector<String> AudioOutputDeviceFactory::AvailableDrivers() {
112 std::vector<String> result;
113 std::map<String, InnerFactory*>::iterator iter = InnerFactories.begin();
114 while (iter != InnerFactories.end()) {
115 result.push_back(iter->first);
116 iter++;
117 }
118 return result;
119 }
120
121 String AudioOutputDeviceFactory::AvailableDriversAsString() {
122 std::vector<String> drivers = AvailableDrivers();
123 String result;
124 std::vector<String>::iterator iter = drivers.begin();
125 for (; iter != drivers.end(); iter++) {
126 if (result != "") result += ",";
127 result += *iter;
128 }
129 return result;
130 }
131
132 std::map<String,DeviceCreationParameter*> AudioOutputDeviceFactory::GetAvailableDriverParameters(String DriverName) throw (Exception) {
133 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
134 std::map<String,DeviceCreationParameter*> thisDeviceParams;
135 DeviceParameterFactory* pParamFactory = ParameterFactories[DriverName];
136 if (pParamFactory) {
137 thisDeviceParams = pParamFactory->CreateAllParams();
138 }
139 return thisDeviceParams;
140 }
141
142 DeviceCreationParameter* AudioOutputDeviceFactory::GetDriverParameter(String DriverName, String ParameterName) throw (Exception) {
143 std::map<String,DeviceCreationParameter*> parameters = GetAvailableDriverParameters(DriverName);
144 if (!parameters.count(ParameterName)) throw Exception("Audio output driver '" + DriverName + "' does not have a parameter '" + ParameterName + "'.");
145 return parameters[ParameterName];
146 }
147
148 String AudioOutputDeviceFactory::GetDriverDescription(String DriverName) throw (Exception) {
149 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
150 return InnerFactories[DriverName]->Description();
151 }
152
153 String AudioOutputDeviceFactory::GetDriverVersion(String DriverName) throw (Exception) {
154 if (!InnerFactories.count(DriverName)) throw Exception("There is no audio output driver '" + DriverName + "'.");
155 return InnerFactories[DriverName]->Version();
156 }
157
158 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC