Changeset View
Changeset View
Standalone View
Standalone View
extern/audaspace/plugins/openal/OpenALDevice.h
- This file was moved from intern/audaspace/OpenAL/AUD_OpenALDevice.h.
| /* | /******************************************************************************* | ||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | * Copyright 2009-2016 Jörg Müller | ||||
| * | * | ||||
| * Copyright 2009-2011 Jörg Hermann Müller | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | * | ||||
| * This file is part of AudaSpace. | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Audaspace is free software; you can redistribute it and/or modify | * Unless required by applicable law or agreed to in writing, software | ||||
| * it under the terms of the GNU General Public License as published by | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * the Free Software Foundation; either version 2 of the License, or | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * (at your option) any later version. | * See the License for the specific language governing permissions and | ||||
| * | * limitations under the License. | ||||
| * AudaSpace is distributed in the hope that it will be useful, | ******************************************************************************/ | ||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with Audaspace; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | |||||
| */ | |||||
| /** \file audaspace/OpenAL/AUD_OpenALDevice.h | #pragma once | ||||
| * \ingroup audopenal | |||||
| */ | |||||
| #ifdef OPENAL_PLUGIN | |||||
| #define AUD_BUILD_PLUGIN | |||||
| #endif | |||||
| #ifndef __AUD_OPENALDEVICE_H__ | /** | ||||
| #define __AUD_OPENALDEVICE_H__ | * @file OpenALDevice.h | ||||
| * @ingroup plugin | |||||
| * The OpenALDevice class. | |||||
| */ | |||||
| #include "AUD_IDevice.h" | #include "devices/IDevice.h" | ||||
| #include "AUD_IHandle.h" | #include "devices/IHandle.h" | ||||
| #include "AUD_I3DDevice.h" | #include "devices/I3DDevice.h" | ||||
| #include "AUD_I3DHandle.h" | #include "devices/I3DHandle.h" | ||||
| #include "AUD_Buffer.h" | #include "devices/DefaultSynchronizer.h" | ||||
| //struct AUD_OpenALBufferedFactory; | #include "util/Buffer.h" | ||||
| #include <AL/al.h> | #include <al.h> | ||||
| #include <AL/alc.h> | #include <alc.h> | ||||
| #include <list> | #include <list> | ||||
| #include <pthread.h> | #include <mutex> | ||||
| #include <thread> | |||||
| #include <string> | |||||
| AUD_NAMESPACE_BEGIN | |||||
| /** | /** | ||||
| * This device plays through OpenAL. | * This device plays through OpenAL. | ||||
| */ | */ | ||||
| class AUD_OpenALDevice : public AUD_IDevice, public AUD_I3DDevice | class AUD_PLUGIN_API OpenALDevice : public IDevice, public I3DDevice | ||||
| { | { | ||||
| private: | private: | ||||
| /// Saves the data for playback. | /// Saves the data for playback. | ||||
| class AUD_OpenALHandle : public AUD_IHandle, public AUD_I3DHandle | class OpenALHandle : public IHandle, public I3DHandle | ||||
| { | { | ||||
| public: | private: | ||||
| friend class OpenALDevice; | |||||
| static const int CYCLE_BUFFERS = 3; | static const int CYCLE_BUFFERS = 3; | ||||
| /// Whether it's a buffered or a streamed source. | /// Whether it's a buffered or a streamed source. | ||||
| bool m_isBuffered; | bool m_isBuffered; | ||||
| /// The reader source. | /// The reader source. | ||||
| boost::shared_ptr<AUD_IReader> m_reader; | std::shared_ptr<IReader> m_reader; | ||||
| /// Whether to keep the source if end of it is reached. | /// Whether to keep the source if end of it is reached. | ||||
| bool m_keep; | bool m_keep; | ||||
| Context not available. | |||||
| void* m_stop_data; | void* m_stop_data; | ||||
| /// Orientation. | /// Orientation. | ||||
| AUD_Quaternion m_orientation; | Quaternion m_orientation; | ||||
| /// Current status of the handle | /// Current status of the handle | ||||
| AUD_Status m_status; | Status m_status; | ||||
| /// Own device. | /// Own device. | ||||
| AUD_OpenALDevice* m_device; | OpenALDevice* m_device; | ||||
| bool pause(bool keep); | AUD_LOCAL bool pause(bool keep); | ||||
| // delete copy constructor and operator= | |||||
| OpenALHandle(const OpenALHandle&) = delete; | |||||
| OpenALHandle& operator=(const OpenALHandle&) = delete; | |||||
| public: | public: | ||||
| Context not available. | |||||
| * \param reader The reader this handle plays. | * \param reader The reader this handle plays. | ||||
| * \param keep Whether to keep the handle alive when the reader ends. | * \param keep Whether to keep the handle alive when the reader ends. | ||||
| */ | */ | ||||
| AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, boost::shared_ptr<AUD_IReader> reader, bool keep); | OpenALHandle(OpenALDevice* device, ALenum format, std::shared_ptr<IReader> reader, bool keep); | ||||
| virtual ~AUD_OpenALHandle() {} | virtual ~OpenALHandle() {} | ||||
| virtual bool pause(); | virtual bool pause(); | ||||
| virtual bool resume(); | virtual bool resume(); | ||||
| virtual bool stop(); | virtual bool stop(); | ||||
| Context not available. | |||||
| virtual bool setKeep(bool keep); | virtual bool setKeep(bool keep); | ||||
| virtual bool seek(float position); | virtual bool seek(float position); | ||||
| virtual float getPosition(); | virtual float getPosition(); | ||||
| virtual AUD_Status getStatus(); | virtual Status getStatus(); | ||||
| virtual float getVolume(); | virtual float getVolume(); | ||||
| virtual bool setVolume(float volume); | virtual bool setVolume(float volume); | ||||
| virtual float getPitch(); | virtual float getPitch(); | ||||
| Context not available. | |||||
| virtual bool setLoopCount(int count); | virtual bool setLoopCount(int count); | ||||
| virtual bool setStopCallback(stopCallback callback = 0, void* data = 0); | virtual bool setStopCallback(stopCallback callback = 0, void* data = 0); | ||||
| virtual AUD_Vector3 getSourceLocation(); | virtual Vector3 getLocation(); | ||||
| virtual bool setSourceLocation(const AUD_Vector3& location); | virtual bool setLocation(const Vector3& location); | ||||
| virtual AUD_Vector3 getSourceVelocity(); | virtual Vector3 getVelocity(); | ||||
| virtual bool setSourceVelocity(const AUD_Vector3& velocity); | virtual bool setVelocity(const Vector3& velocity); | ||||
| virtual AUD_Quaternion getSourceOrientation(); | virtual Quaternion getOrientation(); | ||||
| virtual bool setSourceOrientation(const AUD_Quaternion& orientation); | virtual bool setOrientation(const Quaternion& orientation); | ||||
| virtual bool isRelative(); | virtual bool isRelative(); | ||||
| virtual bool setRelative(bool relative); | virtual bool setRelative(bool relative); | ||||
| virtual float getVolumeMaximum(); | virtual float getVolumeMaximum(); | ||||
| Context not available. | |||||
| virtual bool setConeVolumeOuter(float volume); | virtual bool setConeVolumeOuter(float volume); | ||||
| }; | }; | ||||
| typedef std::list<boost::shared_ptr<AUD_OpenALHandle> >::iterator AUD_HandleIterator; | |||||
| /** | /** | ||||
| * The OpenAL device handle. | * The OpenAL device handle. | ||||
| */ | */ | ||||
| Context not available. | |||||
| /** | /** | ||||
| * The specification of the device. | * The specification of the device. | ||||
| */ | */ | ||||
| AUD_DeviceSpecs m_specs; | DeviceSpecs m_specs; | ||||
| /** | /** | ||||
| * Whether the device has the AL_EXT_MCFORMATS extension. | * Whether the device has the AL_EXT_MCFORMATS extension. | ||||
| Context not available. | |||||
| /** | /** | ||||
| * The list of sounds that are currently playing. | * The list of sounds that are currently playing. | ||||
| */ | */ | ||||
| std::list<boost::shared_ptr<AUD_OpenALHandle> > m_playingSounds; | std::list<std::shared_ptr<OpenALHandle> > m_playingSounds; | ||||
| /** | /** | ||||
| * The list of sounds that are currently paused. | * The list of sounds that are currently paused. | ||||
| */ | */ | ||||
| std::list<boost::shared_ptr<AUD_OpenALHandle> > m_pausedSounds; | std::list<std::shared_ptr<OpenALHandle> > m_pausedSounds; | ||||
| /** | |||||
| * The list of buffered factories. | |||||
| */ | |||||
| //std::list<AUD_OpenALBufferedFactory*>* m_bufferedFactories; | |||||
| /** | /** | ||||
| * The mutex for locking. | * The mutex for locking. | ||||
| */ | */ | ||||
| pthread_mutex_t m_mutex; | std::recursive_mutex m_mutex; | ||||
| /** | /** | ||||
| * The streaming thread. | * The streaming thread. | ||||
| */ | */ | ||||
| pthread_t m_thread; | std::thread m_thread; | ||||
| /** | /** | ||||
| * The condition for streaming thread wakeup. | * The condition for streaming thread wakeup. | ||||
| Context not available. | |||||
| /** | /** | ||||
| * Device buffer. | * Device buffer. | ||||
| */ | */ | ||||
| AUD_Buffer m_buffer; | Buffer m_buffer; | ||||
| /** | /** | ||||
| * Orientation. | * Orientation. | ||||
| */ | */ | ||||
| AUD_Quaternion m_orientation; | Quaternion m_orientation; | ||||
| /// Synchronizer. | |||||
| DefaultSynchronizer m_synchronizer; | |||||
| /** | /** | ||||
| * Starts the streaming thread. | * Starts the streaming thread. | ||||
| * \param Whether the previous thread should be joined. | * \param Whether the previous thread should be joined. | ||||
| */ | */ | ||||
| void start(bool join = true); | AUD_LOCAL void start(); | ||||
| /** | |||||
| * Streaming thread main function. | |||||
| */ | |||||
| AUD_LOCAL void updateStreams(); | |||||
| /** | /** | ||||
| * Gets the format according to the specs. | * Gets the format according to the specs. | ||||
| Context not available. | |||||
| * \param specs The specs to read the channel count from. | * \param specs The specs to read the channel count from. | ||||
| * \return Whether the format is valid or not. | * \return Whether the format is valid or not. | ||||
| */ | */ | ||||
| bool getFormat(ALenum &format, AUD_Specs specs); | AUD_LOCAL bool getFormat(ALenum &format, Specs specs); | ||||
| // hide copy constructor and operator= | // delete copy constructor and operator= | ||||
| AUD_OpenALDevice(const AUD_OpenALDevice&); | OpenALDevice(const OpenALDevice&) = delete; | ||||
| AUD_OpenALDevice& operator=(const AUD_OpenALDevice&); | OpenALDevice& operator=(const OpenALDevice&) = delete; | ||||
| public: | public: | ||||
| /** | /** | ||||
| * Opens the OpenAL audio device for playback. | * Opens the OpenAL audio device for playback. | ||||
| * \param specs The wanted audio specification. | * \param specs The wanted audio specification. | ||||
| * \param buffersize The size of the internal buffer. | * \param buffersize The size of the internal buffer. | ||||
| * \param name The name of the device to be opened. | |||||
| * \note The specification really used for opening the device may differ. | * \note The specification really used for opening the device may differ. | ||||
| * \note The buffersize will be multiplicated by three for this device. | * \note The buffersize will be multiplicated by three for this device. | ||||
| * \exception AUD_Exception Thrown if the audio device cannot be opened. | * \exception DeviceException Thrown if the audio device cannot be opened. | ||||
| */ | |||||
| AUD_OpenALDevice(AUD_DeviceSpecs specs, | |||||
| int buffersize = AUD_DEFAULT_BUFFER_SIZE); | |||||
| /** | |||||
| * Streaming thread main function. | |||||
| */ | */ | ||||
| void updateStreams(); | OpenALDevice(DeviceSpecs specs, int buffersize = AUD_DEFAULT_BUFFER_SIZE, std::string name = ""); | ||||
| virtual ~AUD_OpenALDevice(); | virtual ~OpenALDevice(); | ||||
| virtual AUD_DeviceSpecs getSpecs() const; | virtual DeviceSpecs getSpecs() const; | ||||
| virtual boost::shared_ptr<AUD_IHandle> play(boost::shared_ptr<AUD_IReader> reader, bool keep = false); | virtual std::shared_ptr<IHandle> play(std::shared_ptr<IReader> reader, bool keep = false); | ||||
| virtual boost::shared_ptr<AUD_IHandle> play(boost::shared_ptr<AUD_IFactory> factory, bool keep = false); | virtual std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound, bool keep = false); | ||||
| virtual void stopAll(); | virtual void stopAll(); | ||||
| virtual void lock(); | virtual void lock(); | ||||
| virtual void unlock(); | virtual void unlock(); | ||||
| virtual float getVolume() const; | virtual float getVolume() const; | ||||
| virtual void setVolume(float volume); | virtual void setVolume(float volume); | ||||
| virtual ISynchronizer* getSynchronizer(); | |||||
| virtual AUD_Vector3 getListenerLocation() const; | |||||
| virtual void setListenerLocation(const AUD_Vector3& location); | virtual Vector3 getListenerLocation() const; | ||||
| virtual AUD_Vector3 getListenerVelocity() const; | virtual void setListenerLocation(const Vector3& location); | ||||
| virtual void setListenerVelocity(const AUD_Vector3& velocity); | virtual Vector3 getListenerVelocity() const; | ||||
| virtual AUD_Quaternion getListenerOrientation() const; | virtual void setListenerVelocity(const Vector3& velocity); | ||||
| virtual void setListenerOrientation(const AUD_Quaternion& orientation); | virtual Quaternion getListenerOrientation() const; | ||||
| virtual void setListenerOrientation(const Quaternion& orientation); | |||||
| virtual float getSpeedOfSound() const; | virtual float getSpeedOfSound() const; | ||||
| virtual void setSpeedOfSound(float speed); | virtual void setSpeedOfSound(float speed); | ||||
| virtual float getDopplerFactor() const; | virtual float getDopplerFactor() const; | ||||
| virtual void setDopplerFactor(float factor); | virtual void setDopplerFactor(float factor); | ||||
| virtual AUD_DistanceModel getDistanceModel() const; | virtual DistanceModel getDistanceModel() const; | ||||
| virtual void setDistanceModel(AUD_DistanceModel model); | virtual void setDistanceModel(DistanceModel model); | ||||
| /** | |||||
| * Retrieves a list of available hardware devices to open with OpenAL. | |||||
| * @return The list of devices to open. | |||||
| */ | |||||
| static std::list<std::string> getDeviceNames(); | |||||
| /** | |||||
| * Registers this plugin. | |||||
| */ | |||||
| static void registerPlugin(); | |||||
| }; | }; | ||||
| #endif //__AUD_OPENALDEVICE_H__ | AUD_NAMESPACE_END | ||||
| Context not available. | |||||