# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

sound.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_SOUND_H
00027 #define NL_SOUND_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/stream.h"
00031 #include "nel/sound/u_source.h"
00032 #include "nel/georges/u_form_elm.h"
00033 #include <string>
00034 #include <hash_map>
00035 
00036 namespace NLSOUND {
00037 
00038 
00039 class ISoundDriver;
00040 class IBuffer;
00041 class CSound;
00042 
00043 
00045 typedef std::hash_map<std::string, CSound*> TSoundMap;
00046 
00048 typedef std::set<CSound*> TSoundSet;
00049 
00050 const double Sqrt12_2 = 1.0594630943592952645618252949463;  // 2^1/12
00051 
00058 class CSound
00059 {
00060 public:
00062         static CSound *createSound(const std::string &filename, NLGEORGES::UFormElm& formRoot);
00063 
00064         enum TSOUND_TYPE
00065         {
00066                 SOUND_SIMPLE,
00067                 SOUND_COMPLEX,
00068                 SOUND_BACKGROUND,
00069                 SOUND_CONTEXT
00070         };
00071 
00072 
00074         CSound();
00076         virtual ~CSound();
00077 
00079         virtual TSOUND_TYPE getSoundType() =0;
00080 
00082         virtual void            importForm(const std::string& filename, NLGEORGES::UFormElm& formRoot);
00083 
00085         bool                            getLooping() const                              { return _Looping; }
00087         float                           getGain() const                                 { return _Gain; }
00089         float                           getPitch() const                                { return _Pitch; }
00091         TSoundPriority          getPriority() const                             { return _Priority; }
00093         virtual bool            isDetailed() const = 0;
00095         float                           getConeInnerAngle() const                       { return _ConeInnerAngle; }
00097         float                           getConeOuterAngle() const                       { return _ConeOuterAngle; }
00099         float                           getConeOuterGain() const                        { return _ConeOuterGain; }
00101         const NLMISC::CVector &getDirectionVector()const                { return _Direction;}
00103         virtual uint32          getDuration() = 0;
00105         const std::string&      getName() const                                         { return _Name; }
00107         virtual float           getMaxDistance() const                          { return _MaxDist; }
00108 
00110         void                            setLooping( bool looping ) { _Looping = looping; }
00111 
00113         virtual void            getSubSoundList(std::vector<std::pair<std::string, CSound*> > &subsounds) const =0;
00114          
00115 
00116         virtual void            serial(NLMISC::IStream &s);
00117 
00118         bool                            operator<( const CSound& otherSound ) const
00119         {
00120                 return _Name < otherSound._Name;
00121         }
00122 
00123 protected:
00124 
00125         // Static properties
00126         float                           _Gain;  // [0,1]
00127         float                           _Pitch; // ]0,1]
00128         TSoundPriority          _Priority;
00129         float                           _ConeInnerAngle, _ConeOuterAngle, _ConeOuterGain;
00130         NLMISC::CVector         _Direction;
00131 
00132         bool                            _Looping;
00133 
00135         float                           _MaxDist;
00136 
00137         // Sound name.
00138         std::string                     _Name;
00139 
00140 };
00141 
00142 
00146 class ESoundFileNotFound : public NLMISC::Exception
00147 {
00148 public:
00149         ESoundFileNotFound( const std::string filename ) :
00150           NLMISC::Exception( (std::string("Sound file not found, or invalid file format: ")+filename).c_str() ) {}
00151 };
00152 
00153 
00154 } // NLSOUND
00155 
00156 
00157 #endif // NL_SOUND_H
00158 
00159 /* End of sound.h */
00160