Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8969 in orxonox.OLD for trunk/src/lib/sound/sound_buffer.cc


Ignore:
Timestamp:
Jul 1, 2006, 10:45:47 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: ogg-files loadable (hopefully)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/sound/sound_buffer.cc

    r8619 r8969  
    2323#include <cassert>
    2424#include "debug.h"
     25#include "sys/stat.h"
     26#include "helper_functions.h"
    2527
    2628#ifdef HAVE_SDL_SDL_H
     
    4850    alGenBuffers(1, &this->bufferID);
    4951    SoundEngine::checkError("Generate Buffer", __LINE__);
    50     this->loadWAV(fileName);
     52    if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV"))
     53    {
     54      this->loadWAV(fileName);
     55    }
     56    else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG"))
     57      this->loadOGG(fileName);
     58
    5159  }
    5260
     
    7684    }
    7785#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    78                 if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) ) {
    79                         int cnt = wavLength/2;
    80                         Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer;
    81                         for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts )
    82                                 *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts );
    83                 }
     86    if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) )
     87    {
     88      int cnt = wavLength/2;
     89      Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer;
     90      for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts )
     91        *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts );
     92    }
    8493#endif
    8594    alBufferData(this->bufferID, SoundBuffer::sdlAudioSpecToAlFormat(&wavSpec),
    86                         wavBuffer, wavLength, wavSpec.freq);
     95                 wavBuffer, wavLength, wavSpec.freq);
    8796
    8897    SDL_FreeWAV(wavBuffer);
     
    92101      return false;
    93102  }
     103
     104
     105#ifndef AL_FORMAT_VORBIS_EXT
     106#define AL_FORMAT_VORBIS_EXT 0x100030
     107#endif
     108  bool SoundBuffer::loadOGG(const std::string& fileName)
     109  {
     110    void*     ovdata;
     111    FILE*     fh;
     112
     113    fh = fopen( fileName.c_str() , "rb") ;
     114    if( fh != NULL )
     115    {
     116      struct stat sbuf ;
     117
     118      if(stat( fileName.c_str(), &sbuf ) != -1)
     119      {
     120        ovdata = malloc(sbuf.st_size);
     121        if(ovdata != NULL)
     122        {
     123          fread( ovdata, 1, sbuf.st_size, fh);
     124
     125          alBufferData( this->bufferID,
     126                        AL_FORMAT_VORBIS_EXT,
     127                        ovdata,
     128                        sbuf.st_size,
     129                        1) ;
     130
     131          free(ovdata);
     132        }
     133        fclose(fh);
     134      }
     135      else
     136        return false;
     137    }
     138    else
     139      return false;
     140
     141    return true ;
     142
     143  }
     144
    94145
    95146  /**
Note: See TracChangeset for help on using the changeset viewer.