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