Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2984 for code/branches/sound


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

implemented a fallback ogg loader via libvorbisfile

Location:
code/branches/sound
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/sound/cmake/LibraryConfig.cmake

    r2950 r2984  
    111111FIND_PACKAGE(OGRE  1.4 EXACT REQUIRED)
    112112FIND_PACKAGE(ENet  1.1       REQUIRED)
    113 #FIND_PACKAGE(Ogg             REQUIRED)
    114 #FIND_PACKAGE(Vorbis          REQUIRED)
     113FIND_PACKAGE(Ogg             REQUIRED)
     114FIND_PACKAGE(Vorbis          REQUIRED)
    115115FIND_PACKAGE(ALUT            REQUIRED)
    116116FIND_PACKAGE(ZLIB            REQUIRED)
  • 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
  • code/branches/sound/src/orxonox/sound/SoundManager.cc

    r2982 r2984  
    4646        if(!alutInitWithoutContext(NULL,NULL))
    4747        {
    48             COUT(2) << "OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
     48            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
    4949        }
    5050        else
    5151        {
    52             COUT(4) << "OpenAL ALUT version:" << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
    53             COUT(4) << "OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
     52            COUT(4) << "Sound: OpenAL ALUT version:" << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
     53            COUT(4) << "Sound: OpenAL ALUT supported MIME types:" << alutGetMIMETypes(ALUT_LOADER_BUFFER) << std::endl;
    5454            if(SoundManager::device_s == NULL)
    5555            {
    56                 COUT(3) << "OpenAL: Open sound device..." << std::endl;
     56                COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
    5757                SoundManager::device_s = alcOpenDevice(NULL);
    5858            }
     
    6060            if(SoundManager::device_s == NULL)
    6161            {
    62                 COUT(2) << "OpenAL: Could not open sound device" << std::endl;
     62                COUT(2) << "Sound: OpenAL: Could not open sound device" << std::endl;
    6363            }
    6464            else
    6565            {
    66                 COUT(3) << "OpenAL: Sound device opened" << std::endl;
     66                COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
    6767                this->context_ = alcCreateContext(SoundManager::device_s, NULL);
    6868                if(this->context_ == NULL)
    6969                {
    70                     COUT(2) << "OpenAL: Could not create sound context" << std::endl;
     70                    COUT(2) << "Sound: OpenAL: Could not create sound context" << std::endl;
    7171                }
    7272                else
    7373                {
    7474                    if(alcMakeContextCurrent(this->context_) == AL_TRUE)
    75                         COUT(3) << "OpenAL: Context " << this->context_ << "loaded" << std::endl;
     75                        COUT(3) << "Sound: OpenAL: Context " << this->context_ << "loaded" << std::endl;
    7676                }
    7777            }
     
    127127        ALenum error = alGetError();
    128128        if(error == AL_INVALID_VALUE)
    129             COUT(2) << "OpenAL: Invalid listener position" << std::endl;
     129            COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl;
    130130
    131131        // update listener orientation
     
    140140        error = alGetError();
    141141        if(error == AL_INVALID_VALUE)
    142             COUT(2) << "OpenAL: Invalid listener orientation" << std::endl;
     142            COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
    143143
    144144        // update sounds
Note: See TracChangeset for help on using the changeset viewer.