Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 430


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

We now have a background sound playlist

Location:
code/branches/FICN
Files:
3 added
5 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        }
  • code/branches/FICN/src/audio/AudioManager.h

    r419 r430  
    3737                void update();
    3838
     39                void ambientAdd(std::string file);
     40                void ambientStart();
     41                void ambientStop();
     42
    3943        private:
    4044
    41                 // Backgroundsound
    42     AudioStream bgSound;
     45                // Background sound
     46    std::vector<AudioStream> bgSounds;
     47                int currentBgSound;
     48
     49
     50
     51                std::string ambientPath;
    4352       
    4453                // Vector containing all audio files
  • code/branches/FICN/src/audio/AudioStream.cc

    r424 r430  
    44namespace audio
    55{
    6         void AudioStream::open(std::string path)
     6        AudioStream::AudioStream(std::string path)
     7        {
     8                this->path = path;
     9                loaded = false;
     10        }       
     11
     12        void AudioStream::open()
    713        {
    814            int result;
    9                         loaded = false;
    10            
    11 
    12             path = "audio/ambient/" + path + ".ogg";
     15
    1316           
    1417            if(!(oggFile = fopen(path.c_str(), "rb")))
     
    5356        void AudioStream::release()
    5457        {
    55                 if (loaded)
    56                 {
     58
    5759            alSourceStop(source);
    5860            empty();
     
    6466            ov_clear(&oggStream);
    6567                        loaded = false;
    66                 }
     68               
    6769        }
    6870       
     
    155157            }
    156158       
     159                        if (active==false)
     160                        {
     161                                loaded = false;
     162                        }
    157163            return active;
    158164        }
  • code/branches/FICN/src/audio/AudioStream.h

    r423 r430  
    77{
    88        #define BUFFER_SIZE (4096 * 4)
    9         #define STREAM_FILES_DIR "audio/ambient"
    109       
    1110        class AudioStream
    1211        {
    1312            public:
    14        
    15                 void open(std::string path);
     13                                        AudioStream(std::string path);
     14                void open();
    1615                void release();
    1716                void display();
     
    3029            private:
    3130       
     31                                        std::string path;
     32
    3233                FILE*           oggFile;
    3334                OggVorbis_File  oggStream;
  • code/branches/FICN/src/orxonox/orxonox.cc

    r427 r430  
    287287                                auMan = new audio::AudioManager();
    288288
     289                                auMan->ambientAdd("a1");
     290                                auMan->ambientAdd("a2");
     291                                auMan->ambientAdd("a3");
     292                                //auMan->ambientAdd("ambient1");
     293                                auMan->ambientStart();
    289294
    290295      string levelFile = "sp_level_moonstation.oxw";
Note: See TracChangeset for help on using the changeset viewer.