| 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 | using namespace std; | 
|---|
| 23 |  | 
|---|
| 24 | ////////////////// | 
|---|
| 25 | /* SOUND-BUFFER */ | 
|---|
| 26 | ////////////////// | 
|---|
| 27 | /** | 
|---|
| 28 |  *  Creates a Soundbuffer out of an inputfile | 
|---|
| 29 |  * @param fileName The name of the File | 
|---|
| 30 |  */ | 
|---|
| 31 | SoundBuffer::SoundBuffer(const char* fileName) | 
|---|
| 32 | { | 
|---|
| 33 |   this->setClassID(CL_SOUND_BUFFER, "SoundBuffer"); | 
|---|
| 34 |   this->setName(fileName); | 
|---|
| 35 |  | 
|---|
| 36 |   ALenum format; | 
|---|
| 37 |   ALvoid* data; | 
|---|
| 38 |   ALsizei freq; | 
|---|
| 39 |  | 
|---|
| 40 |   ALenum result; | 
|---|
| 41 |  | 
|---|
| 42 |   // generate a Buffer | 
|---|
| 43 |   alGenBuffers(1, &this->bufferID); | 
|---|
| 44 |   if ((result = alGetError()) != AL_NO_ERROR) | 
|---|
| 45 |     PRINTF(2)("%s\n", SoundEngine::getALErrorString(result)); | 
|---|
| 46 |  | 
|---|
| 47 |   // read in the wav data | 
|---|
| 48 |   /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/ | 
|---|
| 49 | #ifdef __APPLE__ | 
|---|
| 50 |   alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq); | 
|---|
| 51 | #elif defined __WIN32__ | 
|---|
| 52 |   alutLoadWAVFile((ALbyte*)fileName, &format, &data, &size, &freq, &this->loop); | 
|---|
| 53 | #else | 
|---|
| 54 |   alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop); | 
|---|
| 55 | #endif | 
|---|
| 56 |   if ((result = alGetError()) != AL_NO_ERROR) | 
|---|
| 57 |     PRINTF(2)("%s\n", SoundEngine::getALErrorString(result)); | 
|---|
| 58 |  | 
|---|
| 59 |   // send the loaded wav data to the buffer | 
|---|
| 60 |   alBufferData(this->bufferID, format, data, this->size, freq); | 
|---|
| 61 |   if ((result = alGetError()) != AL_NO_ERROR) | 
|---|
| 62 |     PRINTF(2)("%s\n", SoundEngine::getALErrorString(result)); | 
|---|
| 63 |  | 
|---|
| 64 |   // remove the wav data (redundant) | 
|---|
| 65 |   alutUnloadWAV(format, data, this->size, freq); | 
|---|
| 66 |   if ((result = alGetError()) != AL_NO_ERROR) | 
|---|
| 67 |     PRINTF(2)("%s\n", SoundEngine::getALErrorString(result)); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | SoundBuffer::~SoundBuffer() | 
|---|
| 71 | { | 
|---|
| 72 | //  SoundEngine::getInstance()->removeBuffer(this); | 
|---|
| 73 |   alDeleteBuffers(1, &this->bufferID); | 
|---|
| 74 | } | 
|---|