Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5386 in orxonox.OLD for trunk/src/lib/sound/sound_buffer.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_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}
Note: See TracChangeset for help on using the changeset viewer.