[513] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1505] | 3 | * > www.orxonox.net < |
---|
[513] | 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: |
---|
[1056] | 23 | * Nicolas Perrenoud <nicolape_at_ee.ethz.ch> |
---|
[513] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[349] | 29 | #include "AudioManager.h" |
---|
[1039] | 30 | |
---|
[1639] | 31 | #include <cstdlib> |
---|
| 32 | |
---|
[1039] | 33 | #include <AL/alut.h> |
---|
| 34 | |
---|
[1064] | 35 | #include "AudioBuffer.h" |
---|
| 36 | #include "AudioSource.h" |
---|
| 37 | #include "AudioStream.h" |
---|
[1039] | 38 | #include "core/Error.h" |
---|
[774] | 39 | #include "core/Debug.h" |
---|
[349] | 40 | |
---|
| 41 | namespace audio |
---|
| 42 | { |
---|
| 43 | AudioManager::AudioManager() |
---|
| 44 | { |
---|
[458] | 45 | ambientPath = "audio/ambient"; |
---|
[430] | 46 | |
---|
[458] | 47 | alutInit(NULL, 0); |
---|
[419] | 48 | |
---|
[423] | 49 | |
---|
[458] | 50 | } |
---|
[423] | 51 | |
---|
[349] | 52 | AudioManager::~AudioManager() |
---|
| 53 | { |
---|
[1021] | 54 | for (unsigned int i=0;i<bgSounds.size();i++) |
---|
[430] | 55 | { |
---|
[1064] | 56 | bgSounds[i]->release(); |
---|
[430] | 57 | } |
---|
[419] | 58 | alutExit(); |
---|
[349] | 59 | } |
---|
[430] | 60 | |
---|
| 61 | void AudioManager::ambientStart() |
---|
| 62 | { |
---|
[666] | 63 | // currentBgSound = 0; |
---|
[430] | 64 | if (bgSounds.size() > 0) |
---|
| 65 | { |
---|
[1089] | 66 | currentBgSound = rand() % bgSounds.size(); |
---|
[1064] | 67 | if(!bgSounds[currentBgSound]->playback()) |
---|
[430] | 68 | { |
---|
| 69 | orxonox::Error("Ogg refused to play."); |
---|
| 70 | } |
---|
| 71 | else |
---|
| 72 | { |
---|
[560] | 73 | COUT(3) << "Info: Started playing background sound" << std::endl; |
---|
[430] | 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void AudioManager::ambientStop() |
---|
| 79 | { |
---|
[560] | 80 | COUT(3) << "Info: Stopped playing background sound" << std::endl; |
---|
[458] | 81 | } |
---|
[430] | 82 | |
---|
[715] | 83 | void AudioManager::ambientAdd(std::string file) |
---|
[430] | 84 | { |
---|
[715] | 85 | std::string path = ambientPath + "/" + file + ".ogg"; |
---|
[1064] | 86 | AudioStream* tmp = new AudioStream(path); |
---|
| 87 | tmp->open(); |
---|
| 88 | if (tmp->isLoaded()) |
---|
[430] | 89 | { |
---|
[458] | 90 | bgSounds.push_back(tmp); |
---|
[560] | 91 | COUT(3) << "Info: Added background sound " << file << std::endl; |
---|
[430] | 92 | } |
---|
| 93 | } |
---|
[458] | 94 | |
---|
[1021] | 95 | void AudioManager::tick(float dt) |
---|
[419] | 96 | { |
---|
[430] | 97 | if (bgSounds.size() > 0) |
---|
[423] | 98 | { |
---|
[1064] | 99 | if (bgSounds[currentBgSound]->isLoaded()) |
---|
[430] | 100 | { |
---|
[1064] | 101 | bool playing = bgSounds[currentBgSound]->update(); |
---|
| 102 | if(!bgSounds[currentBgSound]->playing() && playing) |
---|
[430] | 103 | { |
---|
[1064] | 104 | if(!bgSounds[currentBgSound]->playback()) |
---|
[430] | 105 | orxonox::Error("Ogg abruptly stopped."); |
---|
| 106 | else |
---|
| 107 | orxonox::Error("Ogg stream was interrupted."); |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | if (!playing) |
---|
| 111 | { |
---|
[458] | 112 | // if (currentBgSound < bgSounds.size()-1) |
---|
| 113 | // { |
---|
| 114 | // currentBgSound++; |
---|
| 115 | // } |
---|
| 116 | // else |
---|
| 117 | // { |
---|
| 118 | // currentBgSound=0; |
---|
| 119 | // } |
---|
| 120 | // switch to next sound in list/array |
---|
| 121 | currentBgSound = ++currentBgSound % bgSounds.size(); |
---|
| 122 | |
---|
[1064] | 123 | if (!bgSounds[currentBgSound]->isLoaded()) |
---|
[430] | 124 | { |
---|
[1064] | 125 | bgSounds[currentBgSound]->release(); |
---|
| 126 | bgSounds[currentBgSound]->open(); |
---|
[430] | 127 | } |
---|
[1064] | 128 | bgSounds[currentBgSound]->playback(); |
---|
[560] | 129 | COUT(3) << "Info: Playing next background sound" << std::endl; |
---|
[430] | 130 | } |
---|
| 131 | } |
---|
[423] | 132 | } |
---|
[419] | 133 | } |
---|
[458] | 134 | |
---|
[349] | 135 | void AudioManager::setPos(std::vector<float> newPosition) |
---|
| 136 | { |
---|
[458] | 137 | |
---|
[349] | 138 | } |
---|
| 139 | |
---|
| 140 | void AudioManager::setSpeed(std::vector<float> newSpeed) |
---|
| 141 | { |
---|
[458] | 142 | |
---|
[349] | 143 | } |
---|
| 144 | |
---|
| 145 | void AudioManager::setOri(std::vector<float> at, std::vector<float> up) |
---|
| 146 | { |
---|
[458] | 147 | |
---|
[349] | 148 | } |
---|
| 149 | } |
---|