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