Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5386 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Oct 15, 2005, 11:44:14 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: split open the soundengine into
sound_engine: the Handler
sound_source: the sources
sound_buffers: playback-buffers

Location:
trunk/src/lib/sound
Files:
4 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/sound/Makefile.am

    r4750 r5386  
    55
    66libORXsound_a_SOURCES = sound_engine.cc \
     7                        sound_source.cc \
     8                        sound_buffer.cc \
    79                        ogg_player.cc
    810
    911noinst_HEADERS = sound_engine.h \
     12                 sound_source.h \
     13                 sound_buffer.h \
    1014                 ogg_player.h
  • trunk/src/lib/sound/Makefile.in

    r5351 r5386  
    5454libORXsound_a_AR = $(AR) $(ARFLAGS)
    5555libORXsound_a_LIBADD =
    56 am_libORXsound_a_OBJECTS = sound_engine.$(OBJEXT) ogg_player.$(OBJEXT)
     56am_libORXsound_a_OBJECTS = sound_engine.$(OBJEXT) \
     57        sound_source.$(OBJEXT) sound_buffer.$(OBJEXT) \
     58        ogg_player.$(OBJEXT)
    5759libORXsound_a_OBJECTS = $(am_libORXsound_a_OBJECTS)
    5860DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
     
    6062am__depfiles_maybe = depfiles
    6163@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ogg_player.Po \
    62 @AMDEP_TRUE@    ./$(DEPDIR)/sound_engine.Po
     64@AMDEP_TRUE@    ./$(DEPDIR)/sound_buffer.Po \
     65@AMDEP_TRUE@    ./$(DEPDIR)/sound_engine.Po \
     66@AMDEP_TRUE@    ./$(DEPDIR)/sound_source.Po
    6367CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    6468        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    183187noinst_LIBRARIES = libORXsound.a
    184188libORXsound_a_SOURCES = sound_engine.cc \
     189                        sound_source.cc \
     190                        sound_buffer.cc \
    185191                        ogg_player.cc
    186192
    187193noinst_HEADERS = sound_engine.h \
     194                 sound_source.h \
     195                 sound_buffer.h \
    188196                 ogg_player.h
    189197
     
    236244
    237245@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ogg_player.Po@am__quote@
     246@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_buffer.Po@am__quote@
    238247@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_engine.Po@am__quote@
     248@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sound_source.Po@am__quote@
    239249
    240250.cc.o:
  • trunk/src/lib/sound/sound_buffer.cc

    r5382 r5386  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
    1515
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
    1717
    18 #include "proto_class.h"
     18#include "sound_buffer.h"
     19
     20#include "sound_engine.h"
     21
    1922
    2023using namespace std;
    2124
    2225
     26//////////////////
     27/* SOUND-BUFFER */
     28//////////////////
    2329/**
    24  * standard constructor
    25  * @todo this constructor is not jet implemented - do it
    26 */
    27 ProtoClass::ProtoClass ()
     30 *  Creates a Soundbuffer out of an inputfile
     31 * @param fileName The name of the File
     32 */
     33SoundBuffer::SoundBuffer(const char* fileName)
    2834{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     35  this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
     36  this->setName(fileName);
    3037
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
     38  SoundEngine::getInstance()->addBuffer(this);
    3539
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
     40  ALenum format;
     41  ALvoid* data;
     42  ALsizei freq;
     43
     44  ALenum result;
     45
     46  // generate a Buffer
     47  alGenBuffers(1, &this->bufferID);
     48  if ((result = alGetError()) != AL_NO_ERROR)
     49    SoundEngine::PrintALErrorString(result);
     50
     51  // read in the wav data
     52  /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/
     53#ifdef __APPLE__
     54  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq);
     55#elif defined __WIN32__
     56  alutLoadWAVFile(fileName, &format, &data, &size, &freq, &this->loop);
     57#else
     58  alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop);
     59#endif
     60  if ((result = alGetError()) != AL_NO_ERROR)
     61    SoundEngine::PrintALErrorString(result);
     62
     63  // send the loaded wav data to the buffer
     64  alBufferData(this->bufferID, format, data, this->size, freq);
     65  if ((result = alGetError()) != AL_NO_ERROR)
     66    SoundEngine::PrintALErrorString(result);
     67
     68  // remove the wav data (redundant)
     69  alutUnloadWAV(format, data, this->size, freq);
     70  if ((result = alGetError()) != AL_NO_ERROR)
     71    SoundEngine::PrintALErrorString(result);
    4172}
    4273
    43 
    44 /**
    45  * standard deconstructor
    46 */
    47 ProtoClass::~ProtoClass ()
     74SoundBuffer::~SoundBuffer()
    4875{
    49   // delete what has to be deleted here
     76//  SoundEngine::getInstance()->removeBuffer(this);
     77  alDeleteBuffers(1, &this->bufferID);
    5078}
  • trunk/src/lib/sound/sound_buffer.h

    r5382 r5386  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
     2 * @file sound_buffer.h
     3 * @brief Definition of the sound-buffer-class
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _SOUND_BUFFER_H
     7#define _SOUND_BUFFER_H
    88
    99#include "base_object.h"
     10#include "alincl.h"
    1011
    1112// FORWARD DECLARATION
    1213
     14//! A class that represents a datastructure to play Sounds.
     15class SoundBuffer : public BaseObject
     16{
     17  public:
     18    SoundBuffer(const char* fileName);
     19    ~SoundBuffer();
    1320
     21    /** @returns the ID of the buffer used in this SoundBuffer */
     22    inline ALuint getID() const { return this->bufferID; }
    1423
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
     24  private:
     25    ALuint        bufferID;             //!< The address of the Buffer.
    1726
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
    21 
    22 
    23  private:
    24 
     27    ALsizei       size;                 //!< The size of the Buffer.
     28    ALboolean     loop;                 //!< loop information.
    2529};
    2630
    27 #endif /* _PROTO_CLASS_H */
     31#endif /* _SOUND_BUFFER_H */
  • trunk/src/lib/sound/sound_engine.cc

    r5385 r5386  
    1717*/
    1818
    19 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     19#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
    2020
    2121#include "sound_engine.h"
     
    3131
    3232using namespace std;
    33 
    34 //////////////////
    35 /* SOUND-BUFFER */
    36 //////////////////
    37 /**
    38  *  Creates a Soundbuffer out of an inputfile
    39  * @param fileName The name of the File
    40 */
    41 SoundBuffer::SoundBuffer(const char* fileName)
    42 {
    43   this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
    44   this->setName(fileName);
    45 
    46   SoundEngine::getInstance()->addBuffer(this);
    47 
    48   ALenum format;
    49   ALvoid* data;
    50   ALsizei freq;
    51 
    52   ALenum result;
    53 
    54   // generate a Buffer
    55   alGenBuffers(1, &this->bufferID);
    56   if ((result = alGetError()) != AL_NO_ERROR)
    57     SoundEngine::PrintALErrorString(result);
    58 
    59   // read in the wav data
    60   /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/
    61 #ifdef __APPLE__
    62   alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq);
    63 #elif defined __WIN32__
    64   alutLoadWAVFile(fileName, &format, &data, &size, &freq, &this->loop);
    65 #else
    66   alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop);
    67 #endif
    68   if ((result = alGetError()) != AL_NO_ERROR)
    69     SoundEngine::PrintALErrorString(result);
    70 
    71   // send the loaded wav data to the buffer
    72   alBufferData(this->bufferID, format, data, this->size, freq);
    73   if ((result = alGetError()) != AL_NO_ERROR)
    74     SoundEngine::PrintALErrorString(result);
    75 
    76   // remove the wav data (redundant)
    77   alutUnloadWAV(format, data, this->size, freq);
    78   if ((result = alGetError()) != AL_NO_ERROR)
    79     SoundEngine::PrintALErrorString(result);
    80 }
    81 
    82 SoundBuffer::~SoundBuffer()
    83 {
    84 //  SoundEngine::getInstance()->removeBuffer(this);
    85   alDeleteBuffers(1, &this->bufferID);
    86 }
    87 
    88 //////////////////
    89 /* SOUND-SOURCE */
    90 //////////////////
    91 /**
    92  *  creates a SoundSource at position sourceNode with the SoundBuffer buffer
    93 */
    94 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
    95 {
    96   this->setClassID(CL_SOUND_SOURCE, "SoundSource");
    97 
    98   ALenum result;
    99 
    100   // adding the Source to the SourcesList of the SoundEngine
    101   SoundEngine::getInstance()->addSource(this);
    102 
    103   this->buffer = buffer;
    104   this->sourceNode = sourceNode;
    105 
    106   alGenSources(1, &this->sourceID);
    107   if ((result = alGetError()) != AL_NO_ERROR)
    108     SoundEngine::PrintALErrorString(result);
    109   if (this->buffer != NULL)
    110     alSourcei (this->sourceID, AL_BUFFER,   this->buffer->getID());
    111   alSourcef (this->sourceID, AL_PITCH,    1.0      );
    112   alSourcef (this->sourceID, AL_GAIN,     SoundEngine::getInstance()->getEffectsVolume() );
    113   alSourcei (sourceID, AL_LOOPING,  AL_FALSE     );
    114 }
    115 
    116 /**
    117  *  deletes a SoundSource
    118 */
    119 SoundSource::~SoundSource()
    120 {
    121   //SoundEngine::getInstance()->removeSource(this);
    122   alDeleteSources(1, &this->sourceID);
    123 }
    124 
    125 /**
    126  *  Plays back a SoundSource
    127 */
    128 void SoundSource::play()
    129 {
    130   alSourcePlay(this->sourceID);
    131 }
    132 
    133 /**
    134  * Plays back buffer on this Source
    135  * @param buffer the buffer to play back on this Source
    136  */
    137 void SoundSource::play(const SoundBuffer* buffer)
    138 {
    139   alSourceStop(this->sourceID);
    140   alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
    141   alSourcePlay(this->sourceID);
    142 
    143   if (unlikely(this->buffer != NULL))
    144     alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
    145 }
    146 
    147 /**
    148  *  Stops playback of a SoundSource
    149 */
    150 void SoundSource::stop()
    151 {
    152   alSourceStop(this->sourceID);
    153 }
    154 
    155 /**
    156  *  Pauses Playback of a SoundSource
    157 */
    158 void SoundSource::pause()
    159 {
    160   alSourcePause(this->sourceID);
    161 }
    162 
    163 /**
    164  *  Rewinds Playback of a SoundSource
    165 */
    166 void SoundSource::rewind()
    167 {
    168   alSourceRewind(this->sourceID);
    169 }
    170 
    171 /**
    172  *  sets the RolloffFactor of the Sound emitted from the SoundSource
    173  * @param rolloffFactor The Factor described
    174 
    175    this tells openAL how fast the Sounds decay outward from the Source
    176 */
    177 void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
    178 {
    179   alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
    180 }
    181 
    18233
    18334
     
    439290  const char* devWalk = deviceList;
    440291  if (alcIsExtensionPresent(NULL, (ALubyte*)"ALC_ENUMERATION_EXT") == AL_TRUE) { // try out enumeration extension
    441     printf("Enumeration-extension found\n");
    442 
    443     printf("Default device: %s\n", defaultDevice);
     292    PRINTF(3)("Enumeration-extension found\n");
     293
     294    PRINTF(3)("Default device: %s\n", defaultDevice);
    444295    do
    445296    {
    446       printf("%s\n", devWalk);
     297      PRINTF(3)("%s\n", devWalk);
    447298      devWalk += strlen(devWalk)+1;
    448299    } while (devWalk[0] != '\0');
  • trunk/src/lib/sound/sound_engine.h

    r5216 r5386  
    1010#include "alincl.h"
    1111
     12#include "sound_buffer.h"
     13#include "sound_source.h"
     14
    1215#define SOUND_DOPPLER_FACTOR       0.001          //!< A factor for the audible doppler effect
    1316#define SOUND_DOPPLER_VELOCITY     5000000        //!< A factor for the TravelSpeed of sound
     
    1720template<class T> class tList;
    1821class IniParser;
    19 
    20 
    21 //! A class that represents a datastructure to play Sounds.
    22 class SoundBuffer : public BaseObject
    23 {
    24   public:
    25     SoundBuffer(const char* fileName);
    26     ~SoundBuffer();
    27 
    28     /** @returns the ID of the buffer used in this SoundBuffer */
    29     inline ALuint getID() const { return this->bufferID; }
    30 
    31   private:
    32     ALuint        bufferID;             //!< The address of the Buffer.
    33 
    34     ALsizei       size;                 //!< The size of the Buffer.
    35     ALboolean     loop;                 //!< loop information.
    36 };
    37 
    38 //! A class that represents a SoundSource
    39 class SoundSource : public BaseObject
    40 {
    41   public:
    42     SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
    43     ~SoundSource();
    44 
    45   // user interaction
    46     void play();
    47     void play(const SoundBuffer* buffer);
    48     void stop();
    49     void pause();
    50     void rewind();
    51 
    52   // development functions
    53     /** @returns The ID of this Source */
    54     inline ALuint getID() const { return this->sourceID; }
    55     /** @returns the SoundBuffer of this Source */
    56     inline const SoundBuffer* getBuffer() const { return this->buffer; }
    57     /** @returns the SourceNode of this Source */
    58     inline const PNode* getNode() const { return this->sourceNode;}
    59 
    60     void setRolloffFactor(ALfloat rolloffFactor);
    61 
    62   private:
    63     ALuint                 sourceID;              //!< The ID of the Source
    64     const SoundBuffer*     buffer;                //!< The buffer to play in this source.
    65     const PNode*           sourceNode;            //!< The SourceNode represente the position/velocity... of this source.
    66 };
    67 
    68 
    6922
    7023//! A class that handles audio via the openAudioLibrary
  • trunk/src/lib/sound/sound_source.cc

    r5382 r5386  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
    1515
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
    1717
    18 #include "proto_class.h"
     18#include "sound_source.h"
     19#include "sound_engine.h"
     20#include "alincl.h"
     21#include "compiler.h"
    1922
    2023using namespace std;
    2124
     25/**
     26 *  creates a SoundSource at position sourceNode with the SoundBuffer buffer
     27 */
     28SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
     29{
     30  this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     31
     32  ALenum result;
     33
     34  // adding the Source to the SourcesList of the SoundEngine
     35  SoundEngine::getInstance()->addSource(this);
     36
     37  this->buffer = buffer;
     38  this->sourceNode = sourceNode;
     39
     40  alGenSources(1, &this->sourceID);
     41  if ((result = alGetError()) != AL_NO_ERROR)
     42    SoundEngine::PrintALErrorString(result);
     43  if (this->buffer != NULL)
     44    alSourcei (this->sourceID, AL_BUFFER,   this->buffer->getID());
     45  alSourcef (this->sourceID, AL_PITCH,    1.0      );
     46  alSourcef (this->sourceID, AL_GAIN,     SoundEngine::getInstance()->getEffectsVolume() );
     47  alSourcei (sourceID, AL_LOOPING,  AL_FALSE     );
     48}
    2249
    2350/**
    24  * standard constructor
    25  * @todo this constructor is not jet implemented - do it
    26 */
    27 ProtoClass::ProtoClass ()
     51 *  deletes a SoundSource
     52 */
     53SoundSource::~SoundSource()
    2854{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
    30 
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    35 
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
     55  //SoundEngine::getInstance()->removeSource(this);
     56  alDeleteSources(1, &this->sourceID);
    4157}
    4258
     59/**
     60 *  Plays back a SoundSource
     61 */
     62void SoundSource::play()
     63{
     64  alSourcePlay(this->sourceID);
     65}
    4366
    4467/**
    45  * standard deconstructor
    46 */
    47 ProtoClass::~ProtoClass ()
     68 * Plays back buffer on this Source
     69 * @param buffer the buffer to play back on this Source
     70 */
     71void SoundSource::play(const SoundBuffer* buffer)
    4872{
    49   // delete what has to be deleted here
     73  alSourceStop(this->sourceID);
     74  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     75  alSourcePlay(this->sourceID);
     76
     77  if (unlikely(this->buffer != NULL))
     78    alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
    5079}
     80
     81/**
     82 *  Stops playback of a SoundSource
     83 */
     84void SoundSource::stop()
     85{
     86  alSourceStop(this->sourceID);
     87}
     88
     89/**
     90 *  Pauses Playback of a SoundSource
     91 */
     92void SoundSource::pause()
     93{
     94  alSourcePause(this->sourceID);
     95}
     96
     97/**
     98 *  Rewinds Playback of a SoundSource
     99 */
     100void SoundSource::rewind()
     101{
     102  alSourceRewind(this->sourceID);
     103}
     104
     105/**
     106 *  sets the RolloffFactor of the Sound emitted from the SoundSource
     107 * @param rolloffFactor The Factor described
     108
     109   this tells openAL how fast the Sounds decay outward from the Source
     110 */
     111void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
     112{
     113  alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
     114}
     115
  • trunk/src/lib/sound/sound_source.h

    r5382 r5386  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
     2 * @file sound_source.h
     3 * @brief Definition of the SoundSource.
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _SOUND_SOURCE_H
     7#define _SOUND_SOURCE_H
    88
    99#include "base_object.h"
     10#include "alincl.h"
    1011
    1112// FORWARD DECLARATION
     13class SoundBuffer;
     14class PNode;
    1215
     16//! A class that represents a SoundSource
     17class SoundSource : public BaseObject
     18{
     19  public:
     20    SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
     21    ~SoundSource();
    1322
     23  // user interaction
     24    void play();
     25    void play(const SoundBuffer* buffer);
     26    void stop();
     27    void pause();
     28    void rewind();
    1429
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
     30  // development functions
     31    /** @returns The ID of this Source */
     32    inline ALuint getID() const { return this->sourceID; }
     33    /** @returns the SoundBuffer of this Source */
     34    inline const SoundBuffer* getBuffer() const { return this->buffer; }
     35    /** @returns the SourceNode of this Source */
     36    inline const PNode* getNode() const { return this->sourceNode;}
    1737
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     38    void setRolloffFactor(ALfloat rolloffFactor);
    2139
    22 
    23  private:
    24 
     40  private:
     41    ALuint                 sourceID;              //!< The ID of the Source
     42    const SoundBuffer*     buffer;                //!< The buffer to play in this source.
     43    const PNode*           sourceNode;            //!< The SourceNode represente the position/velocity... of this source.
    2544};
    26 
    27 #endif /* _PROTO_CLASS_H */
     45#endif /* _SOUND_SOURCE_H */
Note: See TracChangeset for help on using the changeset viewer.