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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (hide annotations) (download)
Wed Aug 25 22:00:33 2004 UTC (19 years, 7 months ago) by schoenebeck
File size: 9434 byte(s)
* ALSA MIDI driver: create one MIDI port by default, implemented parameter
  info for parameter 'ALSA_SEQ_BINDINGS'
* ALSA audio driver: implemented parameter info for driver parameters
  'FRAGMENTS' and 'FRAGMENTSIZE'
* JACK audio driver: fixed creation of channels on device creation, channel
  parameter 'NAME' now actually updates the respective JACK port name,
  implemented channel parameter 'JACK_BINDINGS' (as well as its parameter
  info)
* src/network/lscpserver.cpp: fixed commands
  "GET MIDI_INPUT_DRIVER_PARAMETER INFO" and
  "GET AUDIO_OUTPUT_DRIVER_PARAMETER  INFO", fixed backward compatibility
  for "SET AUDIO_OUTPUT_TYPE" and "SET MIDI_INPUT_TYPE" commands
* src/networ/lscp.y: added comma character (',') to symbol 'char'
* src/drivers/DeviceParameter.cpp: fixed methods RangeMin(), RangeMax() in
  class DeviceCreationParameterInt which returned wrong values

1 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6     * *
7     * This program is free software; you can redistribute it and/or modify *
8     * it under the terms of the GNU General Public License as published by *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #include "AudioOutputDeviceFactory.h"
24     #include "AudioOutputDevice.h"
25    
26     namespace LinuxSampler {
27    
28 schoenebeck 226 // *************** ParameterActive ***************
29     // *
30    
31     AudioOutputDevice::ParameterActive::ParameterActive() : DeviceCreationParameterBool() {
32     InitWithDefault();
33     }
34    
35     AudioOutputDevice::ParameterActive::ParameterActive(String s) : DeviceCreationParameterBool(s) {
36     }
37    
38     String AudioOutputDevice::ParameterActive::Description() {
39     return "Enable / disable device";
40     }
41    
42     bool AudioOutputDevice::ParameterActive::Fix() {
43     return false;
44     }
45    
46     bool AudioOutputDevice::ParameterActive::Mandatory() {
47     return false;
48     }
49    
50     std::map<String,DeviceCreationParameter*> AudioOutputDevice::ParameterActive::DependsAsParameters() {
51     return std::map<String,DeviceCreationParameter*>();
52     }
53    
54     optional<bool> AudioOutputDevice::ParameterActive::DefaultAsBool(std::map<String,String> Parameters) {
55     return true;
56     }
57    
58     void AudioOutputDevice::ParameterActive::OnSetValue(bool b) throw (LinuxSamplerException) {
59     if (b) ((AudioOutputDevice*)pDevice)->Play();
60     else ((AudioOutputDevice*)pDevice)->Stop();
61     }
62    
63     String AudioOutputDevice::ParameterActive::Name() {
64     return "ACTIVE";
65     }
66    
67    
68    
69     // *************** ParameterSampleRate ***************
70     // *
71    
72     AudioOutputDevice::ParameterSampleRate::ParameterSampleRate() : DeviceCreationParameterInt() {
73     InitWithDefault();
74     }
75    
76     AudioOutputDevice::ParameterSampleRate::ParameterSampleRate(String s) : DeviceCreationParameterInt(s) {
77     }
78    
79     String AudioOutputDevice::ParameterSampleRate::Description() {
80     return "Output sample rate";
81     }
82    
83     bool AudioOutputDevice::ParameterSampleRate::Fix() {
84     return true;
85     }
86    
87     bool AudioOutputDevice::ParameterSampleRate::Mandatory() {
88     return false;
89     }
90    
91     std::map<String,DeviceCreationParameter*> AudioOutputDevice::ParameterSampleRate::DependsAsParameters() {
92     return std::map<String,DeviceCreationParameter*>();
93     }
94    
95     optional<int> AudioOutputDevice::ParameterSampleRate::DefaultAsInt(std::map<String,String> Parameters) {
96     return 44100;
97     }
98    
99     optional<int> AudioOutputDevice::ParameterSampleRate::RangeMinAsInt(std::map<String,String> Parameters) {
100     return optional<int>::nothing;
101     }
102    
103     optional<int> AudioOutputDevice::ParameterSampleRate::RangeMaxAsInt(std::map<String,String> Parameters) {
104     return optional<int>::nothing;
105     }
106    
107     std::vector<int> AudioOutputDevice::ParameterSampleRate::PossibilitiesAsInt(std::map<String,String> Parameters) {
108     return std::vector<int>();
109     }
110    
111     void AudioOutputDevice::ParameterSampleRate::OnSetValue(int i) throw (LinuxSamplerException) {
112     /* cannot happen, as parameter is fix */
113     }
114    
115     String AudioOutputDevice::ParameterSampleRate::Name() {
116     return "SAMPLERATE";
117     }
118    
119    
120    
121     // *************** ParameterChannels ***************
122     // *
123    
124     AudioOutputDevice::ParameterChannels::ParameterChannels() : DeviceCreationParameterInt() {
125     InitWithDefault();
126     }
127    
128     AudioOutputDevice::ParameterChannels::ParameterChannels(String s) : DeviceCreationParameterInt(s) {
129     }
130    
131     String AudioOutputDevice::ParameterChannels::Description() {
132     return "Number of output channels";
133     }
134    
135     bool AudioOutputDevice::ParameterChannels::Fix() {
136     return false;
137     }
138    
139     bool AudioOutputDevice::ParameterChannels::Mandatory() {
140     return false;
141     }
142    
143     std::map<String,DeviceCreationParameter*> AudioOutputDevice::ParameterChannels::DependsAsParameters() {
144     return std::map<String,DeviceCreationParameter*>();
145     }
146    
147     optional<int> AudioOutputDevice::ParameterChannels::DefaultAsInt(std::map<String,String> Parameters) {
148     return 2;
149     }
150    
151     optional<int> AudioOutputDevice::ParameterChannels::RangeMinAsInt(std::map<String,String> Parameters) {
152     return optional<int>::nothing;
153     }
154    
155     optional<int> AudioOutputDevice::ParameterChannels::RangeMaxAsInt(std::map<String,String> Parameters) {
156     return optional<int>::nothing;
157     }
158    
159     std::vector<int> AudioOutputDevice::ParameterChannels::PossibilitiesAsInt(std::map<String,String> Parameters) {
160     return std::vector<int>();
161     }
162    
163     void AudioOutputDevice::ParameterChannels::OnSetValue(int i) throw (LinuxSamplerException) {
164     ((AudioOutputDevice*)pDevice)->AcquireChannels(i);
165     }
166    
167     String AudioOutputDevice::ParameterChannels::Name() {
168     return "CHANNELS";
169     }
170    
171    
172    
173     // *************** AudioOutputDevice ***************
174     // *
175    
176 schoenebeck 200 AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) {
177     this->Parameters = DriverParameters;
178     }
179    
180     AudioOutputDevice::~AudioOutputDevice() {
181 schoenebeck 226 // delete all audio channels
182     {
183     std::vector<AudioChannel*>::iterator iter = Channels.begin();
184     while (iter != Channels.end()) {
185     Channels.erase(iter);
186     delete *iter;
187     iter++;
188     }
189    
190 schoenebeck 200 }
191 schoenebeck 226
192     // delete all device parameters
193     {
194     std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();
195     while (iter != Parameters.end()) {
196     Parameters.erase(iter);
197     delete iter->second;
198     iter++;
199     }
200     }
201 schoenebeck 200 }
202    
203     void AudioOutputDevice::Connect(Engine* pEngine) {
204     if (Engines.find(pEngine) == Engines.end()) {
205     pEngine->Connect(this);
206     Engines.insert(pEngine);
207     }
208     }
209    
210     void AudioOutputDevice::Disconnect(Engine* pEngine) {
211     if (Engines.find(pEngine) != Engines.end()) { // if clause to prevent disconnect loop
212     Engines.erase(pEngine);
213     pEngine->DisconnectAudioOutputDevice();
214     }
215     }
216    
217     AudioChannel* AudioOutputDevice::Channel(uint ChannelIndex) {
218     return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL;
219     }
220    
221 schoenebeck 226 void AudioOutputDevice::AcquireChannels(uint Channels) {
222     if (Channels > this->Channels.size()) {
223     for (int c = this->Channels.size(); c < Channels; c++) {
224     this->Channels.push_back(CreateChannel(c));
225     }
226     }
227     }
228    
229 schoenebeck 200 std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() {
230     return Parameters;
231     }
232    
233     int AudioOutputDevice::RenderAudio(uint Samples) {
234     if (Channels.empty()) return 0;
235    
236     // reset all channels with silence
237     {
238     std::vector<AudioChannel*>::iterator iterChannels = Channels.begin();
239     std::vector<AudioChannel*>::iterator end = Channels.end();
240     for (; iterChannels != end; iterChannels++)
241     (*iterChannels)->Clear(); // zero out audio buffer
242     }
243    
244     int result = 0;
245    
246     // let all connected engines render audio for the current audio fragment cycle
247     {
248     std::set<Engine*>::iterator iterEngine = Engines.begin();
249     std::set<Engine*>::iterator end = Engines.end();
250     for (; iterEngine != end; iterEngine++) {
251     int res = (*iterEngine)->RenderAudio(Samples);
252     if (res != 0) result = res;
253     }
254     }
255    
256     return result;
257     }
258    
259     int AudioOutputDevice::RenderSilence(uint Samples) {
260     if (Channels.empty()) return 0;
261    
262     // reset all channels with silence
263     {
264     std::vector<AudioChannel*>::iterator iterChannels = Channels.begin();
265     std::vector<AudioChannel*>::iterator end = Channels.end();
266     for (; iterChannels != end; iterChannels++)
267     (*iterChannels)->Clear(); // zero out audio buffer
268     }
269    
270     return 0;
271     }
272    
273     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC