[349] | 1 | #include "AudioManager.h" |
---|
| 2 | |
---|
[430] | 3 | |
---|
| 4 | |
---|
[349] | 5 | namespace audio |
---|
| 6 | { |
---|
| 7 | AudioManager::AudioManager() |
---|
| 8 | { |
---|
[458] | 9 | ambientPath = "audio/ambient"; |
---|
[430] | 10 | |
---|
[458] | 11 | alutInit(NULL, 0); |
---|
[419] | 12 | |
---|
[423] | 13 | |
---|
[458] | 14 | } |
---|
[423] | 15 | |
---|
[349] | 16 | AudioManager::~AudioManager() |
---|
| 17 | { |
---|
[430] | 18 | for (unsigned int i=0;i<=bgSounds.size();i++) |
---|
| 19 | { |
---|
[458] | 20 | bgSounds[i].release(); |
---|
[430] | 21 | } |
---|
[419] | 22 | alutExit(); |
---|
[349] | 23 | } |
---|
[430] | 24 | |
---|
| 25 | void AudioManager::ambientStart() |
---|
| 26 | { |
---|
| 27 | currentBgSound = 0; |
---|
| 28 | if (bgSounds.size() > 0) |
---|
| 29 | { |
---|
| 30 | if(!bgSounds[currentBgSound].playback()) |
---|
| 31 | { |
---|
| 32 | orxonox::Error("Ogg refused to play."); |
---|
| 33 | } |
---|
| 34 | else |
---|
| 35 | { |
---|
| 36 | std::cout << "Started playing background sound"<<std::endl; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | void AudioManager::ambientStop() |
---|
| 43 | { |
---|
| 44 | std::cout << "Stopped playing background sound"<<std::endl; |
---|
[458] | 45 | } |
---|
[430] | 46 | |
---|
| 47 | void AudioManager::ambientAdd(std::string file) |
---|
| 48 | { |
---|
[458] | 49 | std::string path = ambientPath + "/" + file + ".ogg"; |
---|
| 50 | AudioStream tmp(path); |
---|
[430] | 51 | tmp.open(); |
---|
| 52 | if (tmp.isLoaded()) |
---|
| 53 | { |
---|
[458] | 54 | bgSounds.push_back(tmp); |
---|
[430] | 55 | std::cout << "Added background sound "<<file<<std::endl; |
---|
| 56 | } |
---|
| 57 | } |
---|
[458] | 58 | |
---|
[419] | 59 | void AudioManager::update() |
---|
| 60 | { |
---|
[430] | 61 | if (bgSounds.size() > 0) |
---|
[423] | 62 | { |
---|
[430] | 63 | if (bgSounds[currentBgSound].isLoaded()) |
---|
| 64 | { |
---|
| 65 | bool playing = bgSounds[currentBgSound].update(); |
---|
| 66 | if(!bgSounds[currentBgSound].playing() && playing) |
---|
| 67 | { |
---|
| 68 | if(!bgSounds[currentBgSound].playback()) |
---|
| 69 | orxonox::Error("Ogg abruptly stopped."); |
---|
| 70 | else |
---|
| 71 | orxonox::Error("Ogg stream was interrupted."); |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | if (!playing) |
---|
| 75 | { |
---|
[458] | 76 | // if (currentBgSound < bgSounds.size()-1) |
---|
| 77 | // { |
---|
| 78 | // currentBgSound++; |
---|
| 79 | // } |
---|
| 80 | // else |
---|
| 81 | // { |
---|
| 82 | // currentBgSound=0; |
---|
| 83 | // } |
---|
| 84 | // switch to next sound in list/array |
---|
| 85 | currentBgSound = ++currentBgSound % bgSounds.size(); |
---|
| 86 | |
---|
[430] | 87 | if (!bgSounds[currentBgSound].isLoaded()) |
---|
| 88 | { |
---|
| 89 | bgSounds[currentBgSound].release(); |
---|
| 90 | bgSounds[currentBgSound].open(); |
---|
| 91 | } |
---|
| 92 | bgSounds[currentBgSound].playback(); |
---|
| 93 | std::cout << "Playing next background sound "<<std::endl; |
---|
| 94 | } |
---|
| 95 | } |
---|
[423] | 96 | } |
---|
[419] | 97 | } |
---|
[458] | 98 | |
---|
[349] | 99 | void AudioManager::setPos(std::vector<float> newPosition) |
---|
| 100 | { |
---|
[458] | 101 | |
---|
[349] | 102 | } |
---|
| 103 | |
---|
| 104 | void AudioManager::setSpeed(std::vector<float> newSpeed) |
---|
| 105 | { |
---|
[458] | 106 | |
---|
[349] | 107 | } |
---|
| 108 | |
---|
| 109 | void AudioManager::setOri(std::vector<float> at, std::vector<float> up) |
---|
| 110 | { |
---|
[458] | 111 | |
---|
[349] | 112 | } |
---|
| 113 | } |
---|