/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDevice.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/drivers/audio/AudioOutputDevice.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 207 by schoenebeck, Thu Jul 15 21:51:15 2004 UTC revision 2137 by schoenebeck, Mon Oct 4 12:20:23 2010 UTC
# Line 3  Line 3 
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 - 2010 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  *
# Line 29  Line 30 
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 "../Device.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        class IDGenerator;
47    
48      /** Abstract base class for audio output drivers in LinuxSampler      /** Abstract base class for audio output drivers in LinuxSampler
49       *       *
# Line 52  namespace LinuxSampler { Line 57  namespace LinuxSampler {
57              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
58              // Device parameters              // Device parameters
59    
60                /** Device Parameter 'ACTIVE'
61                 *
62                 * Used to activate / deactivate the audio output device.
63                 */
64              class ParameterActive : public DeviceCreationParameterBool {              class ParameterActive : public DeviceCreationParameterBool {
65                  public:                  public:
66                      ParameterActive( void ) : DeviceCreationParameterBool()                  { InitWithDefault();                                  }                      ParameterActive();
67                      ParameterActive( String s ) : DeviceCreationParameterBool(s)             {}                      ParameterActive(String s);
68                      virtual String Description()                                             { return "Enable / disable device";                   }                      virtual String Description();
69                      virtual bool   Fix()                                                     { return false;                                       }                      virtual bool   Fix();
70                      virtual bool   Mandatory()                                               { return false;                                       }                      virtual bool   Mandatory();
71                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters()  { return std::map<String,DeviceCreationParameter*>(); }                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
72                      virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters) { return true;                                        }                      virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters);
73                      virtual void OnSetValue(bool b) throw (LinuxSamplerException)            { if (b) ((AudioOutputDevice*)pDevice)->Play(); else ((AudioOutputDevice*)pDevice)->Stop();       }                      virtual void OnSetValue(bool b) throw (Exception);
74                      static String Name( void ) { return "active"; }                      static String Name();
75              };              };
76    
77                /** Device Parameter 'SAMPLERATE'
78                 *
79                 * Used to set the sample rate of the audio output device.
80                 */
81              class ParameterSampleRate : public DeviceCreationParameterInt {              class ParameterSampleRate : public DeviceCreationParameterInt {
82                  public:                  public:
83                      ParameterSampleRate() : DeviceCreationParameterInt()                            { InitWithDefault();                                  }                      ParameterSampleRate();
84                      ParameterSampleRate( String s ) : DeviceCreationParameterInt(s)                 {}                      ParameterSampleRate(String s);
85                      virtual String Description()                                                    { return "Output sample rate";                        }                      virtual String Description();
86                      virtual bool   Fix()                                                            { return true;                                        }                      virtual bool   Fix();
87                      virtual bool   Mandatory()                                                      { return false;                                       }                      virtual bool   Mandatory();
88                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters()         { return std::map<String,DeviceCreationParameter*>(); }                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
89                      virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters)       { return 44100;                                       }                      virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters);
90                      virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters)      { return optional<int>::nothing;                      }                      virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters);
91                      virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters)      { return optional<int>::nothing;                      }                      virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters);
92                      virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>();                          }                      virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
93                      virtual void             OnSetValue(int i) throw (LinuxSamplerException)        { /* cannot happen, as parameter is fix */            }                      virtual int              ValueAsInt();
94                      static String Name( void ) { return "samplerate"; }                      virtual void             OnSetValue(int i) throw (Exception);
95                        static String Name();
96              };              };
97    
98                /** Device Parameters 'CHANNELS'
99                 *
100                 * Used to increase / decrease the number of audio channels of
101                 * audio output device.
102                 */
103              class ParameterChannels : public DeviceCreationParameterInt {              class ParameterChannels : public DeviceCreationParameterInt {
104                  public:                  public:
105                      ParameterChannels() : DeviceCreationParameterInt()                              { InitWithDefault();                                  }                      ParameterChannels();
106                      ParameterChannels( String s ) : DeviceCreationParameterInt(s)                   {}                      ParameterChannels(String s);
107                      virtual String Description()                                                    { return "Number of output channels";                 }                      virtual String Description();
108                      virtual bool   Fix()                                                            { return false;                                       }                      virtual bool   Fix();
109                      virtual bool   Mandatory()                                                      { return false;                                       }                      virtual bool   Mandatory();
110                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters()         { return std::map<String,DeviceCreationParameter*>(); }                      virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
111                      virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters)       { return 2;                                           }                      virtual optional<int>    DefaultAsInt(std::map<String,String> Parameters);
112                      virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters)      { return optional<int>::nothing;                      }                      virtual optional<int>    RangeMinAsInt(std::map<String,String> Parameters);
113                      virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters)      { return optional<int>::nothing;                      }                      virtual optional<int>    RangeMaxAsInt(std::map<String,String> Parameters);
114                      virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters) { return std::vector<int>();                          }                      virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
115                      virtual void             OnSetValue(int i) throw (LinuxSamplerException)        { ((AudioOutputDevice*)pDevice)->AcquireChannels(i);    }                      virtual void             OnSetValue(int i) throw (Exception);
116                      static String Name( void ) { return "channels"; }                      static String Name();
117              };              };
118    
119    
120    
121              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
122              // abstract methods              // abstract methods
123              //     (these have to be implemented by the descendant)              //     (these have to be implemented by the descendant)
# Line 132  namespace LinuxSampler { Line 152  namespace LinuxSampler {
152              virtual void Stop() = 0;              virtual void Stop() = 0;
153    
154              /**              /**
              * 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;  
   
             /**  
155               * Maximum amount of sample points the implementing audio               * Maximum amount of sample points the implementing audio
156               * device will ever demand the sampler engines to write in one               * device will ever demand the sampler engines to write in one
157               * fragment cycle / period. Simple audio device drivers usually               * fragment cycle / period. Simple audio device drivers usually
# Line 172  namespace LinuxSampler { Line 172  namespace LinuxSampler {
172              virtual uint SampleRate() = 0;              virtual uint SampleRate() = 0;
173    
174              /**              /**
175               * Return the audio output device driver type name.               * Return the audio output device driver name.
176               */               */
177              virtual String Driver() = 0;              virtual String Driver() = 0;
178    
179                /**
180                 * Create new audio channel. This will be called by
181                 * AcquireChannels(). Each driver must implement it.
182                 */
183                virtual AudioChannel* CreateChannel(uint ChannelNr) = 0;
184    
185    
186    
187              /////////////////////////////////////////////////////////////////              /////////////////////////////////////////////////////////////////
188              // normal methods              // normal methods
189              //     (usually not to be overriden by descendant)              //     (usually not to be overriden by descendant)
# Line 205  namespace LinuxSampler { Line 213  namespace LinuxSampler {
213               */               */
214              AudioChannel* Channel(uint ChannelIndex);              AudioChannel* Channel(uint ChannelIndex);
215    
216                /**
217                 * This method will usually be called by the sampler engines that
218                 * are connected to this audio device to inform the audio device
219                 * how much audio channels the engine(s) need. It's the
220                 * responsibility of the audio device to offer that amount of
221                 * audio channels - again: this is not an option this is a must!
222                 * The engines will assume to be able to access those audio
223                 * channels right after. If the audio driver is not able to offer
224                 * that much channels, it can simply create mix channels which
225                 * are then just mixed to the 'real' audio channels. See
226                 * AudioChannel.h for details about channels and mix channels.
227                 *
228                 * @param Channels - amount of output channels required by
229                 *                   a sampler engine
230                 * @throws AudioOutputException  if desired amount of channels
231                 *                               cannot be offered
232                 * @see AudioChannel
233                 */
234                void AcquireChannels(uint Channels);
235    
236                /**
237                 * Returns the amount of audio channels (including the so called
238                 * "mix channels") the device is currently providing.
239                 */
240                uint ChannelCount();
241    
242                /**
243                 * Returns all device parameter settings.
244                 */
245              std::map<String,DeviceCreationParameter*> DeviceParameters();              std::map<String,DeviceCreationParameter*> DeviceParameters();
246    
247                /**
248                 * Add a chain of send effects to this AudioOutputDevice.
249                 * You actually have to add effects to that chain afterwards.
250                 */
251                EffectChain* AddSendEffectChain();
252    
253                /**
254                 * Remove the send effect chain given by @a iChain .
255                 *
256                 * @throws Exception - if given send effect chain doesn't exist
257                 */
258                void RemoveSendEffectChain(uint iChain) throw (Exception);
259    
260                /**
261                 * Returns send effect chain given by @a iChain or @c NULL if
262                 * there's no such effect chain.
263                 */
264                EffectChain* SendEffectChain(uint iChain) const;
265    
266                /**
267                 * Returns amount of send effect chains this AudioOutputDevice
268                 * currently provides.
269                 */
270                uint SendEffectChainCount() const;
271    
272                /**
273                 * @deprecated This method will be removed, use AddSendEffectChain() instead!
274                 */
275                EffectChain* AddMasterEffectChain() DEPRECATED_API;
276    
277                /**
278                 * @deprecated This method will be removed, use RemoveSendEffectChain() instead!
279                 */
280                void RemoveMasterEffectChain(uint iChain) throw (Exception) DEPRECATED_API;
281    
282                /**
283                 * @deprecated This method will be removed, use SendEffectChain() instead!
284                 */
285                EffectChain* MasterEffectChain(uint iChain) const DEPRECATED_API;
286    
287                /**
288                 * @deprecated This method will be removed, use SendEffectChainCount() instead!
289                 */
290                uint MasterEffectChainCount() const DEPRECATED_API;
291    
292          protected:          protected:
293              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.
294                SynchronizedConfig<std::set<Engine*> >::Reader EnginesReader; ///< Audio thread access to Engines.
295              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.
296              std::map<String,DeviceCreationParameter*> Parameters;  ///< All device parameters.              std::map<String,DeviceCreationParameter*> Parameters;  ///< All device parameters.
297                std::vector<EffectChain*>                 vEffectChains;
298                IDGenerator*                              EffectChainIDs;
299    
300              AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters);              AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters);
301    
# Line 242  namespace LinuxSampler { Line 326  namespace LinuxSampler {
326               */               */
327              int RenderSilence(uint Samples);              int RenderSilence(uint Samples);
328    
329              friend class Sampler; // allow Sampler class to destroy audio devices              friend class AudioOutputDeviceFactory; // allow AudioOutputDeviceFactory class to destroy audio devices
330    
331      };      };
332    
# Line 252  namespace LinuxSampler { Line 336  namespace LinuxSampler {
336       * (which should be done in the constructor of the AudioOutputDevice       * (which should be done in the constructor of the AudioOutputDevice
337       * descendant).       * descendant).
338       */       */
339      class AudioOutputException : public LinuxSamplerException {      class AudioOutputException : public Exception {
340          public:          public:
341              AudioOutputException(const std::string& msg) : LinuxSamplerException(msg) {}              AudioOutputException(const std::string& msg) : Exception(msg) {}
342      };      };
343  }  }
344    

Legend:
Removed from v.207  
changed lines
  Added in v.2137

  ViewVC Help
Powered by ViewVC