Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 8, 2009, 12:00:21 AM (15 years ago)
Author:
rgrieder
Message:

Ogg file loading should work again now using the Ogre resource system.

Location:
code/branches/core5/src/orxonox/sound
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/orxonox/sound/BaseSound.cc

    r5899 r5904  
    132132            return;
    133133        }
    134         DataStreamPtr stream = Resource::open(source);
     134        dataStream_ = Resource::open(source);
    135135        // Read everything into a temporary buffer
    136136        char* buffer = new char[fileInfo->size];
    137         stream->read(buffer, fileInfo->size);
     137        dataStream_->read(buffer, fileInfo->size);
     138        dataStream_->seek(0);
    138139
    139140        this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
     
    143144        {
    144145            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    145             return;
    146             //if (filename.find("ogg", 0) != std::string::npos)
    147             //{
    148             //    COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
    149             //    this->audioBuffer_ = loadOggFile(filename);
    150             //}
    151 
    152             //if (this->audioBuffer_ == AL_NONE)
    153             //{
    154             //    COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
    155             //    return;
    156             //}
     146            if (source.find("ogg", 0) != std::string::npos)
     147            {
     148                COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
     149                this->audioBuffer_ = loadOggFile();
     150            }
     151
     152            if (this->audioBuffer_ == AL_NONE)
     153            {
     154                COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
     155                return;
     156            }
    157157        }
    158158
     
    178178    }
    179179
    180 #if 0 // Not yet supported because of missing resource implementation
    181     ALuint BaseSound::loadOggFile(const std::string& filename)
     180    size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource)
     181    {
     182        return static_cast<Ogre::DataStream*>(datasource)->read(ptr, size * nmemb);
     183    }
     184
     185    int seekVorbis(void* datasource, ogg_int64_t offset, int whence)
     186    {
     187        Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource);
     188        int offset_beg = offset;
     189        if (whence == SEEK_CUR)
     190            offset_beg = stream->tell() + offset;
     191        else if (whence == SEEK_END)
     192            offset_beg = stream->size() + offset;
     193        else if (whence != SEEK_SET)
     194            return -1;
     195        stream->seek(offset_beg);
     196        return 0;
     197    }
     198
     199    long tellVorbis(void* datasource)
     200    {
     201        return static_cast<long>(static_cast<Ogre::DataStream*>(datasource)->tell());
     202    }
     203
     204    ALuint BaseSound::loadOggFile()
    182205    {
    183206        char inbuffer[4096];
     
    190213        ALenum format;
    191214
    192         FILE* f = fopen(filename.c_str(), "rb");
    193 
    194         if (ov_open(f, &vf, NULL, 0) < 0)
     215        // Open file with custom streaming
     216        ov_callbacks vorbisCallbacks;
     217        vorbisCallbacks.read_func  = &readVorbis;
     218        vorbisCallbacks.seek_func  = &seekVorbis;
     219        vorbisCallbacks.tell_func  = &tellVorbis;
     220        vorbisCallbacks.close_func = NULL;
     221
     222        int ret = ov_open_callbacks(dataStream_.get(), &vf, NULL, 0, vorbisCallbacks);
     223        if (ret < 0)
    195224        {
    196225            COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
     
    230259        return buffer;
    231260    }
    232 #endif
    233261
    234262} // namespace: orxonox
  • code/branches/core5/src/orxonox/sound/BaseSound.h

    r5899 r5904  
    3232
    3333#include <string>
     34#include <OgreSharedPtr.h>
     35#include <OgreDataStream.h>
    3436#include "core/OrxonoxClass.h"
    3537
     
    6567
    6668    protected:
    67         ALuint loadOggFile(const std::string& filename);
     69        ALuint loadOggFile();
    6870        ALint getSourceState();
    6971
     
    7577        bool bPlayOnLoad_;
    7678        bool bLoop_;
     79        DataStreamPtr dataStream_;
    7780    };
    7881}
Note: See TracChangeset for help on using the changeset viewer.