Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/sound


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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

Legend:

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

    r5475 r9869  
    77                        sound_source.cc \
    88                        sound_buffer.cc \
     9                        sound_buffer_data.cc \
     10                        resource_sound_buffer.cc \
    911                        ogg_player.cc
    1012
     
    1214                 sound_source.h \
    1315                 sound_buffer.h \
     16                 sound_buffer_data.h \
     17                 resource_sound_buffer.h \
    1418                 ogg_player.h
  • trunk/src/lib/sound/ogg_player.cc

    r9406 r9869  
    3434
    3535#include "helper_functions.h"
    36 
    37 #ifdef HAVE_SDL_SDL_H
    38 
    39 #include <SDL/SDL.h>
    40 #include <SDL/SDL_endian.h>
    41 
    42 #else
    43 
    44 #include <SDL.h>
    45 #include <SDL_endian.h>
    46 
    47 #endif
     36#include "sdlincl.h"
    4837
    4938namespace OrxSound
    5039{
     40  ObjectListDefinition(OggPlayer);
    5141  /**
    5242   * initializes an Ogg-player from a file
     
    5545  OggPlayer::OggPlayer(const std::string& fileName)
    5646  {
    57     this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer");
     47    this->registerObject(this, OggPlayer::_objectList);
    5848
    5949    this->state = OggPlayer::None;
     
    276266        ogg->update();
    277267      }
    278       SDL_Delay(10);
     268      SDL_Delay(1);
    279269    }
    280270    PRINTF(4)("End the AudioThread\n");
  • trunk/src/lib/sound/ogg_player.h

    r9019 r9869  
    1313#include <ogg/ogg.h>
    1414#include <vorbis/vorbisfile.h>
    15 #include "threading.h"
     15#include "util/threading.h"
    1616
    1717struct File;
     
    2525  class OggPlayer : public BaseObject
    2626  {
     27    ObjectListDeclaration(OggPlayer);
     28
    2729  public:
    2830    /**
     
    98100
    99101
    100     std::string         _title;
    101     std::string         _artist;
    102     std::string         _album;
    103     std::string         _vendor;
     102    std::string         _title;               //!< Song Title.
     103    std::string         _artist;              //!< Artist Name of the current song.
     104    std::string         _album;               //!< Album Name of the current song.
     105    std::string         _vendor;              //!< Vendor Name of the current song.
    104106  };
    105107
  • trunk/src/lib/sound/sound_buffer.cc

    r8971 r9869  
    1818#include "sound_buffer.h"
    1919
    20 #include "sound_engine.h"
    2120
    22 #include "sdlincl.h"
    23 #include <cassert>
    24 #include "debug.h"
    25 #include "sys/stat.h"
    26 #include "helper_functions.h"
    27 
    28 #ifdef HAVE_SDL_SDL_H
    29 #include <SDL/SDL.h>
    30 #include <SDL/SDL_endian.h>
    31 #else
    32 #include <SDL.h>
    33 #include <SDL_endian.h>
    34 #endif
    3521namespace OrxSound
    3622{
     23  ObjectListDefinition(SoundBuffer);
    3724  //////////////////
    3825  /* SOUND-BUFFER */
    3926  //////////////////
     27  SoundBuffer::SoundBuffer()
     28      : data(new SoundBufferData)
     29  {
     30    this->registerObject(this, SoundBuffer::_objectList);
     31  }
    4032  /**
    41    * Creates a Soundbuffer out of an inputfile
     33   * @brief Creates a Soundbuffer out of an inputfile
    4234   * @param fileName The name of the File
    4335   */
    4436  SoundBuffer::SoundBuffer(const std::string& fileName)
     37      : data(new SoundBufferData)
    4538  {
    46     this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
    47     this->setName(fileName);
     39    this->registerObject(this, SoundBuffer::_objectList);
     40    this->load(fileName);
     41  }
    4842
    49     // generate a Buffer
    50     alGenBuffers(1, &this->bufferID);
    51     SoundEngine::checkError("Generate Buffer", __LINE__);
    52     if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV"))
    53     {
    54       this->loadWAV(fileName);
    55     }
    56     else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG"))
    57       this->loadOGG(fileName);
     43  SoundBuffer::SoundBuffer(const SoundBuffer& buffer)
     44      : data(buffer.data)
     45  {
     46    this->registerObject(this, SoundBuffer::_objectList);
     47  }
    5848
    59   }
     49  SoundBuffer::SoundBuffer(const SoundBufferData::Pointer& dataPointer)
     50      : data(dataPointer)
     51  {
     52    this->registerObject(this, SoundBuffer::_objectList);
     53  };
    6054
    6155  SoundBuffer::~SoundBuffer()
    6256  {
    63     //  SoundEngine::getInstance()->removeBuffer(this);
    64     alDeleteBuffers(1, &this->bufferID);
    65     SoundEngine::checkError("SoundBuffer: Delete Buffer", __LINE__);
    6657  }
    6758
    68   /**
    69    * @brief loads a Waveform from the local fileSystem into this Source.
    70    * @param fileName the Name of the File to Load.
    71    * @returns true on success.
    72    */
    73   bool SoundBuffer::loadWAV(const std::string& fileName)
    74   {
    75     SDL_AudioSpec wavSpec;
    76     Uint32 wavLength;
    77     Uint8 *wavBuffer;
    78 
    79     /* Load the WAV */
    80     if( SDL_LoadWAV(fileName.c_str(), &wavSpec, &wavBuffer, &wavLength) == NULL)
    81     {
    82       PRINTF(2)("Could not open %s: %s\n", fileName.c_str(), SDL_GetError());
    83       return false;
    84     }
    85 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    86     if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) )
    87     {
    88       int cnt = wavLength/2;
    89       Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer;
    90       for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts )
    91         *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts );
    92     }
    93 #endif
    94     alBufferData(this->bufferID, SoundBuffer::sdlAudioSpecToAlFormat(&wavSpec),
    95                  wavBuffer, wavLength, wavSpec.freq);
    96 
    97     SDL_FreeWAV(wavBuffer);
    98     if (SoundEngine::checkError("Could not load Wave file", __LINE__))
    99       return true;
    100     else
    101       return false;
    102   }
    103 
    104 
    105 #ifndef AL_FORMAT_VORBIS_EXT
    106 #define AL_FORMAT_VORBIS_EXT 0x100030
    107 #endif
    108   /**
    109    * @brief loads an OGG-file into a SOundBuffer
    110    * @param fileName the Name of the File to load.
    111    * @returns true on success (file exists and is fully loaded), false otherwise.
    112    */
    113   bool SoundBuffer::loadOGG(const std::string& fileName)
    114   {
    115     void*     ovdata;
    116     FILE*     fh;
    117 
    118     fh = fopen( fileName.c_str() , "rb") ;
    119     if( fh != NULL )
    120     {
    121       struct stat sbuf ;
    122 
    123       if(stat( fileName.c_str(), &sbuf ) != -1)
    124       {
    125         ovdata = malloc(sbuf.st_size);
    126         if(ovdata != NULL)
    127         {
    128           fread( ovdata, 1, sbuf.st_size, fh);
    129 
    130           alBufferData( this->bufferID,
    131                         AL_FORMAT_VORBIS_EXT,
    132                         ovdata,
    133                         sbuf.st_size,
    134                         1) ;
    135           SoundEngine::checkError("Could not load OGG file", __LINE__);
    136 
    137           free(ovdata);
    138         }
    139         fclose(fh);
    140       }
    141       else
    142         return false;
    143     }
    144     else
    145       return false;
    146 
    147     return true ;
    148 
    149   }
    150 
    151 
    152   /**
    153    * @brief converts an SDL_AudioSpec into a valid OpenAL AUDIO_FORMAT enumerator
    154    * @param audiospec the AudioSpec to convert.
    155    * @returns the AL_FORMAT
    156    */
    157   ALenum SoundBuffer::sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec)
    158   {
    159     assert (audiospec != NULL);
    160     bool stereo = true;
    161     bool is16Bit = true;
    162     if (audiospec->format == AUDIO_U8 || audiospec->format == AUDIO_S8)
    163       is16Bit = false;
    164     if (audiospec->channels == 1)
    165       stereo = false;
    166 
    167     if (!stereo && !is16Bit)
    168       return AL_FORMAT_MONO8;
    169     else if (!stereo && is16Bit)
    170       return AL_FORMAT_MONO16;
    171     else if (stereo && !is16Bit)
    172       return AL_FORMAT_STEREO8;
    173     else /* if (stereo && is16Bit) */
    174       return AL_FORMAT_STEREO16;
    175   }
    17659}
  • trunk/src/lib/sound/sound_buffer.h

    r8969 r9869  
    88
    99#include "base_object.h"
    10 #include "alincl.h"
    11 
    12 // FORWARD DECLARATION
    13 typedef struct SDL_AudioSpec;
     10#include "sound_buffer_data.h"
    1411
    1512namespace OrxSound
    1613{
    1714  //! A class that represents a datastructure to play Sounds.
    18   class SoundBuffer : public BaseObject
     15  class SoundBuffer : virtual public BaseObject
    1916  {
     17    ObjectListDeclaration(SoundBuffer);
    2018  public:
     19    SoundBuffer();
     20    SoundBuffer(const SoundBuffer& buffer);
     21    SoundBuffer(const SoundBufferData::Pointer& dataPointer);
    2122    SoundBuffer(const std::string& fileName);
    2223    virtual ~SoundBuffer();
    2324
    24     bool loadWAV(const std::string& fileName);
    25     bool loadOGG(const std::string& fileName);
     25    /** @brief assignment operator */
     26    SoundBuffer& operator=(const SoundBuffer& buffer) { this->data = buffer.data; return *this; };
     27    bool operator==(const SoundBuffer& buffer) const {return this->data == buffer.data; };
     28
     29    /** @see SoundBufferData::load */
     30    inline bool load(const std::string& fileName) { return this->data->load(fileName); };
     31    /** @see SoundBufferData::loadWav */
     32    inline bool loadWAV(const std::string& fileName) { return this->data->loadWAV(fileName); };
     33    /** @see SoundBufferData::loadOgg */
     34    inline bool loadOGG(const std::string& fileName) { return this->data->loadOGG(fileName); };
    2635
    2736    /** @returns the ID of the buffer used in this SoundBuffer */
    28     inline ALuint getID() const { return this->bufferID; }
     37    inline ALuint getID() const { return this->data->getID(); }
     38    inline bool loaded() const { return this->data->loaded(); }
     39
     40    /** @returns the DataPointer */
     41    const SoundBufferData::Pointer& dataPointer() const { return data; }
     42    /** @param dataPointer the data to acquire @brief Buffer shall acquire dataPointers data */
     43    void acquireData(const SoundBufferData::Pointer& dataPointer)  { data = dataPointer; };
    2944
    3045  private:
    31     ALenum sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec);
    32 
    33   private:
    34     ALuint        bufferID;             //!< The address of the Buffer.
    35 
    36     ALsizei       size;                 //!< The size of the Buffer.
    37     ALboolean     loop;                 //!< loop information.
     46    SoundBufferData::Pointer    data;                //!< Pointer to the Stored Data
    3847  };
    3948}
  • trunk/src/lib/sound/sound_engine.cc

    r9235 r9869  
    2121#include "sound_engine.h"
    2222
    23 #include "class_list.h"
    24 
    2523#include "p_node.h"
    26 #include "util/loading/resource_manager.h"
    2724#include "debug.h"
    28 #include "util/preferences.h"
     25#include "parser/preferences/preferences.h"
    2926#include "globals.h"
     27#include "resource_sound_buffer.h"
    3028
    3129namespace OrxSound
    3230{
    33 
     31  ObjectListDefinition(SoundEngine);
    3432  //////////////////
    3533  /* SOUND-ENGINE */
     
    4038  SoundEngine::SoundEngine ()
    4139  {
    42     this->setClassID(CL_SOUND_ENGINE, "SoundEngine");
     40    this->registerObject(this, SoundEngine::_objectList);
    4341    this->setName("SoundEngine");
    4442
    4543    this->listener = NULL;
    46     this->bufferList = NULL;
    47     this->sourceList = NULL;
    4844
    4945    this->device = NULL;
     
    6965  {
    7066    // deleting all the SoundSources
    71     if(this->sourceList != NULL)
    72     {
    73       while (this->sourceList->size() > 0)
    74         delete static_cast<SoundSource*>(this->sourceList->front());
    75     }
     67    while (!SoundSource::objectList().empty())
     68      delete (SoundSource::objectList().front());
    7669
    7770    while(!this->ALSources.empty())
     
    8982
    9083    // deleting all the SoundBuffers
    91     if (this->bufferList != NULL)
    92     {
    93       while(this->bufferList->size() > 0)
    94         ResourceManager::getInstance()->unload(static_cast<SoundBuffer*>(this->bufferList->front()));
    95     }
     84    //    while(!SoundBuffer::objectList().empty())
     85    //ResourceManager::getInstance()->unload(SoundBuffer::objectList().front());
    9686
    9787    // removing openAL from AudioResource
     
    129119  SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode)
    130120  {
    131     SoundBuffer* buffer = NULL;
     121    SoundBuffer buffer;
    132122    if (!fileName.empty())
    133123    {
    134       buffer= (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL);
    135       if (buffer == NULL)
     124      buffer = ResourceSoundBuffer(fileName);
     125      if (!buffer.loaded())
    136126        PRINTF(2)("Wav-Sound %s could not be loaded onto new Source\n", fileName.c_str());
    137127    }
     
    212202
    213203    // updating all the Sources positions
    214     if (likely(this->sourceList != NULL || (this->sourceList = ClassList::getList(CL_SOUND_SOURCE)) != NULL))
    215     {
    216       std::list<BaseObject*>::const_iterator sourceIT;
    217       SoundSource* source;
    218       for (sourceIT = this->sourceList->begin(); sourceIT != this->sourceList->end(); sourceIT++)
     204    ObjectList<SoundSource>::const_iterator sourceIT;
     205    for (sourceIT = SoundSource::objectList().begin();
     206         sourceIT != SoundSource::objectList().end();
     207         sourceIT++)
     208    {
     209      if ((*sourceIT)->isPlaying())
    219210      {
    220         source = static_cast<SoundSource*>(*sourceIT);
    221         if (source->isPlaying())
     211        int play = 0x000;
     212        alGetSourcei((*sourceIT)->getID(), AL_SOURCE_STATE, &play);
     213        if (DEBUG_LEVEL > 2)
     214          SoundEngine::checkError("SoundEngine::update() Play", __LINE__);
     215        if(play == AL_PLAYING)
    222216        {
    223           int play = 0x000;
    224           alGetSourcei(source->getID(), AL_SOURCE_STATE, &play);
    225           if (DEBUG_LEVEL > 2)
    226             SoundEngine::checkError("SoundEngine::update() Play", __LINE__);
    227           if(play == AL_PLAYING)
     217          if (likely((*sourceIT)->getNode() != NULL))
    228218          {
    229             if (likely(source->getNode() != NULL))
    230             {
    231               alSource3f(source->getID(), AL_POSITION,
    232                          source->getNode()->getAbsCoor().x,
    233                          source->getNode()->getAbsCoor().y,
    234                          source->getNode()->getAbsCoor().z);
    235               if (DEBUG_LEVEL > 2)
    236                 SoundEngine::checkError("SoundEngine::update() Set Source Position", __LINE__);
    237               alSource3f(source->getID(), AL_VELOCITY,
    238                          source->getNode()->getVelocity().x,
    239                          source->getNode()->getVelocity().y,
    240                          source->getNode()->getVelocity().z);
    241               if (DEBUG_LEVEL > 2)
    242                 SoundEngine::checkError("SoundEngine::update() Set Source Velocity", __LINE__);
    243             }
     219            alSource3f((*sourceIT)->getID(), AL_POSITION,
     220                       (*sourceIT)->getNode()->getAbsCoor().x,
     221                       (*sourceIT)->getNode()->getAbsCoor().y,
     222                       (*sourceIT)->getNode()->getAbsCoor().z);
     223            if (DEBUG_LEVEL > 2)
     224              SoundEngine::checkError("SoundEngine::update() Set Source Position", __LINE__);
     225            alSource3f((*sourceIT)->getID(), AL_VELOCITY,
     226                       (*sourceIT)->getNode()->getVelocity().x,
     227                       (*sourceIT)->getNode()->getVelocity().y,
     228                       (*sourceIT)->getNode()->getVelocity().z);
     229            if (DEBUG_LEVEL > 2)
     230              SoundEngine::checkError("SoundEngine::update() Set Source Velocity", __LINE__);
    244231          }
    245           else
    246           {
    247             source->stop();
    248           }
     232        }
     233        else
     234        {
     235          (*sourceIT)->stop();
    249236        }
    250237      }
     
    393380      default:
    394381      case AL_NO_ERROR:
    395         return ("AL_NO_ERROR");
     382      return ("AL_NO_ERROR");
    396383      case AL_INVALID_NAME:
    397         return ("AL_INVALID_NAME");
     384      return ("AL_INVALID_NAME");
    398385      case AL_INVALID_ENUM:
    399         return ("AL_INVALID_ENUM");
     386      return ("AL_INVALID_ENUM");
    400387      case AL_INVALID_VALUE:
    401         return ("AL_INVALID_VALUE");
     388      return ("AL_INVALID_VALUE");
    402389      case AL_INVALID_OPERATION:
    403         return ("AL_INVALID_OPERATION");
     390      return ("AL_INVALID_OPERATION");
    404391      case AL_OUT_OF_MEMORY:
    405         return ("AL_OUT_OF_MEMORY");
     392      return ("AL_OUT_OF_MEMORY");
    406393    };
    407394  }
     
    414401      default:
    415402      case ALC_NO_ERROR:
    416         return ("AL_NO_ERROR");
     403      return ("AL_NO_ERROR");
    417404      case ALC_INVALID_DEVICE:
    418         return ("ALC_INVALID_DEVICE");
     405      return ("ALC_INVALID_DEVICE");
    419406      case ALC_INVALID_CONTEXT:
    420         return("ALC_INVALID_CONTEXT");
     407      return("ALC_INVALID_CONTEXT");
    421408      case ALC_INVALID_ENUM:
    422         return("ALC_INVALID_ENUM");
     409      return("ALC_INVALID_ENUM");
    423410      case ALC_INVALID_VALUE:
    424         return ("ALC_INVALID_VALUE");
     411      return ("ALC_INVALID_VALUE");
    425412      case ALC_OUT_OF_MEMORY:
    426         return("ALC_OUT_OF_MEMORY");
     413      return("ALC_OUT_OF_MEMORY");
    427414    };
    428415  }
  • trunk/src/lib/sound/sound_engine.h

    r7847 r9869  
    2727  class SoundEngine : public BaseObject
    2828  {
    29   public:
     29    ObjectListDeclaration(SoundEngine);
     30    public:
    3031    virtual ~SoundEngine();
    3132    /** @returns a Pointer to the only object of this Class */
     
    7576    const PNode*                   listener;                 //!< The listener of the Scene
    7677
    77     const std::list<BaseObject*>*  bufferList;               //!< A list of buffers
    78     const std::list<BaseObject*>*  sourceList;               //!< A list for all the sources in the scene.
    79 
    8078    unsigned int                   maxSourceCount;           //!< How many Sources is the Maximum
    8179    std::stack<ALuint>             ALSources;                //!< A list of real openAL-Sources, the engine allocates, and stores for reuse.
  • trunk/src/lib/sound/sound_source.cc

    r8969 r9869  
    1919#include "sound_engine.h"
    2020
    21 #include "alincl.h"
    2221#include "compiler.h"
    2322#include "debug.h"
     
    2524namespace OrxSound
    2625{
     26  ObjectListDefinition(SoundSource);
    2727  /**
    2828  * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer
    2929  */
    30   SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
    31   {
    32     this->setClassID(CL_SOUND_SOURCE, "SoundSource");
    33 
     30  SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer& buffer)
     31  {
     32    this->registerObject(this, SoundSource::_objectList);
    3433    // adding the Source to the SourcesList of the SoundEngine
    3534    this->buffer = buffer;
     
    5150  SoundSource::SoundSource(const SoundSource& source)
    5251  {
    53     this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     52    this->registerObject(this, SoundSource::_objectList);
    5453
    5554    // adding the Source to the SourcesList of the SoundEngine
     
    120119  void SoundSource::play()
    121120  {
    122     if (this->buffer && this->retrieveSource())
     121    if (this->retrieveSource())
    123122    {
    124123      if (this->bPlay)
    125124        alSourceStop(this->sourceID);
    126125
    127       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     126      alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID());
    128127      alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
    129128      alSourcef (this->sourceID, AL_GAIN, 1);
     
    141140  * @param buffer the buffer to play back on this Source
    142141  */
    143   void SoundSource::play(const SoundBuffer* buffer)
     142  void SoundSource::play(const SoundBuffer& buffer)
    144143  {
    145144    if (!this->retrieveSource())
     
    150149
    151150    alSourceStop(this->sourceID);
    152     alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     151    alSourcei (this->sourceID, AL_BUFFER, buffer.getID());
    153152    alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
    154153    alSourcef (this->sourceID, AL_GAIN, 1);
     
    156155    alSourcePlay(this->sourceID);
    157156
    158     if (unlikely(this->buffer != NULL))
    159       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     157    if (unlikely(this->buffer.getID() != 0))
     158      alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID());
    160159    this->bPlay = true;
    161160
     
    170169   * @param gain the gain of the sound buffer
    171170  */
    172   void SoundSource::play(const SoundBuffer* buffer, float gain)
     171  void SoundSource::play(const SoundBuffer& buffer, float gain)
    173172  {
    174173    if (!this->retrieveSource())
     
    179178
    180179    alSourceStop(this->sourceID);
    181     alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     180    alSourcei (this->sourceID, AL_BUFFER, buffer.getID());
    182181    alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
    183182    alSourcef (this->sourceID, AL_GAIN, gain);
     
    185184    alSourcePlay(this->sourceID);
    186185
    187     if (unlikely(this->buffer != NULL))
    188       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     186    if (unlikely(this->buffer.getID() != 0))
     187      alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID());
    189188    this->bPlay = true;
    190189
     
    199198   * @param loop if true, sound gets looped
    200199   */
    201   void SoundSource::play(const SoundBuffer* buffer, float gain, bool loop)
     200  void SoundSource::play(const SoundBuffer& buffer, float gain, bool loop)
    202201  {
    203202    if (!this->retrieveSource())
     
    208207
    209208    alSourceStop(this->sourceID);
    210     alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     209    alSourcei (this->sourceID, AL_BUFFER, buffer.getID());
    211210
    212211    if (loop)
     
    219218    alSourcePlay(this->sourceID);
    220219
    221     if (unlikely(this->buffer != NULL))
    222       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     220    if (unlikely(this->buffer.getID() != 0))
     221      alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID());
    223222    this->bPlay = true;
    224223
     
    232231   * @param gain the new gain value
    233232   */
    234   void SoundSource::gain(const SoundBuffer* buffer, float gain)
     233  void SoundSource::gain(const SoundBuffer& buffer, float gain)
    235234  {
    236235    // alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     
    347346  * @param duration time perios to fade in
    348347  */
    349   void SoundSource::fadein(const SoundBuffer* buffer, ALfloat duration)
     348  void SoundSource::fadein(const SoundBuffer& buffer, ALfloat duration)
    350349  {
    351350    //if (this->buffer && this->retrieveSource())
  • trunk/src/lib/sound/sound_source.h

    r8793 r9869  
    88
    99#include "base_object.h"
     10#include "sound_buffer.h"
    1011#include "alincl.h"
    1112
     
    1415namespace OrxSound
    1516{
    16   class SoundBuffer;
    1717  //! A class that represents a SoundSource
    1818  class SoundSource : public BaseObject
    1919  {
     20    ObjectListDeclaration(SoundSource);
    2021  public:
    21     SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
     22    SoundSource(const PNode* sourceNode = NULL, const SoundBuffer& buffer = SoundBuffer());
    2223    SoundSource(const SoundSource& source);
    2324    SoundSource& operator=(const SoundSource& source);
     
    2829    // user interaction
    2930    void play();
    30     void play(const SoundBuffer* buffer);
    31     void play(const SoundBuffer* buffer, float gain);
    32     void play(const SoundBuffer* buffer, float gain, bool loop);
     31    void play(const SoundBuffer& buffer);
     32    void play(const SoundBuffer& buffer, float gain);
     33    void play(const SoundBuffer& buffer, float gain, bool loop);
    3334
    34     void gain(const SoundBuffer* buffer, float gain);
     35    void gain(const SoundBuffer& buffer, float gain);
    3536
    3637    void stop();
    3738    void pause();
    3839    void rewind();
    39     void fadein(const SoundBuffer* buffer, ALfloat duration);
     40    void fadein(const SoundBuffer& buffer, ALfloat duration);
    4041
    4142    // development functions
     
    4647    void setSourceNode(const PNode* sourceNode);
    4748    /** @returns the SoundBuffer of this Source */
    48     inline const SoundBuffer* getBuffer() const { return this->buffer; };
     49    inline const SoundBuffer& getBuffer() const { return this->buffer; };
    4950    /** @returns the SourceNode of this Source */
    5051    inline const PNode* getNode() const { return this->sourceNode; };
     
    6566    bool                   resident;    //!< If the alSource should be resident (if true, the alSource will be returned on deletion).
    6667    ALuint                 sourceID;    //!< The ID of the Source
    67     const SoundBuffer*     buffer;      //!< The buffer to play in this source.
     68    SoundBuffer            buffer;      //!< The buffer to play in this source.
    6869    const PNode*           sourceNode;  //!< The SourceNode representing the position/velocity... of this source.
    6970  };
Note: See TracChangeset for help on using the changeset viewer.