Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/output/src/orxonox/sound/BaseSound.h @ 8930

Last change on this file since 8930 was 7856, checked in by landauf, 14 years ago

fixed (?) an endless loop in SoundManager::preUpdate if a non-looping ambient sound faded out. maybe solved the problem by returning a bool from stop() depending on whether or not the sound source was destroyed.

someone who knows more about the sound system should probably have a look at this.

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Erwin 'vaiursch' Herrsche
24 *   Co-authors:
25 *      Reto Grieder
26 *
27 */
28
29#ifndef _BaseSound_H__
30#define _BaseSound_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include <string>
35#include <boost/shared_ptr.hpp>
36#include <OgreDataStream.h>
37#include "core/OrxonoxClass.h"
38
39namespace orxonox
40{
41    /**
42     * The BaseSound class is the base class for all sound file loader classes.
43     * It serves as main interface to the OpenAL library.
44     */
45    class _OrxonoxExport BaseSound : virtual public OrxonoxClass
46    {
47    public:
48        BaseSound();
49
50        void XMLPortExtern(Element& xmlelement, XMLPort::Mode mode);
51
52        virtual void play()  { this->doPlay(); }
53        virtual bool stop()  { return this->doStop(); } // returns true if the sound source was destroyed
54        virtual void pause() { this->doPause(); }
55
56        bool isPlaying() const { return this->state_ == Playing; }
57        bool isPaused()  const { return this->state_ == Paused; }
58        bool isStopped() const { return this->state_ == Stopped; }
59
60        virtual void setSource(const std::string& source);
61        virtual const std::string& getSource() const
62            { return this->source_; }
63
64        void setVolume(float vol);
65        float getVolume() const
66            { return this->volume_; }
67        void updateVolume();
68
69        bool getLooping() const
70            { return this->bLooping_; }
71        void setLooping(bool val);
72
73        float getPitch() const
74            { return this->pitch_; }
75        void setPitch(float pitch);
76
77    protected:
78        enum State
79        {
80            Stopped,
81            Playing,
82            Paused
83        };
84
85        virtual ~BaseSound();
86
87        void doPlay();
88        bool doStop(); // returns true if the sound source was destroyed
89        void doPause();
90
91        // network callbacks
92        inline void pitchChanged()
93            { this->setPitch(this->pitch_); }
94        inline void loopingChanged()
95            { this->setLooping(this->bLooping_); }
96        inline void volumeChanged()
97            { this->setVolume(this->volume_); }
98        inline void sourceChanged()
99            { this->setSource(this->source_); }
100        void stateChanged();
101
102        virtual void initialiseSource();
103        ALint getSourceState() const;
104
105        virtual float getRealVolume() = 0;
106
107        ALuint          audioSource_;
108        bool            bPooling_;
109        shared_ptr<SoundBuffer> soundBuffer_;
110        std::string     source_;
111        float           volume_;
112        bool            bLooping_;
113        uint8_t         state_;       // This Variable is actually of type State
114        float           pitch_;
115
116    private:
117        DataStreamPtr   dataStream_;
118    };
119}
120
121#endif /* _BaseSound_H__ */
Note: See TracBrowser for help on using the repository browser.