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

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

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

revision 200 by schoenebeck, Tue Jul 13 22:04:16 2004 UTC revision 840 by persson, Sun Feb 26 13:00:08 2006 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 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 25  Line 26 
26    
27  namespace LinuxSampler {  namespace LinuxSampler {
28    
29    // *************** ParameterActive ***************
30    // *
31    
32        AudioOutputDevice::ParameterActive::ParameterActive() : DeviceCreationParameterBool() {
33            InitWithDefault();
34        }
35    
36        AudioOutputDevice::ParameterActive::ParameterActive(String s) : DeviceCreationParameterBool(s) {
37        }
38    
39        String AudioOutputDevice::ParameterActive::Description() {
40            return "Enable / disable device";
41        }
42    
43        bool AudioOutputDevice::ParameterActive::Fix() {
44            return false;
45        }
46    
47        bool AudioOutputDevice::ParameterActive::Mandatory() {
48            return false;
49        }
50    
51        std::map<String,DeviceCreationParameter*> AudioOutputDevice::ParameterActive::DependsAsParameters() {
52            return std::map<String,DeviceCreationParameter*>();
53        }
54    
55        optional<bool> AudioOutputDevice::ParameterActive::DefaultAsBool(std::map<String,String> Parameters) {
56            return true;
57        }
58    
59        void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (LinuxSamplerException) {
60            if (b) ((AudioOutputDevice*)pDevice)->Play();
61            else ((AudioOutputDevice*)pDevice)->Stop();
62        }
63    
64        String AudioOutputDevice::ParameterActive::Name() {
65            return "ACTIVE";
66        }
67    
68    
69    
70    // *************** ParameterSampleRate ***************
71    // *
72    
73        AudioOutputDevice::ParameterSampleRate::ParameterSampleRate() : DeviceCreationParameterInt() {
74            InitWithDefault();
75        }
76    
77        AudioOutputDevice::ParameterSampleRate::ParameterSampleRate(String s) : DeviceCreationParameterInt(s) {
78        }
79    
80        String AudioOutputDevice::ParameterSampleRate::Description() {
81            return "Output sample rate";
82        }
83    
84        bool AudioOutputDevice::ParameterSampleRate::Fix() {
85            return true;
86        }
87    
88        bool AudioOutputDevice::ParameterSampleRate::Mandatory() {
89            return false;
90        }
91    
92        std::map<String,DeviceCreationParameter*> AudioOutputDevice::ParameterSampleRate::DependsAsParameters() {
93            return std::map<String,DeviceCreationParameter*>();
94        }
95    
96        optional<int> AudioOutputDevice::ParameterSampleRate::DefaultAsInt(std::map<String,String> Parameters) {
97            return 44100;
98        }
99    
100        optional<int> AudioOutputDevice::ParameterSampleRate::RangeMinAsInt(std::map<String,String> Parameters) {
101            return optional<int>::nothing;
102        }
103    
104        optional<int> AudioOutputDevice::ParameterSampleRate::RangeMaxAsInt(std::map<String,String> Parameters) {
105            return optional<int>::nothing;
106        }
107    
108        std::vector<int> AudioOutputDevice::ParameterSampleRate::PossibilitiesAsInt(std::map<String,String> Parameters) {
109            return std::vector<int>();
110        }
111    
112        void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (LinuxSamplerException) {
113            /* cannot happen, as parameter is fix */
114        }
115    
116        String AudioOutputDevice::ParameterSampleRate::Name() {
117            return "SAMPLERATE";
118        }
119    
120    
121    
122    // *************** ParameterChannels ***************
123    // *
124    
125        AudioOutputDevice::ParameterChannels::ParameterChannels() : DeviceCreationParameterInt() {
126           InitWithDefault();
127        }
128    
129        AudioOutputDevice::ParameterChannels::ParameterChannels(String s) : DeviceCreationParameterInt(s) {
130        }
131    
132        String AudioOutputDevice::ParameterChannels::Description() {
133            return "Number of output channels";
134        }
135    
136        bool AudioOutputDevice::ParameterChannels::Fix() {
137            return false;
138        }
139    
140        bool AudioOutputDevice::ParameterChannels::Mandatory() {
141            return false;
142        }
143    
144        std::map<String,DeviceCreationParameter*> AudioOutputDevice::ParameterChannels::DependsAsParameters() {
145            return std::map<String,DeviceCreationParameter*>();
146        }
147    
148        optional<int> AudioOutputDevice::ParameterChannels::DefaultAsInt(std::map<String,String> Parameters) {
149            return 2;
150        }
151    
152        optional<int> AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) {
153            return optional<int>::nothing;
154        }
155    
156        optional<int> AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) {
157            return optional<int>::nothing;
158        }
159    
160        std::vector<int> AudioOutputDevice::ParameterChannels::PossibilitiesAsInt(std::map<String,String> Parameters) {
161            return std::vector<int>();
162        }
163    
164        void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (LinuxSamplerException) {
165            ((AudioOutputDevice*)pDevice)->AcquireChannels(i);
166        }
167    
168        String AudioOutputDevice::ParameterChannels::Name() {
169            return "CHANNELS";
170        }
171    
172    
173    
174    // *************** AudioOutputDevice ***************
175    // *
176    
177      AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) {      AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) {
178          this->Parameters = DriverParameters;          this->Parameters = DriverParameters;
179      }      }
180    
181      AudioOutputDevice::~AudioOutputDevice() {      AudioOutputDevice::~AudioOutputDevice() {
182          std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();          // delete all audio channels
183          while (iter != Parameters.end()) {          {
184              Parameters.erase(iter);              std::vector<AudioChannel*>::iterator iter = Channels.begin();
185              delete iter->second;              while (iter != Channels.end()) {
186              iter++;                  delete *iter;
187                    iter++;
188                }
189                Channels.clear();
190            }
191    
192            // delete all device parameters
193            {
194                std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();
195                while (iter != Parameters.end()) {
196                    delete iter->second;
197                    iter++;
198                }
199                Parameters.clear();
200          }          }
201      }      }
202    
203      void AudioOutputDevice::Connect(Engine* pEngine) {      void AudioOutputDevice::Connect(Engine* pEngine) {
204          if (Engines.find(pEngine) == Engines.end()) {          std::set<Engine*>& engines = Engines.GetConfigForUpdate();
205              pEngine->Connect(this);          if (engines.find(pEngine) == engines.end()) {
206              Engines.insert(pEngine);              engines.insert(pEngine);
207                Engines.SwitchConfig().insert(pEngine);
208                // make sure the engine knows about the connection
209                //pEngine->Connect(this);
210          }          }
211      }      }
212    
213      void AudioOutputDevice::Disconnect(Engine* pEngine) {      void AudioOutputDevice::Disconnect(Engine* pEngine) {
214          if (Engines.find(pEngine) != Engines.end()) { // if clause to prevent disconnect loop          std::set<Engine*>& engines = Engines.GetConfigForUpdate();
215              Engines.erase(pEngine);          if (engines.find(pEngine) != engines.end()) { // if clause to prevent disconnect loop
216              pEngine->DisconnectAudioOutputDevice();              engines.erase(pEngine);
217                Engines.SwitchConfig().erase(pEngine);
218                // make sure the engine knows about the disconnection
219                //pEngine->DisconnectAudioOutputDevice();
220          }          }
221      }      }
222    
# Line 56  namespace LinuxSampler { Line 224  namespace LinuxSampler {
224          return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL;          return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL;
225      }      }
226    
227        void AudioOutputDevice::AcquireChannels(uint Channels) {
228            if (Channels > this->Channels.size()) {
229                for (int c = this->Channels.size(); c < Channels; c++) {
230                    this->Channels.push_back(CreateChannel(c));
231                }
232            }
233        }
234    
235      std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() {      std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() {
236          return Parameters;          return Parameters;
237      }      }
# Line 74  namespace LinuxSampler { Line 250  namespace LinuxSampler {
250          int result = 0;          int result = 0;
251    
252          // let all connected engines render audio for the current audio fragment cycle          // let all connected engines render audio for the current audio fragment cycle
253            const std::set<Engine*>& engines = Engines.Lock();
254            #if CONFIG_RT_EXCEPTIONS
255            try
256            #endif // CONFIG_RT_EXCEPTIONS
257          {          {
258              std::set<Engine*>::iterator iterEngine = Engines.begin();              std::set<Engine*>::iterator iterEngine = engines.begin();
259              std::set<Engine*>::iterator end        = Engines.end();              std::set<Engine*>::iterator end        = engines.end();
260              for (; iterEngine != end; iterEngine++) {              for (; iterEngine != end; iterEngine++) {
261                  int res = (*iterEngine)->RenderAudio(Samples);                  int res = (*iterEngine)->RenderAudio(Samples);
262                  if (res != 0) result = res;                  if (res != 0) result = res;
263              }              }
264          }          }
265            #if CONFIG_RT_EXCEPTIONS
266            catch (std::runtime_error se) {
267                std::cerr << "std::runtime_error: " << se.what() << std::endl << std::flush;
268                exit(EXIT_FAILURE);
269            }
270            #endif // CONFIG_RT_EXCEPTIONS
271    
272            Engines.Unlock();
273          return result;          return result;
274      }      }
275    

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

  ViewVC Help
Powered by ViewVC