1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Nicolas Perrenoud <nicolape_at_ee.ethz.ch> |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "AudioManager.h" |
---|
30 | |
---|
31 | #include <AL/alut.h> |
---|
32 | |
---|
33 | #include "AudioBuffer.h" |
---|
34 | #include "AudioSource.h" |
---|
35 | #include "AudioStream.h" |
---|
36 | #include "util/Error.h" |
---|
37 | #include "util/Debug.h" |
---|
38 | |
---|
39 | namespace audio |
---|
40 | { |
---|
41 | AudioManager::AudioManager() |
---|
42 | { |
---|
43 | ambientPath = "audio/ambient"; |
---|
44 | |
---|
45 | alutInit(NULL, 0); |
---|
46 | |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | AudioManager::~AudioManager() |
---|
51 | { |
---|
52 | for (unsigned int i=0;i<bgSounds.size();i++) |
---|
53 | { |
---|
54 | bgSounds[i]->release(); |
---|
55 | } |
---|
56 | alutExit(); |
---|
57 | } |
---|
58 | |
---|
59 | void AudioManager::ambientStart() |
---|
60 | { |
---|
61 | // currentBgSound = 0; |
---|
62 | if (bgSounds.size() > 0) |
---|
63 | { |
---|
64 | currentBgSound = rand() % bgSounds.size(); |
---|
65 | if(!bgSounds[currentBgSound]->playback()) |
---|
66 | { |
---|
67 | orxonox::Error("Ogg refused to play."); |
---|
68 | } |
---|
69 | else |
---|
70 | { |
---|
71 | COUT(3) << "Info: Started playing background sound" << std::endl; |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | void AudioManager::ambientStop() |
---|
77 | { |
---|
78 | COUT(3) << "Info: Stopped playing background sound" << std::endl; |
---|
79 | } |
---|
80 | |
---|
81 | void AudioManager::ambientAdd(std::string file) |
---|
82 | { |
---|
83 | std::string path = ambientPath + "/" + file + ".ogg"; |
---|
84 | AudioStream* tmp = new AudioStream(path); |
---|
85 | tmp->open(); |
---|
86 | if (tmp->isLoaded()) |
---|
87 | { |
---|
88 | bgSounds.push_back(tmp); |
---|
89 | COUT(3) << "Info: Added background sound " << file << std::endl; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | void AudioManager::tick(float dt) |
---|
94 | { |
---|
95 | if (bgSounds.size() > 0) |
---|
96 | { |
---|
97 | if (bgSounds[currentBgSound]->isLoaded()) |
---|
98 | { |
---|
99 | bool playing = bgSounds[currentBgSound]->update(); |
---|
100 | if(!bgSounds[currentBgSound]->playing() && playing) |
---|
101 | { |
---|
102 | if(!bgSounds[currentBgSound]->playback()) |
---|
103 | orxonox::Error("Ogg abruptly stopped."); |
---|
104 | else |
---|
105 | orxonox::Error("Ogg stream was interrupted."); |
---|
106 | |
---|
107 | } |
---|
108 | if (!playing) |
---|
109 | { |
---|
110 | // if (currentBgSound < bgSounds.size()-1) |
---|
111 | // { |
---|
112 | // currentBgSound++; |
---|
113 | // } |
---|
114 | // else |
---|
115 | // { |
---|
116 | // currentBgSound=0; |
---|
117 | // } |
---|
118 | // switch to next sound in list/array |
---|
119 | currentBgSound = ++currentBgSound % bgSounds.size(); |
---|
120 | |
---|
121 | if (!bgSounds[currentBgSound]->isLoaded()) |
---|
122 | { |
---|
123 | bgSounds[currentBgSound]->release(); |
---|
124 | bgSounds[currentBgSound]->open(); |
---|
125 | } |
---|
126 | bgSounds[currentBgSound]->playback(); |
---|
127 | COUT(3) << "Info: Playing next background sound" << std::endl; |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | void AudioManager::setPos(std::vector<float> newPosition) |
---|
134 | { |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | void AudioManager::setSpeed(std::vector<float> newSpeed) |
---|
139 | { |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | void AudioManager::setOri(std::vector<float> at, std::vector<float> up) |
---|
144 | { |
---|
145 | |
---|
146 | } |
---|
147 | } |
---|