Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 15, 2008, 10:54:25 AM (16 years ago)
Author:
rgrieder
Message:
  • removed obsolete Convert.h includes (possibly from old XML loading)
  • replaced tabs in audio library, plus minor code cleanup because removing the tabs screwed layout
  • replaced all "#define name number" with "const Type name = number" if possible
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/audio/AudioManager.cc

    r1747 r1784  
    3030
    3131#include <cstdlib>
    32 
    3332#include <AL/alut.h>
    3433
     34#include "util/Debug.h"
    3535#include "AudioBuffer.h"
    3636#include "AudioSource.h"
    3737#include "AudioStream.h"
    38 #include "util/Error.h"
    39 #include "util/Debug.h"
    4038
    4139namespace audio
    4240{
    43         AudioManager::AudioManager()
    44         {
    45     ambientPath = "audio/ambient";
     41    AudioManager::AudioManager()
     42    {
     43        ambientPath = "audio/ambient";
    4644
    47     alutInit(NULL, 0);
     45        alutInit(NULL, 0);
     46    }
    4847
     48    AudioManager::~AudioManager()
     49    {
     50        for (unsigned int i=0;i<bgSounds.size();i++)
     51        {
     52            bgSounds[i]->release();
     53        }
     54        alutExit();
     55    }
    4956
    50         }
     57    void AudioManager::ambientStart()
     58    {
     59//              currentBgSound = 0;
     60        if (bgSounds.size() > 0)
     61        {
     62            currentBgSound = rand() % bgSounds.size();
     63            if(!bgSounds[currentBgSound]->playback())
     64            {
     65                COUT(2) << "AudioManager: Ogg refused to play." << std::endl;
     66            }
     67            else
     68            {
     69                COUT(3) << "Info: Started playing background sound" << std::endl;
     70            }
     71        }
     72    }
    5173
    52         AudioManager::~AudioManager()
    53         {
    54                 for (unsigned int i=0;i<bgSounds.size();i++)
    55                 {
    56                         bgSounds[i]->release();
    57                 }
    58                 alutExit();
    59         }
     74    void AudioManager::ambientStop()
     75    {
     76        COUT(3) << "Info: Stopped playing background sound" << std::endl;
     77    }
    6078
    61         void AudioManager::ambientStart()
    62         {
    63 //              currentBgSound = 0;
    64                 if (bgSounds.size() > 0)
    65                 {
    66       currentBgSound = rand() % bgSounds.size();
    67                         if(!bgSounds[currentBgSound]->playback())
    68                         {
    69                 orxonox::Error("Ogg refused to play.");
    70                         }
    71                         else
    72                         {
    73                                 COUT(3) << "Info: Started playing background sound" << std::endl;
    74                         }
    75                 }
    76         }
     79    void AudioManager::ambientAdd(std::string file)
     80    {
     81        std::string path = ambientPath + "/" + file + ".ogg";
     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    }
    7790
    78         void AudioManager::ambientStop()
    79         {
    80                 COUT(3) << "Info: Stopped playing background sound" << std::endl;
    81         }
     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                        COUT(2) << "AudioManager: Ogg abruptly stopped." << std::endl;
     102                    else
     103                        COUT(2) << "AudioManager: Ogg stream was interrupted." << std::endl;
    82104
    83         void AudioManager::ambientAdd(std::string file)
    84         {
    85     std::string path = ambientPath + "/" + file + ".ogg";
    86                 AudioStream* tmp = new AudioStream(path);
    87                 tmp->open();
    88                 if (tmp->isLoaded())
    89                 {
    90                         bgSounds.push_back(tmp);
    91                         COUT(3) << "Info: Added background sound " << file << std::endl;
    92                 }
    93         }
     105                }
     106                if (!playing)
     107                {
     108//                    if (currentBgSound < bgSounds.size()-1)
     109//                    {
     110//                        currentBgSound++;
     111//                    }
     112//                    else
     113//                    {
     114//                        currentBgSound=0;
     115//                    }
     116                    // switch to next sound in list/array
     117                    currentBgSound = ++currentBgSound % bgSounds.size();
    94118
    95         void AudioManager::tick(float dt)
    96         {
    97                 if (bgSounds.size() > 0)
    98                 {
    99                         if (bgSounds[currentBgSound]->isLoaded())
    100                         {
    101                                 bool playing = bgSounds[currentBgSound]->update();
    102                     if(!bgSounds[currentBgSound]->playing() && playing)
    103                     {
    104                         if(!bgSounds[currentBgSound]->playback())
    105                             orxonox::Error("Ogg abruptly stopped.");
    106                         else
    107                             orxonox::Error("Ogg stream was interrupted.");
     119                    if (!bgSounds[currentBgSound]->isLoaded())
     120                    {
     121                        bgSounds[currentBgSound]->release();
     122                        bgSounds[currentBgSound]->open();
     123                    }
     124                    bgSounds[currentBgSound]->playback();
     125                    COUT(3) << "Info: Playing next background sound" << std::endl;
     126                }
     127            }
     128        }
     129    }
    108130
    109                     }
    110                                 if (!playing)
    111                                 {
    112 //                                      if (currentBgSound < bgSounds.size()-1)
    113 //                                      {
    114 //                                              currentBgSound++;
    115 //                                      }
    116 //                                      else
    117 //                                      {
    118 //                                              currentBgSound=0;
    119 //                                      }
    120           // switch to next sound in list/array
    121           currentBgSound = ++currentBgSound % bgSounds.size();
     131    void AudioManager::setPos(std::vector<float> newPosition)
     132    {
    122133
    123                                         if (!bgSounds[currentBgSound]->isLoaded())
    124                                         {
    125                                                 bgSounds[currentBgSound]->release();
    126                                                 bgSounds[currentBgSound]->open();
    127                                         }
    128                                         bgSounds[currentBgSound]->playback();
    129                                         COUT(3) << "Info: Playing next background sound" << std::endl;
    130                                 }
    131                         }
    132                 }
    133         }
     134    }
    134135
    135         void AudioManager::setPos(std::vector<float> newPosition)
    136         {
     136    void AudioManager::setSpeed(std::vector<float> newSpeed)
     137    {
    137138
    138         }
     139    }
    139140
    140         void AudioManager::setSpeed(std::vector<float> newSpeed)
    141         {
     141    void AudioManager::setOri(std::vector<float> at, std::vector<float> up)
     142    {
    142143
    143         }
    144 
    145         void AudioManager::setOri(std::vector<float> at, std::vector<float> up)
    146         {
    147 
    148         }
     144    }
    149145}
Note: See TracChangeset for help on using the changeset viewer.