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

Contents of /linuxsampler/trunk/src/audiodriver/AudioOutputDevice.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 136 - (show annotations) (download)
Sun Jun 20 16:03:35 2004 UTC (19 years, 9 months ago) by senkov
File size: 5312 byte(s)
* Update audiodriver to supply parameters in compliance
 with the latest LSCP spec

1 /***************************************************************************
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 "AudioOutputDevice.h"
24
25 namespace LinuxSampler {
26
27 AudioOutputDevice::AudioOutputDevice(std::map<String,DeviceCreationParameter*> DriverParameters) {
28 if (!DriverParameters["active"]) DriverParameters["active"] = new ParameterActive(this);
29 if (!DriverParameters["samplerate"]) DriverParameters["samplerate"] = new ParameterSampleRate(this);
30 if (!DriverParameters["channels"]) DriverParameters["channels"] = new ParameterChannels(this);
31 this->Parameters = DriverParameters;
32 }
33
34 AudioOutputDevice::~AudioOutputDevice() {
35 std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();
36 while (iter != Parameters.end()) {
37 delete iter->second;
38 Parameters.erase(iter);
39 }
40 }
41
42 std::map<String,DeviceCreationParameter*> AudioOutputDevice::AvailableParameters() {
43 static const std::map<String,DeviceCreationParameter*> available_parameters = CreateAvailableParameters();
44 return available_parameters;
45 }
46
47 std::map<String,DeviceCreationParameter*> AudioOutputDevice::CreateAvailableParameters() {
48 static ParameterActive param_active(NULL);
49 static ParameterSampleRate param_samplerate(NULL);
50 static ParameterChannels param_channels(NULL);
51 std::map<String,DeviceCreationParameter*> result;
52 result["active"] = &param_active;
53 result["samplerate"] = &param_samplerate;
54 result["channels"] = &param_channels;
55 return result;
56 }
57
58 void AudioOutputDevice::Connect(Engine* pEngine) {
59 if (Engines.find(pEngine) == Engines.end()) {
60 pEngine->Connect(this);
61 Engines.insert(pEngine);
62 }
63 }
64
65 void AudioOutputDevice::Disconnect(Engine* pEngine) {
66 if (Engines.find(pEngine) != Engines.end()) { // if clause to prevent disconnect loop
67 Engines.erase(pEngine);
68 pEngine->DisconnectAudioOutputDevice();
69 }
70 }
71
72 AudioChannel* AudioOutputDevice::Channel(uint ChannelIndex) {
73 return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL;
74 }
75
76 std::map<String,DeviceCreationParameter*> AudioOutputDevice::DeviceParameters() {
77 return Parameters;
78 }
79
80 int AudioOutputDevice::RenderAudio(uint Samples) {
81 if (Channels.empty()) return 0;
82
83 // reset all channels with silence
84 {
85 std::vector<AudioChannel*>::iterator iterChannels = Channels.begin();
86 std::vector<AudioChannel*>::iterator end = Channels.end();
87 for (; iterChannels != end; iterChannels++)
88 (*iterChannels)->Clear(); // zero out audio buffer
89 }
90
91 int result = 0;
92
93 // let all connected engines render audio for the current audio fragment cycle
94 {
95 std::set<Engine*>::iterator iterEngine = Engines.begin();
96 std::set<Engine*>::iterator end = Engines.end();
97 for (; iterEngine != end; iterEngine++) {
98 int res = (*iterEngine)->RenderAudio(Samples);
99 if (res != 0) result = res;
100 }
101 }
102
103 return result;
104 }
105
106 int AudioOutputDevice::RenderSilence(uint Samples) {
107 if (Channels.empty()) return 0;
108
109 // reset all channels with silence
110 {
111 std::vector<AudioChannel*>::iterator iterChannels = Channels.begin();
112 std::vector<AudioChannel*>::iterator end = Channels.end();
113 for (; iterChannels != end; iterChannels++)
114 (*iterChannels)->Clear(); // zero out audio buffer
115 }
116
117 return 0;
118 }
119
120 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC