Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 338


Ignore:
Timestamp:
Nov 28, 2007, 6:17:23 PM (16 years ago)
Author:
nicolape
Message:

Added AudioObject Class

Location:
code/branches/audio/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/audio/src/audio/Ambient.cc

    r335 r338  
    11#include <iostream>
     2#include <string>
    23#include "Ambient.h"
    3 #include "../../include/AL/al.h"
    4 #include "../../include/AL/alc.h"
    5 #include "../../include/AL/alut.h"
    64
    75namespace audio
    86{
    9         Ambient::Ambient()
     7        Ambient::Ambient(std::string audioFile)
    108        {
    11                 SourcePos[0]=0;
    12                 SourcePos[1]=0;
    13                 SourcePos[2]=0;
    14 
    15                  SourceVel[0]=0;
    16                  SourceVel[1]=0;
    17                  SourceVel[2]=0;
    18 
    19                  ListenerPos[0]=0;
    20                  ListenerPos[1]=0;
    21                  ListenerPos[2]=0;
    22 
    23                  ListenerVel[0]=0;
    24                  ListenerVel[1]=0;
    25                  ListenerVel[2]=0;
    26 
    27                  ListenerOri[0]=0;
    28                  ListenerOri[1]=0;
    29                  ListenerOri[2]=-1;
    30                  ListenerOri[3]=0;
    31                  ListenerOri[4]=1;
    32                  ListenerOri[5]=0;
    33 
    34 
    35         // Initialize OpenAL and clear the error bit.
    36 
    37         alutInit(NULL, 0);
    38         alGetError();
    39 
    40         // Load the wav data.
    41 
    42         if(LoadALData() == AL_FALSE)
    43         {
    44             printf("Error loading sound data.");
     9                a = new AudioObject(audioFile);
     10        }
     11       
     12        Ambient::~Ambient()
     13        {       
    4514               
    4615        }
    47 
    48         SetListenerValues();
    49 
    50         // Setup an exit procedure.
    51 
    52         //atexit(KillALData);
    53 
    54                 std::cout << "Play sone ambient background sound";
    55         }
    5616       
    57         ALboolean Ambient::LoadALData()
    58         {
    59                 ALenum format;
    60                 ALsizei size;
    61                 ALvoid* data;
    62                 ALsizei freq;
    63                 ALboolean loop;
    64        
    65        
    66                 alGenBuffers(1, &Buffer);
    67        
    68                 if(alGetError() != AL_NO_ERROR)
    69                         return AL_FALSE;
    70        
    71                 alutLoadWAVFile((ALbyte*)"wavdata/pirate.wav", &format, &data, &size, &freq, &loop);
    72                 alBufferData(Buffer, format, data, size, freq);
    73                 alutUnloadWAV(format, data, size, freq);
    74        
    75                 alGenSources(1, &Source);
    76        
    77                 if(alGetError() != AL_NO_ERROR)
    78                         return AL_FALSE;
    79        
    80                 alSourcei (Source, AL_BUFFER,   Buffer   );
    81                 alSourcef (Source, AL_PITCH,    1.0      );
    82                 alSourcef (Source, AL_GAIN,     1.0      );
    83                 alSourcefv(Source, AL_POSITION, SourcePos);
    84                 alSourcefv(Source, AL_VELOCITY, SourceVel);
    85                 alSourcei (Source, AL_LOOPING,  loop     );
    86        
    87                 if(alGetError() == AL_NO_ERROR)
    88                         return AL_TRUE;
    89        
    90        
    91                 return AL_FALSE;
    92         }       
    93 
    94         void Ambient::SetListenerValues()
    95         {
    96                 alListenerfv(AL_POSITION,    ListenerPos);
    97                 alListenerfv(AL_VELOCITY,    ListenerVel);
    98                 alListenerfv(AL_ORIENTATION, ListenerOri);
    99         }
    100        
    101         void Ambient::KillALData()
    102         {
    103                 alDeleteBuffers(1, &Buffer);
    104                 alDeleteSources(1, &Source);
    105                 alutExit();
    106         }
    107 
    10817        void Ambient::play()
    10918        {
    110                 alSourcePlay(Source);
    111        
     19                a->play();     
    11220        }
    11321}
  • code/branches/audio/src/audio/Ambient.h

    r334 r338  
    77#include "../../include/AL/alut.h"
    88
     9#include "AudioObject.h"
    910
    1011namespace audio
     
    1314        {
    1415        public:
    15                 Ambient();
     16                Ambient(std::string audioFile);
     17                ~Ambient();
    1618                void play();
    1719        private:
    18                 ALboolean LoadALData();
    19                 void SetListenerValues();
    20                 void KillALData();
    21 
    22                 ALuint Buffer;
    23                 ALuint Source;
    24                 ALfloat SourcePos[3];
    25                 ALfloat SourceVel[3];
    26                 ALfloat ListenerPos[3];
    27                 ALfloat ListenerVel[3];
    28                 ALfloat ListenerOri[6];
     20                AudioObject* a;
    2921        };
    30        
    31        
    32        
    33        
    34        
    3522}
    3623
  • code/branches/audio/src/audio/CMakeLists.txt

    r334 r338  
    11PROJECT(Orxonox)
    22
    3 SET(SRC_FILES Ambient.cc)
    4 SET(INC_FILES Ambient.h)
     3SET(SRC_FILES
     4        Ambient.cc
     5        AudioObject.cc
     6)
     7SET(INC_FILES
     8        Ambient.h
     9        AudioObject.h
     10)
    511
    612
  • code/branches/audio/src/orxonox/orxonox.cc

    r334 r338  
    191191      void createScene(void)
    192192      {
    193                                 audio::Ambient* bgsound = new audio::Ambient();
    194                                 bgsound->play();
     193                audio::Ambient* bgsound = new audio::Ambient("wavdata/pirate.wav");
     194                bgsound->play();
    195195                                       
    196196        string levelFile = "sp_level_moonstation.oxw";
Note: See TracChangeset for help on using the changeset viewer.