sound.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2001 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_SOUND_H
00025 #define NL_SOUND_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/stream.h"
00029 #include "nel/misc/string_mapper.h"
00030 #include "nel/sound/u_source.h"
00031 #include "nel/georges/u_form_elm.h"
00032 #include <string>
00033 
00034 namespace NLSOUND {
00035 
00036 
00037 class ISoundDriver;
00038 class IBuffer;
00039 class CSound;
00040 
00041 
00043 //typedef std::hash_map<std::string, CSound*> TSoundMap;
00044 typedef CHashMap<NLMISC::TStringId, CSound*, NLMISC::CStringIdHashMapTraits> TSoundMap;
00045 
00047 typedef std::set<CSound*> TSoundSet;
00048 
00049 const double Sqrt12_2 = 1.0594630943592952645618252949463;  // 2^1/12
00050 
00057 class CSound
00058 {
00059     friend class CAudioMixerUser;
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         SOUND_MUSIC
00071     };
00072 
00073 
00075     CSound();
00077     virtual ~CSound();
00078 
00080     virtual TSOUND_TYPE getSoundType() =0;
00081 
00083     virtual void        importForm(const std::string& filename, NLGEORGES::UFormElm& formRoot);
00084 
00086     bool                getLooping() const              { return _Looping; }
00088     float               getGain() const                 { return _Gain; }
00090     float               getPitch() const                { return _Pitch; }
00092     TSoundPriority      getPriority() const             { return _Priority; }
00094     virtual bool        isDetailed() const = 0;
00096     float               getConeInnerAngle() const           { return _ConeInnerAngle; }
00098     float               getConeOuterAngle() const           { return _ConeOuterAngle; }
00100     float               getConeOuterGain() const            { return _ConeOuterGain; }
00102     const NLMISC::CVector &getDirectionVector()const        { return _Direction;}
00104     virtual uint32      getDuration() = 0;
00106     const NLMISC::TStringId&    getName() const                     { return _Name; }
00108     virtual float       getMaxDistance() const              { return _MaxDist; }
00109 
00111     void                setLooping( bool looping ) { _Looping = looping; }
00112 
00114     virtual void        getSubSoundList(std::vector<std::pair<std::string, CSound*> > &subsounds) const =0;
00115 
00116 
00117     virtual void        serial(NLMISC::IStream &s);
00118 
00119     NLMISC::TStringId   getUserVarControler() { return _UserVarControler; }
00120 
00121     bool                operator<( const CSound& otherSound ) const
00122     {
00123         return NLMISC::CStringMapper::unmap(_Name) < NLMISC::CStringMapper::unmap(otherSound._Name);
00124     }
00125 
00126 protected:
00127 
00128     // Static properties
00129     float               _Gain;  // [0,1]
00130     float               _Pitch; // ]0,1]
00131     TSoundPriority      _Priority;
00132     float               _ConeInnerAngle, _ConeOuterAngle, _ConeOuterGain;
00133     NLMISC::CVector     _Direction;
00134 
00135     bool                _Looping;
00136 
00138     float               _MaxDist;
00139 
00140     // Sound name.
00141     NLMISC::TStringId   _Name;
00143     NLMISC::TStringId   _UserVarControler;
00144 
00145 };
00146 
00147 
00151 class ESoundFileNotFound : public NLMISC::Exception
00152 {
00153 public:
00154     ESoundFileNotFound( const std::string filename ) :
00155       NLMISC::Exception( (std::string("Sound file not found, or invalid file format: ")+filename).c_str() ) {}
00156 };
00157 
00158 
00159 } // NLSOUND
00160 
00161 
00162 #endif // NL_SOUND_H
00163 
00164 /* End of sound.h */
00165 

Generated on Thu Jan 7 08:26:38 2010 for NeL by  doxygen 1.6.1