Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5386 in orxonox.OLD for trunk/src/lib/sound/sound_engine.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 edited

Legend:

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