Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/script_trigger/src/audio/AudioManager.cc @ 2051

Last change on this file since 2051 was 1541, checked in by bknecht, 17 years ago

Some updates on the trigger:

  • Reacts on defined sub classes of WorldEntity
  • List of other triggers (no check on them, yet)
  • tick function for delay triggers (have to add a startCounting() function)

etc.

File size: 3.5 KB
RevLine 
[513]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1541]3 *                    > www.orxonox.net <
[513]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[1056]23 *      Nicolas Perrenoud <nicolape_at_ee.ethz.ch>
[513]24 *   Co-authors:
25 *      ...
26 *
27 */
28
[349]29#include "AudioManager.h"
[1039]30
31#include <AL/alut.h>
32
[1064]33#include "AudioBuffer.h"
34#include "AudioSource.h"
35#include "AudioStream.h"
[1039]36#include "core/Error.h"
[774]37#include "core/Debug.h"
[349]38
39namespace audio
40{
[1541]41  AudioManager::AudioManager()
42  {
[458]43    ambientPath = "audio/ambient";
[430]44
[458]45    alutInit(NULL, 0);
[1541]46  }
[419]47
[1541]48  AudioManager::~AudioManager()
49  {
50    for (unsigned int i=0;i<bgSounds.size();i++)
51    {
52      bgSounds[i]->release();
53    }
54    alutExit();
55  }
[423]56
[1541]57  void AudioManager::ambientStart()
58  {
59    // currentBgSound = 0;
60    if (bgSounds.size() > 0)
61    {
[1089]62      currentBgSound = rand() % bgSounds.size();
[1541]63      if(!bgSounds[currentBgSound]->playback())
64      {
65        orxonox::Error("Ogg refused to play.");
66      }
67      else
68      {
69        COUT(3) << "Info: Started playing background sound" << std::endl;
70      }
71    }
72  }
[430]73
[1541]74  void AudioManager::ambientStop()
75  {
76    COUT(3) << "Info: Stopped playing background sound" << std::endl;
77  }
[430]78
[1541]79  void AudioManager::ambientAdd(std::string file)
80  {
[715]81    std::string path = ambientPath + "/" + file + ".ogg";
[1541]82    AudioStream* tmp = new AudioStream(path);
83    tmp->open();
84    if (tmp->isLoaded())
85    {
86      bgSounds.push_back(tmp);
87      COUT(3) << "Info: Added background sound " << file << std::endl;
88    }
89  }
[458]90
[1541]91  void AudioManager::tick(float dt)
92  {
93    if (bgSounds.size() > 0)
94    {
95      if (bgSounds[currentBgSound]->isLoaded())
96      {
97        bool playing = bgSounds[currentBgSound]->update();
98        if(!bgSounds[currentBgSound]->playing() && playing)
99        {
100          if(!bgSounds[currentBgSound]->playback())
101            orxonox::Error("Ogg abruptly stopped.");
102          else
103            orxonox::Error("Ogg stream was interrupted.");
104        }
105        if (!playing)
106        {
107          // if (currentBgSound < bgSounds.size()-1)
108          // {
109          //   currentBgSound++;
110          // }
111          // else
112          // {
113          //   currentBgSound=0;
114          // }
[458]115          // switch to next sound in list/array
116          currentBgSound = ++currentBgSound % bgSounds.size();
117
[1541]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  }
[458]129
[1541]130  void AudioManager::setPos(std::vector<float> newPosition)
131  {
132  }
[458]133
[1541]134  void AudioManager::setSpeed(std::vector<float> newSpeed)
135  {
136  }
[349]137
[1541]138  void AudioManager::setOri(std::vector<float> at, std::vector<float> up)
139  {
140  }
[458]141
[349]142}
Note: See TracBrowser for help on using the repository browser.