1 |
schoenebeck |
53 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003 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 |
|
|
void AudioOutputDevice::Connect(Engine* pEngine) { |
28 |
|
|
if (Engines.find(pEngine) == Engines.end()) { |
29 |
|
|
pEngine->Connect(this); |
30 |
|
|
Engines.insert(pEngine); |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
void AudioOutputDevice::Disconnect(Engine* pEngine) { |
35 |
|
|
if (Engines.find(pEngine) != Engines.end()) { // if clause to prevent disconnect loop |
36 |
|
|
Engines.erase(pEngine); |
37 |
|
|
pEngine->DisconnectAudioOutputDevice(); |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
AudioChannel* AudioOutputDevice::Channel(uint ChannelIndex) { |
42 |
|
|
return (ChannelIndex < Channels.size()) ? Channels[ChannelIndex] : NULL; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
int AudioOutputDevice::RenderAudio(uint Samples) { |
46 |
|
|
if (Channels.empty()) return 0; |
47 |
|
|
|
48 |
|
|
// reset all channels with silence |
49 |
|
|
{ |
50 |
|
|
std::vector<AudioChannel*>::iterator iterChannels = Channels.begin(); |
51 |
|
|
std::vector<AudioChannel*>::iterator end = Channels.end(); |
52 |
|
|
for (; iterChannels != end; iterChannels++) |
53 |
|
|
(*iterChannels)->Clear(); // zero out audio buffer |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
int result = 0; |
57 |
|
|
|
58 |
|
|
// let all connected engines render audio for the current audio fragment cycle |
59 |
|
|
{ |
60 |
|
|
std::set<Engine*>::iterator iterEngine = Engines.begin(); |
61 |
|
|
std::set<Engine*>::iterator end = Engines.end(); |
62 |
|
|
for (; iterEngine != end; iterEngine++) { |
63 |
|
|
int res = (*iterEngine)->RenderAudio(Samples); |
64 |
|
|
if (res != 0) result = res; |
65 |
|
|
} |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
return result; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
int AudioOutputDevice::RenderSilence(uint Samples) { |
72 |
|
|
if (Channels.empty()) return 0; |
73 |
|
|
|
74 |
|
|
// reset all channels with silence |
75 |
|
|
{ |
76 |
|
|
std::vector<AudioChannel*>::iterator iterChannels = Channels.begin(); |
77 |
|
|
std::vector<AudioChannel*>::iterator end = Channels.end(); |
78 |
|
|
for (; iterChannels != end; iterChannels++) |
79 |
|
|
(*iterChannels)->Clear(); // zero out audio buffer |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
return 0; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
} // namespace LinuxSampler |