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 | |
---|
17 | } |
---|
18 | |
---|
19 | AudioManager::~AudioManager() |
---|
20 | { |
---|
21 | for (unsigned int i=0;i<=bgSounds.size();i++) |
---|
22 | { |
---|
23 | bgSounds[i].release(); |
---|
24 | } |
---|
25 | alutExit(); |
---|
26 | } |
---|
27 | |
---|
28 | void AudioManager::ambientStart() |
---|
29 | { |
---|
30 | currentBgSound = 0; |
---|
31 | if (bgSounds.size() > 0) |
---|
32 | { |
---|
33 | if(!bgSounds[currentBgSound].playback()) |
---|
34 | { |
---|
35 | orxonox::Error("Ogg refused to play."); |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | std::cout << "Started playing background sound"<<std::endl; |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | } |
---|
44 | |
---|
45 | void AudioManager::ambientStop() |
---|
46 | { |
---|
47 | std::cout << "Stopped playing background sound"<<std::endl; |
---|
48 | } |
---|
49 | |
---|
50 | void AudioManager::ambientAdd(std::string file) |
---|
51 | { |
---|
52 | std::string path = ambientPath + "/" + file + ".ogg"; |
---|
53 | AudioStream tmp(path); |
---|
54 | tmp.open(); |
---|
55 | if (tmp.isLoaded()) |
---|
56 | { |
---|
57 | bgSounds.push_back(tmp); |
---|
58 | std::cout << "Added background sound "<<file<<std::endl; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | void AudioManager::update() |
---|
63 | { |
---|
64 | if (bgSounds.size() > 0) |
---|
65 | { |
---|
66 | if (bgSounds[currentBgSound].isLoaded()) |
---|
67 | { |
---|
68 | bool playing = bgSounds[currentBgSound].update(); |
---|
69 | if(!bgSounds[currentBgSound].playing() && playing) |
---|
70 | { |
---|
71 | if(!bgSounds[currentBgSound].playback()) |
---|
72 | orxonox::Error("Ogg abruptly stopped."); |
---|
73 | else |
---|
74 | orxonox::Error("Ogg stream was interrupted."); |
---|
75 | |
---|
76 | } |
---|
77 | if (!playing) |
---|
78 | { |
---|
79 | if (currentBgSound < bgSounds.size()-1) |
---|
80 | { |
---|
81 | currentBgSound++; |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | currentBgSound=0; |
---|
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 | } |
---|