3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
30 |
#include <stdexcept> |
#include <stdexcept> |
31 |
|
|
32 |
#include "../../common/global.h" |
#include "../../common/global.h" |
33 |
#include "../../common/LinuxSamplerException.h" |
#include "../../common/Exception.h" |
34 |
#include "../InputOutputDevice.h" |
#include "../Device.h" |
35 |
#include "../DeviceParameter.h" |
#include "../DeviceParameter.h" |
36 |
#include "../../engines/common/Engine.h" |
#include "../../engines/Engine.h" |
37 |
#include "AudioChannel.h" |
#include "AudioChannel.h" |
38 |
|
#include "../../common/SynchronizedConfig.h" |
39 |
|
#include "../../effects/EffectChain.h" |
40 |
|
|
41 |
namespace LinuxSampler { |
namespace LinuxSampler { |
42 |
|
|
43 |
// just symbol prototyping |
// just symbol prototyping |
44 |
class Engine; |
class Engine; |
45 |
|
class AudioOutputDeviceFactory; |
46 |
|
|
47 |
/** Abstract base class for audio output drivers in LinuxSampler |
/** Abstract base class for audio output drivers in LinuxSampler |
48 |
* |
* |
50 |
* connection to a specific audio output system (e.g. Alsa, Jack, |
* connection to a specific audio output system (e.g. Alsa, Jack, |
51 |
* CoreAudio). |
* CoreAudio). |
52 |
*/ |
*/ |
53 |
class AudioOutputDevice : public InputOutputDevice { |
class AudioOutputDevice : public Device { |
54 |
public: |
public: |
55 |
|
|
56 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
57 |
// Device parameters |
// Device parameters |
58 |
|
|
59 |
|
/** Device Parameter 'ACTIVE' |
60 |
|
* |
61 |
|
* Used to activate / deactivate the audio output device. |
62 |
|
*/ |
63 |
class ParameterActive : public DeviceCreationParameterBool { |
class ParameterActive : public DeviceCreationParameterBool { |
64 |
public: |
public: |
65 |
ParameterActive( void ) : DeviceCreationParameterBool() { InitWithDefault(); } |
ParameterActive(); |
66 |
ParameterActive( String s ) : DeviceCreationParameterBool(s) {} |
ParameterActive(String s); |
67 |
virtual String Description() { return "Enable / disable device"; } |
virtual String Description(); |
68 |
virtual bool Fix() { return false; } |
virtual bool Fix(); |
69 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
70 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
71 |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) { return true; } |
virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters); |
72 |
virtual void OnSetValue(bool b) throw (LinuxSamplerException) { if (b) ((AudioOutputDevice*)pDevice)->Play(); else ((AudioOutputDevice*)pDevice)->Stop(); } |
virtual void OnSetValue(bool b) throw (Exception); |
73 |
static String Name( void ) { return "active"; } |
static String Name(); |
74 |
}; |
}; |
75 |
|
|
76 |
|
/** Device Parameter 'SAMPLERATE' |
77 |
|
* |
78 |
|
* Used to set the sample rate of the audio output device. |
79 |
|
*/ |
80 |
class ParameterSampleRate : public DeviceCreationParameterInt { |
class ParameterSampleRate : public DeviceCreationParameterInt { |
81 |
public: |
public: |
82 |
ParameterSampleRate() : DeviceCreationParameterInt() { InitWithDefault(); } |
ParameterSampleRate(); |
83 |
ParameterSampleRate( String s ) : DeviceCreationParameterInt(s) {} |
ParameterSampleRate(String s); |
84 |
virtual String Description() { return "Output sample rate"; } |
virtual String Description(); |
85 |
virtual bool Fix() { return true; } |
virtual bool Fix(); |
86 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
87 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
88 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 44100; } |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
89 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
90 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
91 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
92 |
virtual void OnSetValue(int i) throw (LinuxSamplerException) { /* cannot happen, as parameter is fix */ } |
virtual int ValueAsInt(); |
93 |
static String Name( void ) { return "samplerate"; } |
virtual void OnSetValue(int i) throw (Exception); |
94 |
|
static String Name(); |
95 |
}; |
}; |
96 |
|
|
97 |
|
/** Device Parameters 'CHANNELS' |
98 |
|
* |
99 |
|
* Used to increase / decrease the number of audio channels of |
100 |
|
* audio output device. |
101 |
|
*/ |
102 |
class ParameterChannels : public DeviceCreationParameterInt { |
class ParameterChannels : public DeviceCreationParameterInt { |
103 |
public: |
public: |
104 |
ParameterChannels() : DeviceCreationParameterInt() { InitWithDefault(); } |
ParameterChannels(); |
105 |
ParameterChannels( String s ) : DeviceCreationParameterInt(s) {} |
ParameterChannels(String s); |
106 |
virtual String Description() { return "Number of output channels"; } |
virtual String Description(); |
107 |
virtual bool Fix() { return false; } |
virtual bool Fix(); |
108 |
virtual bool Mandatory() { return false; } |
virtual bool Mandatory(); |
109 |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters() { return std::map<String,DeviceCreationParameter*>(); } |
virtual std::map<String,DeviceCreationParameter*> DependsAsParameters(); |
110 |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters) { return 2; } |
virtual optional<int> DefaultAsInt(std::map<String,String> Parameters); |
111 |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters); |
112 |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters) { return optional<int>::nothing; } |
virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters); |
113 |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>(); } |
virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters); |
114 |
virtual void OnSetValue(int i) throw (LinuxSamplerException) { ((AudioOutputDevice*)pDevice)->AcquireChannels(i); } |
virtual void OnSetValue(int i) throw (Exception); |
115 |
static String Name( void ) { return "channels"; } |
static String Name(); |
116 |
}; |
}; |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
121 |
// abstract methods |
// abstract methods |
122 |
// (these have to be implemented by the descendant) |
// (these have to be implemented by the descendant) |
151 |
virtual void Stop() = 0; |
virtual void Stop() = 0; |
152 |
|
|
153 |
/** |
/** |
|
* This method will usually be called by the sampler engines that |
|
|
* are connected to this audio device to inform the audio device |
|
|
* how much audio channels the engine(s) need. It's the |
|
|
* responsibility of the audio device to offer that amount of |
|
|
* audio channels - again: this is not an option this is a must! |
|
|
* The engines will assume to be able to access those audio |
|
|
* channels right after. If the audio driver is not able to offer |
|
|
* that much channels, it can simply create mix channels which |
|
|
* are then just mixed to the 'real' audio channels. See |
|
|
* AudioChannel.h for details about channels and mix channels. |
|
|
* |
|
|
* @param Channels - amount of output channels required by |
|
|
* a sampler engine |
|
|
* @throws AudioOutputException if desired amount of channels |
|
|
* cannot be offered |
|
|
* @see AudioChannel |
|
|
*/ |
|
|
virtual void AcquireChannels(uint Channels) = 0; |
|
|
|
|
|
/** |
|
154 |
* Maximum amount of sample points the implementing audio |
* Maximum amount of sample points the implementing audio |
155 |
* device will ever demand the sampler engines to write in one |
* device will ever demand the sampler engines to write in one |
156 |
* fragment cycle / period. Simple audio device drivers usually |
* fragment cycle / period. Simple audio device drivers usually |
171 |
virtual uint SampleRate() = 0; |
virtual uint SampleRate() = 0; |
172 |
|
|
173 |
/** |
/** |
174 |
* Return the audio output device driver type name. |
* Return the audio output device driver name. |
175 |
*/ |
*/ |
176 |
virtual String Driver() = 0; |
virtual String Driver() = 0; |
177 |
|
|
178 |
|
/** |
179 |
|
* Create new audio channel. This will be called by |
180 |
|
* AcquireChannels(). Each driver must implement it. |
181 |
|
*/ |
182 |
|
virtual AudioChannel* CreateChannel(uint ChannelNr) = 0; |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
187 |
// normal methods |
// normal methods |
188 |
// (usually not to be overriden by descendant) |
// (usually not to be overriden by descendant) |
212 |
*/ |
*/ |
213 |
AudioChannel* Channel(uint ChannelIndex); |
AudioChannel* Channel(uint ChannelIndex); |
214 |
|
|
215 |
|
/** |
216 |
|
* This method will usually be called by the sampler engines that |
217 |
|
* are connected to this audio device to inform the audio device |
218 |
|
* how much audio channels the engine(s) need. It's the |
219 |
|
* responsibility of the audio device to offer that amount of |
220 |
|
* audio channels - again: this is not an option this is a must! |
221 |
|
* The engines will assume to be able to access those audio |
222 |
|
* channels right after. If the audio driver is not able to offer |
223 |
|
* that much channels, it can simply create mix channels which |
224 |
|
* are then just mixed to the 'real' audio channels. See |
225 |
|
* AudioChannel.h for details about channels and mix channels. |
226 |
|
* |
227 |
|
* @param Channels - amount of output channels required by |
228 |
|
* a sampler engine |
229 |
|
* @throws AudioOutputException if desired amount of channels |
230 |
|
* cannot be offered |
231 |
|
* @see AudioChannel |
232 |
|
*/ |
233 |
|
void AcquireChannels(uint Channels); |
234 |
|
|
235 |
|
/** |
236 |
|
* Returns the amount of audio channels (including the so called |
237 |
|
* "mix channels") the device is currently providing. |
238 |
|
*/ |
239 |
|
uint ChannelCount(); |
240 |
|
|
241 |
|
/** |
242 |
|
* Returns all device parameter settings. |
243 |
|
*/ |
244 |
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
std::map<String,DeviceCreationParameter*> DeviceParameters(); |
245 |
|
|
246 |
|
/** |
247 |
|
* Add a chain of master effects to this AudioOutputDevice. |
248 |
|
* You actually have to add effects to that chain afterwards. |
249 |
|
*/ |
250 |
|
EffectChain* AddMasterEffectChain(); |
251 |
|
|
252 |
|
/** |
253 |
|
* Remove the master effect chain given by @a iChain . |
254 |
|
* |
255 |
|
* @throws Exception - if given master effect chain doesn't exist |
256 |
|
*/ |
257 |
|
void RemoveMasterEffectChain(uint iChain) throw (Exception); |
258 |
|
|
259 |
|
/** |
260 |
|
* Returns master effect chain given by @a iChain or @c NULL if |
261 |
|
* there's no such effect chain. |
262 |
|
*/ |
263 |
|
EffectChain* MasterEffectChain(uint iChain) const; |
264 |
|
|
265 |
|
/** |
266 |
|
* Returns amount of master effect chains this AudioOutputDevice |
267 |
|
* currently provides. |
268 |
|
*/ |
269 |
|
uint MasterEffectChainCount() const; |
270 |
|
|
271 |
protected: |
protected: |
272 |
std::set<Engine*> Engines; ///< All sampler engines that are connected to the audio output device. |
SynchronizedConfig<std::set<Engine*> > Engines; ///< All sampler engines that are connected to the audio output device. |
273 |
|
SynchronizedConfig<std::set<Engine*> >::Reader EnginesReader; ///< Audio thread access to Engines. |
274 |
std::vector<AudioChannel*> Channels; ///< All audio channels of the audio output device. This is just a container; the descendant has to create channels by himself. |
std::vector<AudioChannel*> Channels; ///< All audio channels of the audio output device. This is just a container; the descendant has to create channels by himself. |
275 |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters. |
276 |
|
std::vector<EffectChain*> vEffectChains; |
277 |
|
|
278 |
AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters); |
AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters); |
279 |
|
|
304 |
*/ |
*/ |
305 |
int RenderSilence(uint Samples); |
int RenderSilence(uint Samples); |
306 |
|
|
307 |
friend class Sampler; // allow Sampler class to destroy audio devices |
friend class AudioOutputDeviceFactory; // allow AudioOutputDeviceFactory class to destroy audio devices |
308 |
|
|
309 |
}; |
}; |
310 |
|
|
314 |
* (which should be done in the constructor of the AudioOutputDevice |
* (which should be done in the constructor of the AudioOutputDevice |
315 |
* descendant). |
* descendant). |
316 |
*/ |
*/ |
317 |
class AudioOutputException : public LinuxSamplerException { |
class AudioOutputException : public Exception { |
318 |
public: |
public: |
319 |
AudioOutputException(const std::string& msg) : LinuxSamplerException(msg) {} |
AudioOutputException(const std::string& msg) : Exception(msg) {} |
320 |
}; |
}; |
321 |
} |
} |
322 |
|
|