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

Legend:
Removed from v.200  
changed lines
  Added in v.1722

  ViewVC Help
Powered by ViewVC