Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8969 in orxonox.OLD for trunk/src/lib


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

orxonox/trunk: ogg-files loadable (hopefully)

Location:
trunk/src/lib/sound
Files:
3 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  /**
  • trunk/src/lib/sound/sound_buffer.h

    r7460 r8969  
    2323
    2424    bool loadWAV(const std::string& fileName);
     25    bool loadOGG(const std::string& fileName);
    2526
    2627    /** @returns the ID of the buffer used in this SoundBuffer */
  • trunk/src/lib/sound/sound_source.cc

    r8793 r8969  
    11/*
    22  orxonox - the future of 3D-vertical-scrollers
    3  
     3
    44  Copyright (C) 2004 orx
    5  
     5
    66  This program is free software; you can redistribute it and/or modify
    77  it under the terms of the GNU General Public License as published by
    88  the Free Software Foundation; either version 2, or (at your option)
    99  any later version.
    10  
     10
    1111  ### File Specific:
    1212  main-programmer: Benjamin Grauer
     
    8585    else
    8686      this->stop();
     87
     88    return *this;
    8789  }
    8890
     
    166168   * @brief Plays back buffer on this Source with gain
    167169   * @param buffer the buffer to play back on this Source
    168    * @param gain the gain of the sound buffer 
     170   * @param gain the gain of the sound buffer
    169171  */
    170172  void SoundSource::play(const SoundBuffer* buffer, float gain)
Note: See TracChangeset for help on using the changeset viewer.