| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 4 |    Copyright (C) 2004 orx | 
|---|
| 5 |  | 
|---|
| 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 7 |    it under the terms of the GNU General Public License as published by | 
|---|
| 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 9 |    any later version. | 
|---|
| 10 |  | 
|---|
| 11 |    ### File Specific: | 
|---|
| 12 |    main-programmer: Benjamin Grauer | 
|---|
| 13 |    co-programmer: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND | 
|---|
| 17 |  | 
|---|
| 18 | #include "sound_buffer.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "sound_engine.h" | 
|---|
| 21 |  | 
|---|
| 22 |  | 
|---|
| 23 | using namespace std; | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 | ////////////////// | 
|---|
| 27 | /* SOUND-BUFFER */ | 
|---|
| 28 | ////////////////// | 
|---|
| 29 | /** | 
|---|
| 30 |  *  Creates a Soundbuffer out of an inputfile | 
|---|
| 31 |  * @param fileName The name of the File | 
|---|
| 32 |  */ | 
|---|
| 33 | SoundBuffer::SoundBuffer(const char* fileName) | 
|---|
| 34 | { | 
|---|
| 35 |   this->setClassID(CL_SOUND_BUFFER, "SoundBuffer"); | 
|---|
| 36 |   this->setName(fileName); | 
|---|
| 37 |  | 
|---|
| 38 |   SoundEngine::getInstance()->addBuffer(this); | 
|---|
| 39 |  | 
|---|
| 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); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | SoundBuffer::~SoundBuffer() | 
|---|
| 75 | { | 
|---|
| 76 | //  SoundEngine::getInstance()->removeBuffer(this); | 
|---|
| 77 |   alDeleteBuffers(1, &this->bufferID); | 
|---|
| 78 | } | 
|---|