Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5386 in orxonox.OLD for trunk/src/lib/sound/sound_source.cc


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

File:
1 copied

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.