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