Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 7, 2009, 11:19:19 AM (15 years ago)
Author:
rgrieder
Message:

Renaming BaseSound::setSoundFile (and all its associates) to setSource to be compliant with classes like ParicleInterface.

Location:
code/branches/core5/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/orxonox/gamestates/GSMainMenu.cc

    r5896 r5899  
    6363            // Load sound
    6464            this->ambient_ = new AmbientSound(0);
    65             this->ambient_->setSoundFile("ambient/mainmenu.wav");
     65            this->ambient_->setSource("ambient/mainmenu.wav");
    6666        }
    6767    }
  • code/branches/core5/src/orxonox/sound/AmbientSound.cc

    r5896 r5899  
    4949    {
    5050        SUPER(AmbientSound, XMLPort, xmlelement, mode);
    51         XMLPortParamExtern(AmbientSound, BaseSound, this, "soundFile", setSoundFile, getSoundFile, xmlelement, mode);
     51        XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
    5252        XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
    5353        XMLPortParamExtern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
  • code/branches/core5/src/orxonox/sound/BaseSound.cc

    r5896 r5899  
    4040{
    4141    BaseSound::BaseSound()
    42         : source_(0)
    43         , buffer_(0)
     42        : audioSource_(0)
     43        , audioBuffer_(0)
    4444        , bPlayOnLoad_(false)
    4545        , bLoop_(false)
     
    5050    BaseSound::~BaseSound()
    5151    {
    52         this->setSoundFile("");
     52        this->setSource("");
    5353    }
    5454
    5555    void BaseSound::play()
    5656    {
    57         if (alIsSource(this->source_))
     57        if (alIsSource(this->audioSource_))
    5858        {
    5959            if (this->bLoop_)
    60                 alSourcei(this->source_, AL_LOOPING, AL_TRUE);
     60                alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE);
    6161            else
    62                 alSourcei(this->source_, AL_LOOPING, AL_FALSE);
    63             alSourcePlay(this->source_);
     62                alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE);
     63            alSourcePlay(this->audioSource_);
    6464
    6565            if (alGetError() != AL_NO_ERROR)
    6666            {
    67                  COUT(2) << "Sound: OpenAL: Error playin sound " << this->source_ << std::endl;
     67                 COUT(2) << "Sound: OpenAL: Error playin sound " << this->audioSource_ << std::endl;
    6868            }
    6969        }
     
    7272    void BaseSound::stop()
    7373    {
    74         if (alIsSource(this->source_))
    75             alSourceStop(this->source_);
     74        if (alIsSource(this->audioSource_))
     75            alSourceStop(this->audioSource_);
    7676    }
    7777
    7878    void BaseSound::pause()
    7979    {
    80         if (alIsSource(this->source_))
    81             alSourcePause(this->source_);
     80        if (alIsSource(this->audioSource_))
     81            alSourcePause(this->audioSource_);
    8282    }
    8383
    8484    bool BaseSound::isPlaying()
    8585    {
    86         if (alIsSource(this->source_))
     86        if (alIsSource(this->audioSource_))
    8787            return getSourceState() == AL_PLAYING;
    8888        return false;
     
    9191    bool BaseSound::isPaused()
    9292    {
    93         if (alIsSource(this->source_))
     93        if (alIsSource(this->audioSource_))
    9494            return getSourceState() == AL_PAUSED;
    9595        return true;
     
    9898    bool BaseSound::isStopped()
    9999    {
    100         if (alIsSource(this->source_))
     100        if (alIsSource(this->audioSource_))
    101101            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
    102102        return true;
     
    109109    }
    110110
    111     void BaseSound::setSoundFile(const std::string& soundFile)
    112     {
    113         this->soundFile_ = soundFile;
     111    void BaseSound::setSource(const std::string& source)
     112    {
     113        this->source_ = source;
    114114        if (!GameMode::playsSound())
    115115            return;
    116116
    117         if (soundFile.empty() && alIsSource(this->source_))
     117        if (source.empty() && alIsSource(this->audioSource_))
    118118        {
    119119            // Unload sound
    120             alSourcei(this->source_, AL_BUFFER, 0);
    121             alDeleteSources(1, &this->source_);
    122             alDeleteBuffers(1, &this->buffer_);
    123             return;
    124         }
    125 
    126         COUT(3) << "Sound: OpenAL ALUT: loading file " << soundFile << std::endl;
     120            alSourcei(this->audioSource_, AL_BUFFER, 0);
     121            alDeleteSources(1, &this->audioSource_);
     122            alDeleteBuffers(1, &this->audioBuffer_);
     123            return;
     124        }
     125
     126        COUT(3) << "Sound: OpenAL ALUT: loading file " << source << std::endl;
    127127        // Get DataStream from the resources
    128         shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(soundFile);
     128        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
    129129        if (fileInfo == NULL)
    130130        {
    131             COUT(2) << "Warning: Sound file '" << soundFile << "' not found" << std::endl;
    132             return;
    133         }
    134         DataStreamPtr stream = Resource::open(soundFile);
     131            COUT(2) << "Warning: Sound file '" << source << "' not found" << std::endl;
     132            return;
     133        }
     134        DataStreamPtr stream = Resource::open(source);
    135135        // Read everything into a temporary buffer
    136136        char* buffer = new char[fileInfo->size];
    137137        stream->read(buffer, fileInfo->size);
    138138
    139         this->buffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
     139        this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
    140140        delete[] buffer;
    141141
    142         if (this->buffer_ == AL_NONE)
     142        if (this->audioBuffer_ == AL_NONE)
    143143        {
    144144            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
     
    147147            //{
    148148            //    COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
    149             //    this->buffer_ = loadOggFile(filename);
     149            //    this->audioBuffer_ = loadOggFile(filename);
    150150            //}
    151151
    152             //if (this->buffer_ == AL_NONE)
     152            //if (this->audioBuffer_ == AL_NONE)
    153153            //{
    154154            //    COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
     
    157157        }
    158158
    159         alGenSources(1, &this->source_);
    160         alSourcei(this->source_, AL_BUFFER, this->buffer_);
     159        alGenSources(1, &this->audioSource_);
     160        alSourcei(this->audioSource_, AL_BUFFER, this->audioBuffer_);
    161161        if (alGetError() != AL_NO_ERROR)
    162162        {
    163             COUT(2) << "Sound: OpenAL: Error loading sample file: " << soundFile << std::endl;
    164             return;
    165         }
    166 
    167         alSource3f(this->source_, AL_POSITION,  0, 0, 0);
     163            COUT(2) << "Sound: OpenAL: Error loading sample file: " << source << std::endl;
     164            return;
     165        }
     166
     167        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
    168168
    169169        if (this->bPlayOnLoad_)
     
    174174    {
    175175        ALint state;
    176         alGetSourcei(this->source_, AL_SOURCE_STATE, &state);
     176        alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state);
    177177        return state;
    178178    }
  • code/branches/core5/src/orxonox/sound/BaseSound.h

    r5896 r5899  
    5555        bool isStopped();
    5656
    57         void setSoundFile(const std::string& soundFile);
    58         const std::string& getSoundFile() { return this->soundFile_; }
     57        void setSource(const std::string& source);
     58        const std::string& getSource() { return this->source_; }
    5959
    6060        bool getPlayOnLoad() { return this->bPlayOnLoad_; }
     
    6565
    6666    protected:
    67         //ALuint loadOggFile(const std::string& filename);
     67        ALuint loadOggFile(const std::string& filename);
    6868        ALint getSourceState();
    6969
    70         ALuint source_;
    71         ALuint buffer_;
     70        ALuint audioSource_;
     71        ALuint audioBuffer_;
    7272
    7373    private:
    74         std::string soundFile_;
     74        std::string source_;
    7575        bool bPlayOnLoad_;
    7676        bool bLoop_;
  • code/branches/core5/src/orxonox/sound/WorldSound.cc

    r5897 r5899  
    5252    {
    5353        SUPER(WorldSound, XMLPort, xmlelement, mode);
    54         XMLPortParamExtern(WorldSound, BaseSound, this, "soundFile", setSoundFile, getSoundFile, xmlelement, mode);
     54        XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
    5555        XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
    5656        XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
     
    6565    void WorldSound::tick(float dt)
    6666    {
    67         if (alIsSource(this->source_))
     67        if (alIsSource(this->audioSource_))
    6868        {
    6969            const Vector3& pos = this->getWorldPosition();
    70             alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z);
     70            alSource3f(this->audioSource_, AL_POSITION, pos.x, pos.y, pos.z);
    7171            ALenum error = alGetError();
    7272            if (error == AL_INVALID_VALUE)
     
    7474
    7575            const Vector3& vel = this->getVelocity();
    76             alSource3f(this->source_, AL_VELOCITY, vel.x, vel.y, vel.z);
     76            alSource3f(this->audioSource_, AL_VELOCITY, vel.x, vel.y, vel.z);
    7777            error = alGetError();
    7878            if (error == AL_INVALID_VALUE)
     
    8181            const Quaternion& orient = this->getWorldOrientation();
    8282            Vector3 at = orient.zAxis();
    83             alSource3f(this->source_, AL_DIRECTION, at.x, at.y, at.z);
     83            alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z);
    8484            error = alGetError();
    8585            if (error == AL_INVALID_VALUE)
Note: See TracChangeset for help on using the changeset viewer.