Blender V2.61 - r43446

AUD_OpenALDevice.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * Copyright 2009-2011 Jörg Hermann Müller
00005  *
00006  * This file is part of AudaSpace.
00007  *
00008  * Audaspace 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 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * AudaSpace 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 General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Audaspace; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #ifndef AUD_OPENALDEVICE
00031 #define AUD_OPENALDEVICE
00032 
00033 #include "AUD_IDevice.h"
00034 #include "AUD_IHandle.h"
00035 #include "AUD_I3DDevice.h"
00036 #include "AUD_I3DHandle.h"
00037 #include "AUD_Buffer.h"
00038 //struct AUD_OpenALBufferedFactory;
00039 
00040 #include <AL/al.h>
00041 #include <AL/alc.h>
00042 #include <list>
00043 #include <pthread.h>
00044 
00048 class AUD_OpenALDevice : public AUD_IDevice, public AUD_I3DDevice
00049 {
00050 private:
00052     class AUD_OpenALHandle : public AUD_IHandle, public AUD_I3DHandle
00053     {
00054     public:
00055         static const int CYCLE_BUFFERS = 3;
00056 
00058         bool m_isBuffered;
00059 
00061         AUD_Reference<AUD_IReader> m_reader;
00062 
00064         bool m_keep;
00065 
00067         ALenum m_format;
00068 
00070         ALuint m_source;
00071 
00073         ALuint m_buffers[CYCLE_BUFFERS];
00074 
00076         int m_current;
00077 
00079         bool m_eos;
00080 
00082         int m_loopcount;
00083 
00085         stopCallback m_stop;
00086 
00088         void* m_stop_data;
00089 
00091         AUD_Quaternion m_orientation;
00092 
00094         AUD_Status m_status;
00095 
00097         AUD_OpenALDevice* m_device;
00098 
00099     public:
00100 
00108         AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, AUD_Reference<AUD_IReader> reader, bool keep);
00109 
00110         virtual ~AUD_OpenALHandle() {}
00111         virtual bool pause();
00112         virtual bool resume();
00113         virtual bool stop();
00114         virtual bool getKeep();
00115         virtual bool setKeep(bool keep);
00116         virtual bool seek(float position);
00117         virtual float getPosition();
00118         virtual AUD_Status getStatus();
00119         virtual float getVolume();
00120         virtual bool setVolume(float volume);
00121         virtual float getPitch();
00122         virtual bool setPitch(float pitch);
00123         virtual int getLoopCount();
00124         virtual bool setLoopCount(int count);
00125         virtual bool setStopCallback(stopCallback callback = 0, void* data = 0);
00126 
00127         virtual AUD_Vector3 getSourceLocation();
00128         virtual bool setSourceLocation(const AUD_Vector3& location);
00129         virtual AUD_Vector3 getSourceVelocity();
00130         virtual bool setSourceVelocity(const AUD_Vector3& velocity);
00131         virtual AUD_Quaternion getSourceOrientation();
00132         virtual bool setSourceOrientation(const AUD_Quaternion& orientation);
00133         virtual bool isRelative();
00134         virtual bool setRelative(bool relative);
00135         virtual float getVolumeMaximum();
00136         virtual bool setVolumeMaximum(float volume);
00137         virtual float getVolumeMinimum();
00138         virtual bool setVolumeMinimum(float volume);
00139         virtual float getDistanceMaximum();
00140         virtual bool setDistanceMaximum(float distance);
00141         virtual float getDistanceReference();
00142         virtual bool setDistanceReference(float distance);
00143         virtual float getAttenuation();
00144         virtual bool setAttenuation(float factor);
00145         virtual float getConeAngleOuter();
00146         virtual bool setConeAngleOuter(float angle);
00147         virtual float getConeAngleInner();
00148         virtual bool setConeAngleInner(float angle);
00149         virtual float getConeVolumeOuter();
00150         virtual bool setConeVolumeOuter(float volume);
00151     };
00152 
00153     typedef std::list<AUD_Reference<AUD_OpenALHandle> >::iterator AUD_HandleIterator;
00154 
00158     ALCdevice* m_device;
00159 
00163     ALCcontext* m_context;
00164 
00168     AUD_DeviceSpecs m_specs;
00169 
00173     bool m_useMC;
00174 
00178     std::list<AUD_Reference<AUD_OpenALHandle> > m_playingSounds;
00179 
00183     std::list<AUD_Reference<AUD_OpenALHandle> > m_pausedSounds;
00184 
00188     //std::list<AUD_OpenALBufferedFactory*>* m_bufferedFactories;
00189 
00193     pthread_mutex_t m_mutex;
00194 
00198     pthread_t m_thread;
00199 
00203     bool m_playing;
00204 
00208     int m_buffersize;
00209 
00213     AUD_Buffer m_buffer;
00214 
00218     AUD_Quaternion m_orientation;
00219 
00224     void start(bool join = true);
00225 
00232     bool getFormat(ALenum &format, AUD_Specs specs);
00233 
00234     // hide copy constructor and operator=
00235     AUD_OpenALDevice(const AUD_OpenALDevice&);
00236     AUD_OpenALDevice& operator=(const AUD_OpenALDevice&);
00237 
00238 public:
00247     AUD_OpenALDevice(AUD_DeviceSpecs specs,
00248                      int buffersize = AUD_DEFAULT_BUFFER_SIZE);
00249 
00253     void updateStreams();
00254 
00255     virtual ~AUD_OpenALDevice();
00256 
00257     virtual AUD_DeviceSpecs getSpecs() const;
00258     virtual AUD_Reference<AUD_IHandle> play(AUD_Reference<AUD_IReader> reader, bool keep = false);
00259     virtual AUD_Reference<AUD_IHandle> play(AUD_Reference<AUD_IFactory> factory, bool keep = false);
00260     virtual void stopAll();
00261     virtual void lock();
00262     virtual void unlock();
00263     virtual float getVolume() const;
00264     virtual void setVolume(float volume);
00265 
00266     virtual AUD_Vector3 getListenerLocation() const;
00267     virtual void setListenerLocation(const AUD_Vector3& location);
00268     virtual AUD_Vector3 getListenerVelocity() const;
00269     virtual void setListenerVelocity(const AUD_Vector3& velocity);
00270     virtual AUD_Quaternion getListenerOrientation() const;
00271     virtual void setListenerOrientation(const AUD_Quaternion& orientation);
00272     virtual float getSpeedOfSound() const;
00273     virtual void setSpeedOfSound(float speed);
00274     virtual float getDopplerFactor() const;
00275     virtual void setDopplerFactor(float factor);
00276     virtual AUD_DistanceModel getDistanceModel() const;
00277     virtual void setDistanceModel(AUD_DistanceModel model);
00278 };
00279 
00280 #endif //AUD_OPENALDEVICE