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