- Timestamp:
- Jan 30, 2006, 12:26:32 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/alincl.h
r5001 r6836 10 10 #include <OpenAL/al.h> 11 11 #include <OpenAL/alc.h> 12 #include <OpenAL/alut.h>13 12 #else 14 13 #include <AL/al.h> 15 14 #include <AL/alc.h> 16 #include <AL/alut.h>17 15 #endif 18 16 -
trunk/src/lib/sound/sound_buffer.cc
r5930 r6836 20 20 #include "sound_engine.h" 21 21 22 #include "sdlincl.h" 23 #include <cassert> 24 22 25 using namespace std; 23 26 … … 34 37 this->setName(fileName); 35 38 36 ALenum format;37 ALvoid* data;38 ALsizei freq;39 40 ALenum result;41 42 39 // generate a Buffer 43 40 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)); 41 SoundEngine::checkError("Generate Buffer", __LINE__); 42 this->loadWAV(fileName); 68 43 } 69 44 70 45 SoundBuffer::~SoundBuffer() 71 46 { 72 // SoundEngine::getInstance()->removeBuffer(this);47 // SoundEngine::getInstance()->removeBuffer(this); 73 48 alDeleteBuffers(1, &this->bufferID); 74 49 } 50 51 /** 52 * @brief loads a Waveform from the local fileSystem into this Source. 53 * @param fileName the Name of the File to Load. 54 * @returns true on success. 55 */ 56 bool SoundBuffer::loadWAV(const char* fileName) 57 { 58 SDL_AudioSpec wavSpec; 59 Uint32 wavLength; 60 Uint8 *wavBuffer; 61 62 /* Load the WAV */ 63 if( SDL_LoadWAV(fileName, &wavSpec, &wavBuffer, &wavLength) == NULL) 64 { 65 PRINTF(2)("Could not open %s: %s\n", fileName, SDL_GetError()); 66 return false; 67 } 68 69 alBufferData(this->bufferID, SoundBuffer::sdlAudioSpecToAlFormat(&wavSpec), wavBuffer, wavLength, wavSpec.freq); 70 SDL_FreeWAV(wavBuffer); 71 if (SoundEngine::checkError("Could not load Wave file", __LINE__)) 72 return true; 73 else 74 return false; 75 } 76 77 /** 78 * @brief converts an SDL_AudioSpec into a valid OpenAL AUDIO_FORMAT enumerator 79 * @param audiospec the AudioSpec to convert. 80 * @returns the AL_FORMAT 81 */ 82 ALenum SoundBuffer::sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec) 83 { 84 assert (audiospec != NULL); 85 bool stereo = true; 86 bool is16Bit = true; 87 if (audiospec->format == AUDIO_U8 || audiospec->format == AUDIO_S8) 88 is16Bit = false; 89 if (audiospec->channels == 1) 90 stereo = false; 91 92 if (!stereo && !is16Bit) 93 return AL_FORMAT_MONO8; 94 else if (!stereo && is16Bit) 95 return AL_FORMAT_MONO16; 96 else if (stereo && !is16Bit) 97 return AL_FORMAT_STEREO8; 98 else if (stereo && is16Bit) 99 return AL_FORMAT_STEREO16; 100 } 101 -
trunk/src/lib/sound/sound_buffer.h
r5386 r6836 11 11 12 12 // FORWARD DECLARATION 13 typedef struct SDL_AudioSpec; 13 14 14 15 //! A class that represents a datastructure to play Sounds. … … 19 20 ~SoundBuffer(); 20 21 22 bool loadWAV(const char* fileName); 23 21 24 /** @returns the ID of the buffer used in this SoundBuffer */ 22 25 inline ALuint getID() const { return this->bufferID; } 26 27 private: 28 ALenum sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec); 23 29 24 30 private: -
trunk/src/lib/sound/sound_engine.cc
r6830 r6836 307 307 alcMakeContextCurrent(this->context); 308 308 #else 309 alutInit(0, NULL); 309 this->device = alcOpenDevice(NULL); 310 311 this->context = alcCreateContext(this->device, NULL); 312 313 alcMakeContextCurrent(this->context); 314 // 310 315 #endif 311 316 … … 324 329 bool SoundEngine::allocateSources(unsigned int count) 325 330 { 326 ALenum result;327 331 // Setting default values. 328 332 for (unsigned int i = 0; i < count; i++) 329 333 { 330 ALuint source ;334 ALuint source = 0; 331 335 332 336 alGenSources(1, &source); 333 if ((result = alGetError()) != AL_NO_ERROR) 334 PRINTF(1)("Error Generating Sources: '%s'\n", SoundEngine::getALErrorString(result)); 337 this->checkError("loading Sources", __LINE__); 335 338 336 339 alSourcef (source, AL_PITCH, 1.0 ); … … 340 343 } 341 344 return true; 345 } 346 347 bool SoundEngine::checkError(const char* error, unsigned int line) 348 { 349 ALenum errorCode; 350 if ((errorCode = alGetError()) != AL_NO_ERROR) 351 { 352 PRINTF(1)("Error %s (line:%d): '%s'\n", error, line, SoundEngine::getALErrorString(errorCode)); 353 return false; 354 } 355 else 356 return true; 342 357 } 343 358 -
trunk/src/lib/sound/sound_engine.h
r5930 r6836 59 59 60 60 // error handling: 61 static bool checkError(const char* error, unsigned int line); 61 62 static const char* getALErrorString(ALenum err); 62 63
Note: See TracChangeset
for help on using the changeset viewer.