PixelLightAPI  .
Source.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Source.h                                       *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSOUND_SOURCE_H__
00024 #define __PLSOUND_SOURCE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/Vector3.h>
00032 #include "PLSound/Resource.h"
00033 #include "PLSound/BufferHandler.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLSound {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class Buffer;
00046 
00047 
00048 //[-------------------------------------------------------]
00049 //[ Classes                                               ]
00050 //[-------------------------------------------------------]
00051 /**
00052 *  @brief
00053 *    Abstract sound source resource
00054 *
00055 *  @note
00056 *    - For sources with 3D spatialization, do only use one channel buffers because not each sound backend may be capable to use 3D spatialization for buffers with multiple channels
00057 */
00058 class Source : public Resource {
00059 
00060 
00061     //[-------------------------------------------------------]
00062     //[ Public definitions                                    ]
00063     //[-------------------------------------------------------]
00064     public:
00065         /**
00066         *  @brief
00067         *    Sound source flags
00068         */
00069         enum EFlags {
00070             NoMasterPitch = 1<<0    /**< The master pitch has no influence on this source */
00071         };
00072 
00073         /**
00074         *  @brief
00075         *    Source attributes
00076         */
00077         enum EAttributes {
00078             Position        = 0,    /**< Position (float3, x/y/z) */
00079             Velocity        = 1,    /**< Velocity in meters per second (float3, x/y/z) */
00080             NumOfAttributes = 2     /**< Number of source attributes */
00081         };
00082 
00083 
00084     //[-------------------------------------------------------]
00085     //[ Public functions                                      ]
00086     //[-------------------------------------------------------]
00087     public:
00088         /**
00089         *  @brief
00090         *    Destructor
00091         */
00092         PLSOUND_API virtual ~Source();
00093 
00094         /**
00095         *  @brief
00096         *    Returns the buffer the source is using
00097         *
00098         *  @return
00099         *    The used sound buffer, a null pointer on error
00100         */
00101         PLSOUND_API Buffer *GetBuffer() const;
00102 
00103         /**
00104         *  @brief
00105         *    Returns the source flags
00106         *
00107         *  @return
00108         *    Source flags (see EFlags)
00109         */
00110         PLSOUND_API PLCore::uint32 GetFlags() const;
00111 
00112         /**
00113         *  @brief
00114         *    Sets the source flags
00115         *
00116         *  @param[in] nFlags
00117         *    Source flags (see EFlags)
00118         */
00119         PLSOUND_API void SetFlags(PLCore::uint32 nFlags = 0);
00120 
00121 
00122     //[-------------------------------------------------------]
00123     //[ Public virtual Source functions                       ]
00124     //[-------------------------------------------------------]
00125     public:
00126         /**
00127         *  @brief
00128         *    Loads the sound source with the given sound buffer
00129         *
00130         *  @param[in] pBuffer
00131         *    Sound buffer the source should load, can be a null pointer (in this case just the same as Unload())
00132         *
00133         *  @return
00134         *   'true' if all went fine, else 'false'
00135         */
00136         PLSOUND_API virtual bool Load(Buffer *pBuffer = nullptr);
00137 
00138         /**
00139         *  @brief
00140         *    Unload the source
00141         */
00142         PLSOUND_API virtual void Unload();
00143 
00144         /**
00145         *  @brief
00146         *    Plays the source
00147         *
00148         *  @param[in] bRestart
00149         *    Restart source if it is already playing?
00150         *
00151         *  @return
00152         *    'true' if all went fine, else 'false' (maybe no buffer is loaded)
00153         */
00154         virtual bool Play(bool bRestart = false) = 0;
00155 
00156         /**
00157         *  @brief
00158         *    Checks whether the source is currently playing or not
00159         *
00160         *  @return
00161         *    'true' if the source is playing at the moment, else 'false'
00162         *
00163         *  @note
00164         *    - If the source is paused this function will return 'true' because the
00165         *      source is played at the moment - but paused :)
00166         */
00167         virtual bool IsPlaying() const = 0;
00168 
00169         /**
00170         *  @brief
00171         *    Pauses the source playback
00172         *
00173         *  @note
00174         *    - Use Play() to continue the playback
00175         */
00176         virtual void Pause() = 0;
00177 
00178         /**
00179         *  @brief
00180         *    Checks whether the source is currently paused or not
00181         *
00182         *  @return
00183         *    'true' if the source is paused at the moment, else 'false'
00184         */
00185         virtual bool IsPaused() const = 0;
00186 
00187         /**
00188         *  @brief
00189         *    Stops the source playback
00190         */
00191         virtual void Stop() = 0;
00192 
00193         /**
00194         *  @brief
00195         *    Returns the volume
00196         *
00197         *  @return
00198         *    Volume (value from 0.0-1.0 -> 0.0 = silence, 1.0 = full volume)
00199         */
00200         virtual float GetVolume() const = 0;
00201 
00202         /**
00203         *  @brief
00204         *    Sets the volume
00205         *
00206         *  @param[in] fVolume
00207         *    Volume (value from 0.0-1.0 -> 0.0 = silence, 1.0 = full volume)
00208         */
00209         virtual void SetVolume(float fVolume = 1.0f) = 0;
00210 
00211         /**
00212         *  @brief
00213         *    Returns whether the source is 2D or not
00214         *
00215         *  @return
00216         *    'true' if source is 2D, else 'false'
00217         */
00218         virtual bool Is2D() const = 0;
00219 
00220         /**
00221         *  @brief
00222         *    Sets whether the source is 2D or not
00223         *
00224         *  @param[in] b2D
00225         *    If 'true' the source is 2D, else 'false'
00226         */
00227         virtual void Set2D(bool b2D = false) = 0;
00228 
00229         /**
00230         *  @brief
00231         *    Returns whether the source is looping or not
00232         *
00233         *  @return
00234         *    'true' if source is looping, else 'false'
00235         */
00236         virtual bool IsLooping() const = 0;
00237 
00238         /**
00239         *  @brief
00240         *    Sets whether the source is looping or not
00241         *
00242         *  @param[in] bLooping
00243         *    If 'true' the source is looping, else 'false'
00244         */
00245         virtual void SetLooping(bool bLooping = false) = 0;
00246 
00247         /**
00248         *  @brief
00249         *    Returns the pitch multiplier
00250         *
00251         *  @return
00252         *    Pitch multiplier
00253         *
00254         *  @remarks
00255         *    pitch < 1.0 = slower\n
00256         *    pitch = 1.0 = normal\n
00257         *    pitch > 1.0 = faster
00258         */
00259         virtual float GetPitch() const = 0;
00260 
00261         /**
00262         *  @brief
00263         *    Sets the pitch multiplier
00264         *
00265         *  @param[in] fPitch
00266         *    Pitch multiplier
00267         *
00268         *  @see
00269         *    - GetPitch()
00270         */
00271         virtual void SetPitch(float fPitch = 1.0f) = 0;
00272 
00273         /**
00274         *  @brief
00275         *    Returns the reference distance
00276         *
00277         *  @return
00278         *    Reference distance
00279         *
00280         *  @remarks
00281         *    Used to increase or decrease the range of a source by decreasing or increasing the attenuation, respectively.
00282         */
00283         virtual float GetReferenceDistance() const = 0;
00284 
00285         /**
00286         *  @brief
00287         *    Sets the reference distance
00288         *
00289         *  @param[in] fReferenceDistance
00290         *    Reference distance
00291         *
00292         *  @note
00293         *    - See GetReferenceDistance()
00294         */
00295         virtual void SetReferenceDistance(float fReferenceDistance = 1.0f) = 0;
00296 
00297         /**
00298         *  @brief
00299         *    Returns the maximum distance 
00300         *
00301         *  @return
00302         *    Maximum distance
00303         *
00304         *  @remarks
00305         *    Defines a distance beyond which the source will not be further attenuated by distance.
00306         */
00307         virtual float GetMaxDistance() const = 0;
00308 
00309         /**
00310         *  @brief
00311         *    Sets the maximum distance
00312         *
00313         *  @param[in] fMaxDistance
00314         *    Maximum distance
00315         *
00316         *  @see
00317         *    - GetMaxDistance()
00318         */
00319         virtual void SetMaxDistance(float fMaxDistance = 10000.0f) = 0;
00320 
00321         /**
00322         *  @brief
00323         *    Returns the roll off factor
00324         *
00325         *  @return
00326         *    Roll off factor
00327         *
00328         *  @remarks
00329         *    This will scale the distance attenuation over the applicable range.
00330         */
00331         virtual float GetRolloffFactor() const = 0;
00332 
00333         /**
00334         *  @brief
00335         *    Sets the roll off factor
00336         *
00337         *  @param[in] fRolloffFactor
00338         *    Roll off factor
00339         *
00340         *  @see
00341         *    - GetRolloffFactor()
00342         */
00343         virtual void SetRolloffFactor(float fRolloffFactor = 1.0f) = 0;
00344 
00345         /**
00346         *  @brief
00347         *    Gets a source attribute value
00348         *
00349         *  @param[in] nAttribute
00350         *    Source attribute to return
00351         *
00352         *  @return
00353         *    Requested source attribute value
00354         */
00355         virtual PLMath::Vector3 GetAttribute(EAttributes nAttribute) const = 0;
00356 
00357         /**
00358         *  @brief
00359         *    Sets a source attribute value
00360         *
00361         *  @param[in] nAttribute
00362         *    Source attribute to set
00363         *  @param[in] vV
00364         *    New source attribute value
00365         *
00366         *  @return
00367         *    'true' if all went fine, else 'false'
00368         */
00369         virtual bool SetAttribute(EAttributes nAttribute, const PLMath::Vector3 &vV) = 0;
00370 
00371 
00372     //[-------------------------------------------------------]
00373     //[ Protected functions                                   ]
00374     //[-------------------------------------------------------]
00375     protected:
00376         /**
00377         *  @brief
00378         *    Constructor
00379         *
00380         *  @param[in] cSoundManager
00381         *    Owner sound manager
00382         */
00383         PLSOUND_API Source(SoundManager &cSoundManager);
00384 
00385 
00386     //[-------------------------------------------------------]
00387     //[ Private functions                                     ]
00388     //[-------------------------------------------------------]
00389     private:
00390         /**
00391         *  @brief
00392         *    Copy constructor
00393         *
00394         *  @param[in] cSource
00395         *    Source to copy from
00396         */
00397         Source(const Source &cSource);
00398 
00399         /**
00400         *  @brief
00401         *    Copy operator
00402         *
00403         *  @param[in] cSource
00404         *    Source to copy from
00405         *
00406         *  @return
00407         *    Reference to this instance
00408         */
00409         Source &operator =(const Source &cSource);
00410 
00411 
00412     //[-------------------------------------------------------]
00413     //[ Private data                                          ]
00414     //[-------------------------------------------------------]
00415     private:
00416         BufferHandler  m_cBufferHandler;    /**< Sound buffer the source is using */
00417         PLCore::uint32 m_nFlags;            /**< Flags */
00418 
00419 
00420 };
00421 
00422 
00423 //[-------------------------------------------------------]
00424 //[ Namespace                                             ]
00425 //[-------------------------------------------------------]
00426 } // PLSound
00427 
00428 
00429 #endif // __PLSOUND_SOURCE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:00
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported