Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/audio/AudioManager.cc @ 1494

Last change on this file since 1494 was 1494, checked in by rgrieder, 16 years ago
  • set the svn:eol-style property to all files so, that where ever you check out, you'll get the right line endings (had to change every file with mixed endings to windows in order to set the property)
  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net < *
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:
22 *      Nicolas Perrenoud <nicolape_at_ee.ethz.ch>
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "AudioManager.h"
29
30#include <AL/alut.h>
31
32#include "AudioBuffer.h"
33#include "AudioSource.h"
34#include "AudioStream.h"
35#include "core/Error.h"
36#include "core/Debug.h"
37
38namespace audio
39{
40        AudioManager::AudioManager()
41        {
42    ambientPath = "audio/ambient";
43
44    alutInit(NULL, 0);
45
46
47        }
48
49        AudioManager::~AudioManager()
50        {
51                for (unsigned int i=0;i<bgSounds.size();i++)
52                {
53                        bgSounds[i]->release();
54                }
55                alutExit();
56        }
57
58        void AudioManager::ambientStart()
59        {
60//              currentBgSound = 0;
61                if (bgSounds.size() > 0)
62                {
63      currentBgSound = rand() % bgSounds.size();
64                        if(!bgSounds[currentBgSound]->playback())
65                        {
66                orxonox::Error("Ogg refused to play.");
67                        }
68                        else
69                        {
70                                COUT(3) << "Info: Started playing background sound" << std::endl;
71                        }
72                }
73        }
74
75        void AudioManager::ambientStop()
76        {
77                COUT(3) << "Info: Stopped playing background sound" << std::endl;
78        }
79
80        void AudioManager::ambientAdd(std::string file)
81        {
82    std::string path = ambientPath + "/" + file + ".ogg";
83                AudioStream* tmp = new AudioStream(path);
84                tmp->open();
85                if (tmp->isLoaded())
86                {
87                        bgSounds.push_back(tmp);
88                        COUT(3) << "Info: Added background sound " << file << std::endl;
89                }
90        }
91
92        void AudioManager::tick(float dt)
93        {
94                if (bgSounds.size() > 0)
95                {
96                        if (bgSounds[currentBgSound]->isLoaded())
97                        {
98                                bool playing = bgSounds[currentBgSound]->update();
99                    if(!bgSounds[currentBgSound]->playing() && playing)
100                    {
101                        if(!bgSounds[currentBgSound]->playback())
102                            orxonox::Error("Ogg abruptly stopped.");
103                        else
104                            orxonox::Error("Ogg stream was interrupted.");
105
106                    }
107                                if (!playing)
108                                {
109//                                      if (currentBgSound < bgSounds.size()-1)
110//                                      {
111//                                              currentBgSound++;
112//                                      }
113//                                      else
114//                                      {
115//                                              currentBgSound=0;
116//                                      }
117          // switch to next sound in list/array
118          currentBgSound = ++currentBgSound % bgSounds.size();
119
120                                        if (!bgSounds[currentBgSound]->isLoaded())
121                                        {
122                                                bgSounds[currentBgSound]->release();
123                                                bgSounds[currentBgSound]->open();
124                                        }
125                                        bgSounds[currentBgSound]->playback();
126                                        COUT(3) << "Info: Playing next background sound" << std::endl;
127                                }
128                        }
129                }
130        }
131
132        void AudioManager::setPos(std::vector<float> newPosition)
133        {
134
135        }
136
137        void AudioManager::setSpeed(std::vector<float> newSpeed)
138        {
139
140        }
141
142        void AudioManager::setOri(std::vector<float> at, std::vector<float> up)
143        {
144
145        }
146}
Note: See TracBrowser for help on using the repository browser.