MPMA Framework 0.4
Player.h
Go to the documentation of this file.
00001 
00002 //Luke Lenhart, 2008-2011
00003 //See /docs/License.txt for details on how this code may be used.
00004 
00005 #pragma once
00006 
00007 #include "../base/Setup.h"
00008 
00009 #ifdef MPMA_COMPILE_AUDIO
00010 
00011 #include <list>
00012 #include <vector>
00013 #include <memory>
00014 #include "Source.h"
00015 #include "AL_Include.h"
00016 
00017 namespace AUDIO_INTERNAL
00018 {
00019     class StreamBuffer;
00020 }
00021 
00022 namespace AUDIO
00023 {
00025     enum RenderMode
00026     {
00028         POSITIONAL=0x200,
00030         FIXED
00031     };
00032 
00034     void SetBackgroundStreaming(bool enable);
00035 
00037     uint32 UpdateStreams();
00038 
00040     class StaticBuffer
00041     {
00042     public:
00044         StaticBuffer(std::shared_ptr<Source> source);
00045 
00046         virtual ~StaticBuffer();
00047 
00048     private:
00049         ALuint buffer;
00050 
00051         friend class Player;
00052     };
00053 
00055     class Player
00056     {
00057     public:
00059         static std::shared_ptr<Player> Create(bool allocateNow=false);
00060 
00061         virtual ~Player();
00062 
00064         bool PlayStreaming(std::shared_ptr<Source> source, RenderMode mode, float streamSizeInSeconds=0.2f);
00065 
00067         bool PlayStatic(std::shared_ptr<StaticBuffer> buffer, RenderMode mode);
00068 
00070         void Stop();
00071 
00073         bool IsPlaying() const;
00074 
00076         void SetVolume(float value);
00078         static void SetDefaultVolume(float value);
00079 
00081         void SetPitchMultiplier(float value);
00083         static void SetDefaultPitchMultiplier(float value);
00084 
00086         void SetPosition(float x, float y, float z);
00088         template <typename VectorType>
00089         inline void SetPosition(const VectorType &pos)
00090             { SetPosition(pos[0], pos[1], pos[2]); }
00091 
00093         void SetVelocity(float x, float y, float z);
00095         template <typename VectorType>
00096         inline void SetVelocity(const VectorType &vel)
00097             { SetVelocity(vel[0], vel[1], vel[2]); }
00098 
00100         void SetCone(float dirX, float dirY, float dirZ, float coneInnerAngle, float coneOutterAngle, float coneOutterAngleVolume);
00102         template <typename VectorType>
00103         inline void SetCone(const VectorType &dir, float coneInnerAngle, float coneOutterAngle, float coneOutterAngleVolume)
00104             { SetCone(dir[0], dir[1], dir[2], coneInnerAngle, coneOutterAngle, coneOutterAngleVolume); }
00105 
00107         void SetDistanceVolumeLimits(float minVolume, float maxVolume);
00109         static void SetDefaultDistanceVolumeLimits(float minVolume, float maxVolume);
00110 
00112         void SetReferenceDistance(float value);
00114         static void SetDefaultReferenceDistance(float value);
00115 
00117         void SetMaxDistance(float value);
00119         static void SetDefaultMaxDistance(float value);
00120 
00122         void SetRolloffFactor(float value);
00124         static void SetDefaultRolloffFactor(float value);
00125 
00126         //TODO: effects (reverb etc)
00127 
00129         void SetDefaults();
00130 
00131     private:
00132         Player();
00133         void Reset();
00134 
00135         ALuint player; //(openal source) - this is lazy initialized but kept around until the class is freed after that
00136         bool isStatic; //whether the data is static or being streamed
00137 
00138         //used by for playing static buffers
00139         std::shared_ptr<StaticBuffer> staticBuffer;
00140 
00141         //used for playing streaming sources
00142         std::shared_ptr<Source> streamSource;
00143         std::shared_ptr<AUDIO_INTERNAL::StreamBuffer> streamBuffer;
00144         std::weak_ptr<Player> self;
00145 
00146         friend class AUDIO_INTERNAL::StreamBuffer;
00147     };
00148 }
00149 
00150 #endif //#ifdef MPMA_COMPILE_AUDIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends