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