Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6836 in orxonox.OLD for trunk


Ignore:
Timestamp:
Jan 30, 2006, 12:26:32 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: no more alut

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/alincl.h

    r5001 r6836  
    1010#include <OpenAL/al.h>
    1111#include <OpenAL/alc.h>
    12 #include <OpenAL/alut.h>
    1312#else
    1413#include <AL/al.h>
    1514#include <AL/alc.h>
    16 #include <AL/alut.h>
    1715#endif
    1816
  • trunk/src/lib/sound/sound_buffer.cc

    r5930 r6836  
    2020#include "sound_engine.h"
    2121
     22#include "sdlincl.h"
     23#include <cassert>
     24
    2225using namespace std;
    2326
     
    3437  this->setName(fileName);
    3538
    36   ALenum format;
    37   ALvoid* data;
    38   ALsizei freq;
    39 
    40   ALenum result;
    41 
    4239  // generate a Buffer
    4340  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);
    6843}
    6944
    7045SoundBuffer::~SoundBuffer()
    7146{
    72 //  SoundEngine::getInstance()->removeBuffer(this);
     47  //  SoundEngine::getInstance()->removeBuffer(this);
    7348  alDeleteBuffers(1, &this->bufferID);
    7449}
     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 */
     56bool 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 */
     82ALenum 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  
    1111
    1212// FORWARD DECLARATION
     13typedef struct SDL_AudioSpec;
    1314
    1415//! A class that represents a datastructure to play Sounds.
     
    1920    ~SoundBuffer();
    2021
     22    bool loadWAV(const char* fileName);
     23
    2124    /** @returns the ID of the buffer used in this SoundBuffer */
    2225    inline ALuint getID() const { return this->bufferID; }
     26
     27  private:
     28    ALenum sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec);
    2329
    2430  private:
  • trunk/src/lib/sound/sound_engine.cc

    r6830 r6836  
    307307  alcMakeContextCurrent(this->context);
    308308#else
    309   alutInit(0, NULL);
     309  this->device = alcOpenDevice(NULL);
     310
     311  this->context = alcCreateContext(this->device, NULL);
     312
     313  alcMakeContextCurrent(this->context);
     314  //
    310315#endif
    311316
     
    324329bool SoundEngine::allocateSources(unsigned int count)
    325330{
    326   ALenum result;
    327331  // Setting default values.
    328332  for (unsigned int i = 0; i < count; i++)
    329333  {
    330     ALuint source;
     334    ALuint source = 0;
    331335
    332336    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__);
    335338
    336339    alSourcef (source, AL_PITCH,    1.0      );
     
    340343  }
    341344  return true;
     345}
     346
     347bool 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;
    342357}
    343358
  • trunk/src/lib/sound/sound_engine.h

    r5930 r6836  
    5959
    6060  // error handling:
     61    static bool checkError(const char* error, unsigned int line);
    6162    static const char* getALErrorString(ALenum err);
    6263
Note: See TracChangeset for help on using the changeset viewer.