Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/audio/AudioManager.cc @ 1042

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