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