Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2009, 4:52:26 PM (15 years ago)
Author:
erwin
Message:

implemented a fallback ogg loader via libvorbisfile

File:
1 edited

Legend:

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

    r2980 r2984  
    2626 *
    2727 */
     28#include <vector>
    2829#include <AL/alut.h>
    2930#include <vorbis/vorbisfile.h>
     
    7172            ALenum error = alGetError();
    7273            if(error == AL_INVALID_VALUE)
    73                 COUT(2) << "OpenAL: Invalid sound position" << std::endl;
     74                COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl;
    7475
    7576            Vector3 vel = this->entity_->getVelocity();
     
    7778            error = alGetError();
    7879            if(error == AL_INVALID_VALUE)
    79                 COUT(2) << "OpenAL: Invalid sound position" << std::endl;
     80                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
    8081
    8182            Quaternion orient = this->entity_->getOrientation();
     
    8485            error = alGetError();
    8586            if(error == AL_INVALID_VALUE)
    86                 COUT(2) << "OpenAL: Invalid sound position" << std::endl;
     87                COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl;
    8788        }
    8889    }
     
    133134    bool SoundBase::loadFile(std::string filename) {
    134135        filename = Core::getMediaPathString() + "/audio/" + filename;
    135         COUT(3) << "OpenAL ALUT: loading file " << filename << std::endl;
     136        COUT(3) << "Sound: OpenAL ALUT: loading file " << filename << std::endl;
    136137        this->buffer_ = alutCreateBufferFromFile(filename.c_str());
    137138        if(this->buffer_ == AL_NONE) {
    138             COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
     139            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    139140            if(filename.find("ogg", 0) != std::string::npos)
    140141            {
     
    149150        alSourcei(this->source_, AL_BUFFER, this->buffer_);
    150151        if(alGetError() != AL_NO_ERROR) {
    151             COUT(2) << "OpenAL: Error loading sample file" << std::endl;
     152            COUT(2) << "Sound: OpenAL: Error loading sample file" << std::endl;
    152153            return false;
    153154        }
     
    160161        return state;
    161162    }
    162    
     163
    163164    ALuint SoundBase::loadOggFile(std::string filename)
    164165    {
    165         // just a dummy
    166         return AL_NONE;
     166        COUT(2) << "Sound: Trying fallback ogg loader";
     167
     168        char inbuffer[4096];
     169        std::vector<char> outbuffer;
     170        OggVorbis_File vf;
     171        int eof = false;
     172        int current_section;
     173
     174        FILE* f = fopen(filename.c_str(), "rb");
     175
     176        if(ov_open(f, &vf, NULL, 0) < 0)
     177        {
     178            COUT(2) << "Sound: libvorbisfile: File seems not to be an Ogg Vorbis bitstream" << std::endl;
     179            ov_clear(&vf);
     180            return AL_NONE;
     181        }
     182
     183        while(!eof)
     184        {
     185            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
     186            if (ret == 0)
     187            {
     188                eof = true;
     189            }
     190            else if (ret < 0)
     191            {
     192                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
     193                ov_clear(&vf);
     194                return AL_NONE;
     195            }
     196            else
     197            {
     198                outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + sizeof(inbuffer));
     199            }
     200        }
     201       
     202        ov_clear(&vf);
     203
     204        return alutCreateBufferFromFileImage(&outbuffer, outbuffer.size());
    167205    }
    168206} // namespace: orxonox
Note: See TracChangeset for help on using the changeset viewer.