1 | #include "AudioManager.h" |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | namespace audio |
---|
6 | { |
---|
7 | AudioManager::AudioManager() |
---|
8 | { |
---|
9 | ambientPath = "audio/ambient"; |
---|
10 | |
---|
11 | alutInit(NULL, 0); |
---|
12 | |
---|
13 | |
---|
14 | } |
---|
15 | |
---|
16 | AudioManager::~AudioManager() |
---|
17 | { |
---|
18 | for (unsigned int i=0;i<=bgSounds.size();i++) |
---|
19 | { |
---|
20 | bgSounds[i].release(); |
---|
21 | } |
---|
22 | alutExit(); |
---|
23 | } |
---|
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; |
---|
45 | } |
---|
46 | |
---|
47 | void AudioManager::ambientAdd(std::string file) |
---|
48 | { |
---|
49 | std::string path = ambientPath + "/" + file + ".ogg"; |
---|
50 | AudioStream tmp(path); |
---|
51 | tmp.open(); |
---|
52 | if (tmp.isLoaded()) |
---|
53 | { |
---|
54 | bgSounds.push_back(tmp); |
---|
55 | std::cout << "Added background sound "<<file<<std::endl; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | void AudioManager::update() |
---|
60 | { |
---|
61 | if (bgSounds.size() > 0) |
---|
62 | { |
---|
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 | { |
---|
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 | |
---|
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 | } |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | void AudioManager::setPos(std::vector<float> newPosition) |
---|
100 | { |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | void AudioManager::setSpeed(std::vector<float> newSpeed) |
---|
105 | { |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | void AudioManager::setOri(std::vector<float> at, std::vector<float> up) |
---|
110 | { |
---|
111 | |
---|
112 | } |
---|
113 | } |
---|