Blender V2.61 - r43446

AUD_SoftwareDevice.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_SOFTWAREDEVICE
00031 #define AUD_SOFTWAREDEVICE
00032 
00033 #include "AUD_IDevice.h"
00034 #include "AUD_IHandle.h"
00035 #include "AUD_I3DDevice.h"
00036 #include "AUD_I3DHandle.h"
00037 #include "AUD_Mixer.h"
00038 #include "AUD_Buffer.h"
00039 #include "AUD_PitchReader.h"
00040 #include "AUD_ResampleReader.h"
00041 #include "AUD_ChannelMapperReader.h"
00042 
00043 #include <list>
00044 #include <pthread.h>
00045 
00054 class AUD_SoftwareDevice : public AUD_IDevice, public AUD_I3DDevice
00055 {
00056 protected:
00058     class AUD_SoftwareHandle : public AUD_IHandle, public AUD_I3DHandle
00059     {
00060     public:
00062         AUD_Reference<AUD_IReader> m_reader;
00063 
00065         AUD_Reference<AUD_PitchReader> m_pitch;
00066 
00068         AUD_Reference<AUD_ResampleReader> m_resampler;
00069 
00071         AUD_Reference<AUD_ChannelMapperReader> m_mapper;
00072 
00074         bool m_keep;
00075 
00077         float m_user_pitch;
00078 
00080         float m_user_volume;
00081 
00083         float m_user_pan;
00084 
00086         float m_volume;
00087 
00089         int m_loopcount;
00090 
00092         AUD_Vector3 m_location;
00093 
00095         AUD_Vector3 m_velocity;
00096 
00098         AUD_Quaternion m_orientation;
00099 
00101         bool m_relative;
00102 
00104         float m_volume_max;
00105 
00107         float m_volume_min;
00108 
00110         float m_distance_max;
00111 
00113         float m_distance_reference;
00114 
00116         float m_attenuation;
00117 
00119         float m_cone_angle_outer;
00120 
00122         float m_cone_angle_inner;
00123 
00125         float m_cone_volume_outer;
00126 
00128         int m_flags;
00129 
00131         stopCallback m_stop;
00132 
00134         void* m_stop_data;
00135 
00137         AUD_Status m_status;
00138 
00140         AUD_SoftwareDevice* m_device;
00141 
00142     public:
00143 
00153         AUD_SoftwareHandle(AUD_SoftwareDevice* device, AUD_Reference<AUD_IReader> reader, AUD_Reference<AUD_PitchReader> pitch, AUD_Reference<AUD_ResampleReader> resampler, AUD_Reference<AUD_ChannelMapperReader> mapper, bool keep);
00154 
00158         void update();
00159 
00164         void setSpecs(AUD_Specs specs);
00165 
00166         virtual ~AUD_SoftwareHandle() {}
00167         virtual bool pause();
00168         virtual bool resume();
00169         virtual bool stop();
00170         virtual bool getKeep();
00171         virtual bool setKeep(bool keep);
00172         virtual bool seek(float position);
00173         virtual float getPosition();
00174         virtual AUD_Status getStatus();
00175         virtual float getVolume();
00176         virtual bool setVolume(float volume);
00177         virtual float getPitch();
00178         virtual bool setPitch(float pitch);
00179         virtual int getLoopCount();
00180         virtual bool setLoopCount(int count);
00181         virtual bool setStopCallback(stopCallback callback = 0, void* data = 0);
00182 
00183         virtual AUD_Vector3 getSourceLocation();
00184         virtual bool setSourceLocation(const AUD_Vector3& location);
00185         virtual AUD_Vector3 getSourceVelocity();
00186         virtual bool setSourceVelocity(const AUD_Vector3& velocity);
00187         virtual AUD_Quaternion getSourceOrientation();
00188         virtual bool setSourceOrientation(const AUD_Quaternion& orientation);
00189         virtual bool isRelative();
00190         virtual bool setRelative(bool relative);
00191         virtual float getVolumeMaximum();
00192         virtual bool setVolumeMaximum(float volume);
00193         virtual float getVolumeMinimum();
00194         virtual bool setVolumeMinimum(float volume);
00195         virtual float getDistanceMaximum();
00196         virtual bool setDistanceMaximum(float distance);
00197         virtual float getDistanceReference();
00198         virtual bool setDistanceReference(float distance);
00199         virtual float getAttenuation();
00200         virtual bool setAttenuation(float factor);
00201         virtual float getConeAngleOuter();
00202         virtual bool setConeAngleOuter(float angle);
00203         virtual float getConeAngleInner();
00204         virtual bool setConeAngleInner(float angle);
00205         virtual float getConeVolumeOuter();
00206         virtual bool setConeVolumeOuter(float volume);
00207     };
00208 
00209     typedef std::list<AUD_Reference<AUD_SoftwareHandle> >::iterator AUD_HandleIterator;
00210 
00214     AUD_DeviceSpecs m_specs;
00215 
00219     AUD_Reference<AUD_Mixer> m_mixer;
00220 
00224     bool m_quality;
00225 
00229     void create();
00230 
00234     void destroy();
00235 
00241     void mix(data_t* buffer, int length);
00242 
00247     virtual void playing(bool playing)=0;
00248 
00253     void setSpecs(AUD_Specs specs);
00254 
00255 private:
00259     AUD_Buffer m_buffer;
00260 
00264     std::list<AUD_Reference<AUD_SoftwareHandle> > m_playingSounds;
00265 
00269     std::list<AUD_Reference<AUD_SoftwareHandle> > m_pausedSounds;
00270 
00274     bool m_playback;
00275 
00279     pthread_mutex_t m_mutex;
00280 
00284     float m_volume;
00285 
00287     AUD_Vector3 m_location;
00288 
00290     AUD_Vector3 m_velocity;
00291 
00293     AUD_Quaternion m_orientation;
00294 
00296     float m_speed_of_sound;
00297 
00299     float m_doppler_factor;
00300 
00302     AUD_DistanceModel m_distance_model;
00303 
00305     int m_flags;
00306 
00307 public:
00308 
00314     static void setPanning(AUD_IHandle* handle, float pan);
00315 
00320     void setQuality(bool quality);
00321 
00322     virtual AUD_DeviceSpecs getSpecs() const;
00323     virtual AUD_Reference<AUD_IHandle> play(AUD_Reference<AUD_IReader> reader, bool keep = false);
00324     virtual AUD_Reference<AUD_IHandle> play(AUD_Reference<AUD_IFactory> factory, bool keep = false);
00325     virtual void stopAll();
00326     virtual void lock();
00327     virtual void unlock();
00328     virtual float getVolume() const;
00329     virtual void setVolume(float volume);
00330 
00331     virtual AUD_Vector3 getListenerLocation() const;
00332     virtual void setListenerLocation(const AUD_Vector3& location);
00333     virtual AUD_Vector3 getListenerVelocity() const;
00334     virtual void setListenerVelocity(const AUD_Vector3& velocity);
00335     virtual AUD_Quaternion getListenerOrientation() const;
00336     virtual void setListenerOrientation(const AUD_Quaternion& orientation);
00337     virtual float getSpeedOfSound() const;
00338     virtual void setSpeedOfSound(float speed);
00339     virtual float getDopplerFactor() const;
00340     virtual void setDopplerFactor(float factor);
00341     virtual AUD_DistanceModel getDistanceModel() const;
00342     virtual void setDistanceModel(AUD_DistanceModel model);
00343 };
00344 
00345 #endif //AUD_SOFTWAREDEVICE