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