Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 5, 2007, 11:47:05 PM (16 years ago)
Author:
nicolape
Message:

We now have a background sound playlist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/audio/AudioManager.cc

    r423 r430  
    11#include "AudioManager.h"
     2
     3
    24
    35namespace audio
     
    57        AudioManager::AudioManager()
    68        {
     9                ambientPath = "audio/ambient";
     10
    711                alutInit(NULL, 0);
    8 
    9                 bgSound.open("ambient1");
     12               
     13           
    1014
    1115
    1216
    13                 bgSound.display();
    14 
    15                 if(!bgSound.playback())
    16                 {
    17         orxonox::Error("Ogg refused to play.");
    18                 }
    1917        }
    2018               
    2119        AudioManager::~AudioManager()
    2220        {
    23                 bgSound.release();
     21                for (unsigned int i=0;i<=bgSounds.size();i++)
     22                {
     23                        bgSounds[i].release(); 
     24                }
    2425                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                }
    2560        }
    2661       
    2762        void AudioManager::update()
    2863        {
    29                
    30                 if (bgSound.isLoaded())
     64                if (bgSounds.size() > 0)
    3165                {
    32                         bgSound.update();
    33             if(!bgSound.playing())
    34             {
    35                 if(!bgSound.playback())
    36                     orxonox::Error("Ogg abruptly stopped.");
    37                 else
    38                     orxonox::Error("Ogg stream was interrupted.");
    39             }
     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                        }
    4096                }
    4197        }
Note: See TracChangeset for help on using the changeset viewer.