Changeset View
Changeset View
Standalone View
Standalone View
extern/audaspace/include/devices/SoftwareDevice.h
- This file was moved from intern/audaspace/intern/AUD_SoftwareDevice.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 | #pragma once | ||||
| * 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/intern/AUD_SoftwareDevice.h | /** | ||||
| * \ingroup audaspaceintern | * @file SoftwareDevice.h | ||||
| * @ingroup devices | |||||
| * The SoftwareDevice class. | |||||
| */ | */ | ||||
| #include "devices/IDevice.h" | |||||
| #include "devices/IHandle.h" | |||||
| #include "devices/I3DDevice.h" | |||||
| #include "devices/I3DHandle.h" | |||||
| #include "devices/DefaultSynchronizer.h" | |||||
| #include "util/Buffer.h" | |||||
| #ifndef __AUD_SOFTWAREDEVICE_H__ | #include <list> | ||||
| #define __AUD_SOFTWAREDEVICE_H__ | #include <mutex> | ||||
| #include "AUD_IDevice.h" | AUD_NAMESPACE_BEGIN | ||||
| #include "AUD_IHandle.h" | |||||
| #include "AUD_I3DDevice.h" | |||||
| #include "AUD_I3DHandle.h" | |||||
| #include "AUD_Mixer.h" | |||||
| #include "AUD_Buffer.h" | |||||
| #include "AUD_PitchReader.h" | |||||
| #include "AUD_ResampleReader.h" | |||||
| #include "AUD_ChannelMapperReader.h" | |||||
| #include <list> | class Mixer; | ||||
| #include <pthread.h> | class PitchReader; | ||||
| class ResampleReader; | |||||
| class ChannelMapperReader; | |||||
| /** | /** | ||||
| * This device plays is a generic device with software mixing. | * The software device is a generic device with software mixing. | ||||
| * It is a base class for all software mixing classes. | |||||
| * Classes implementing this have to: | * Classes implementing this have to: | ||||
| * - Implement the playing function. | * - Implement the playing function. | ||||
| * - Prepare the m_specs, m_mixer variables. | * - Prepare the m_specs, m_mixer variables. | ||||
| * - Call the create and destroy functions. | * - Call the create and destroy functions. | ||||
| * - Call the mix function to retrieve their audio data. | * - Call the mix function to retrieve their audio data. | ||||
| */ | */ | ||||
| class AUD_SoftwareDevice : public AUD_IDevice, public AUD_I3DDevice | class AUD_API SoftwareDevice : public IDevice, public I3DDevice | ||||
| { | { | ||||
| protected: | protected: | ||||
| /// Saves the data for playback. | /// Saves the data for playback. | ||||
| class AUD_SoftwareHandle : public AUD_IHandle, public AUD_I3DHandle | class AUD_API SoftwareHandle : public IHandle, public I3DHandle | ||||
| { | { | ||||
| private: | |||||
| // delete copy constructor and operator= | |||||
| SoftwareHandle(const SoftwareHandle&) = delete; | |||||
| SoftwareHandle& operator=(const SoftwareHandle&) = delete; | |||||
| public: | public: | ||||
| /// The reader source. | /// The reader source. | ||||
| boost::shared_ptr<AUD_IReader> m_reader; | std::shared_ptr<IReader> m_reader; | ||||
| /// The pitch reader in between. | /// The pitch reader in between. | ||||
| boost::shared_ptr<AUD_PitchReader> m_pitch; | std::shared_ptr<PitchReader> m_pitch; | ||||
| /// The resample reader in between. | /// The resample reader in between. | ||||
| boost::shared_ptr<AUD_ResampleReader> m_resampler; | std::shared_ptr<ResampleReader> m_resampler; | ||||
| /// The channel mapper reader in between. | /// The channel mapper reader in between. | ||||
| boost::shared_ptr<AUD_ChannelMapperReader> m_mapper; | std::shared_ptr<ChannelMapperReader> m_mapper; | ||||
| /// 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. | |||||
| /// The calculated final volume of the source. | /// The calculated final volume of the source. | ||||
| float m_volume; | float m_volume; | ||||
| /// The previous calculated final volume of the source. | |||||
| float m_old_volume; | float m_old_volume; | ||||
| /// The loop count of the source. | /// The loop count of the source. | ||||
| int m_loopcount; | int m_loopcount; | ||||
| /// Location in 3D Space. | /// Location in 3D Space. | ||||
| AUD_Vector3 m_location; | Vector3 m_location; | ||||
| /// Velocity in 3D Space. | /// Velocity in 3D Space. | ||||
| AUD_Vector3 m_velocity; | Vector3 m_velocity; | ||||
| /// Orientation in 3D Space. | /// Orientation in 3D Space. | ||||
| AUD_Quaternion m_orientation; | Quaternion m_orientation; | ||||
| /// Whether the position to the listener is relative or absolute | /// Whether the position to the listener is relative or absolute | ||||
| bool m_relative; | bool m_relative; | ||||
| Context not available. | |||||
| void* m_stop_data; | void* m_stop_data; | ||||
| /// Current status of the handle | /// Current status of the handle | ||||
| AUD_Status m_status; | Status m_status; | ||||
| /// Own device. | /// Own device. | ||||
| AUD_SoftwareDevice* m_device; | SoftwareDevice* m_device; | ||||
| /** | |||||
| * This method is for internal use only. | |||||
| * @param keep Whether the sound should be marked stopped or paused. | |||||
| * @return Whether the action succeeded. | |||||
| */ | |||||
| bool pause(bool keep); | bool pause(bool keep); | ||||
| public: | public: | ||||
| /** | /** | ||||
| * Creates a new software handle. | * Creates a new software handle. | ||||
| * \param device The device this handle is from. | * \param device The device this handle is from. | ||||
| Context not available. | |||||
| * \param mapper The channel mapping reader. | * \param mapper The channel mapping reader. | ||||
| * \param keep Whether to keep the handle when the sound ends. | * \param keep Whether to keep the handle when the sound ends. | ||||
| */ | */ | ||||
| AUD_SoftwareHandle(AUD_SoftwareDevice* device, boost::shared_ptr<AUD_IReader> reader, boost::shared_ptr<AUD_PitchReader> pitch, boost::shared_ptr<AUD_ResampleReader> resampler, boost::shared_ptr<AUD_ChannelMapperReader> mapper, bool keep); | SoftwareHandle(SoftwareDevice* device, std::shared_ptr<IReader> reader, std::shared_ptr<PitchReader> pitch, std::shared_ptr<ResampleReader> resampler, std::shared_ptr<ChannelMapperReader> mapper, bool keep); | ||||
| /** | /** | ||||
| * Updates the handle's playback parameters. | * Updates the handle's playback parameters. | ||||
| Context not available. | |||||
| /** | /** | ||||
| * Sets the audio output specification of the readers. | * Sets the audio output specification of the readers. | ||||
| * \param sepcs The output specification. | * \param specs The output specification. | ||||
| */ | */ | ||||
| void setSpecs(AUD_Specs specs); | void setSpecs(Specs specs); | ||||
| virtual ~AUD_SoftwareHandle() {} | virtual ~SoftwareHandle() {} | ||||
| 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_SoftwareHandle> >::iterator AUD_HandleIterator; | |||||
| /** | /** | ||||
| * The specification of the device. | * The specification of the device. | ||||
| */ | */ | ||||
| AUD_DeviceSpecs m_specs; | DeviceSpecs m_specs; | ||||
| /** | /** | ||||
| * The mixer. | * The mixer. | ||||
| */ | */ | ||||
| boost::shared_ptr<AUD_Mixer> m_mixer; | std::shared_ptr<Mixer> m_mixer; | ||||
| /** | /** | ||||
| * Whether to do high or low quality resampling. | * Whether to do high or low quality resampling. | ||||
| Context not available. | |||||
| /** | /** | ||||
| * Sets the audio output specification of the device. | * Sets the audio output specification of the device. | ||||
| * \param sepcs The output specification. | * \param specs The output specification. | ||||
| */ | |||||
| void setSpecs(Specs specs); | |||||
| /** | |||||
| * Empty default constructor. To setup the device call the function create() | |||||
| * and to uninitialize call destroy(). | |||||
| */ | */ | ||||
| void setSpecs(AUD_Specs specs); | SoftwareDevice(); | ||||
| private: | private: | ||||
| /** | /** | ||||
| * The reading buffer. | * The reading buffer. | ||||
| */ | */ | ||||
| AUD_Buffer m_buffer; | Buffer m_buffer; | ||||
| /** | /** | ||||
| * The list of sounds that are currently playing. | * The list of sounds that are currently playing. | ||||
| */ | */ | ||||
| std::list<boost::shared_ptr<AUD_SoftwareHandle> > m_playingSounds; | std::list<std::shared_ptr<SoftwareHandle> > m_playingSounds; | ||||
| /** | /** | ||||
| * The list of sounds that are currently paused. | * The list of sounds that are currently paused. | ||||
| */ | */ | ||||
| std::list<boost::shared_ptr<AUD_SoftwareHandle> > m_pausedSounds; | std::list<std::shared_ptr<SoftwareHandle> > m_pausedSounds; | ||||
| /** | /** | ||||
| * Whether there is currently playback. | * Whether there is currently playback. | ||||
| Context not available. | |||||
| /** | /** | ||||
| * The mutex for locking. | * The mutex for locking. | ||||
| */ | */ | ||||
| pthread_mutex_t m_mutex; | std::recursive_mutex m_mutex; | ||||
| /** | /** | ||||
| * The overall volume of the device. | * The overall volume of the device. | ||||
| Context not available. | |||||
| float m_volume; | float m_volume; | ||||
| /// Listener location. | /// Listener location. | ||||
| AUD_Vector3 m_location; | Vector3 m_location; | ||||
| /// Listener velocity. | /// Listener velocity. | ||||
| AUD_Vector3 m_velocity; | Vector3 m_velocity; | ||||
| /// Listener orientation. | /// Listener orientation. | ||||
| AUD_Quaternion m_orientation; | Quaternion m_orientation; | ||||
| /// Speed of Sound. | /// Speed of Sound. | ||||
| float m_speed_of_sound; | float m_speed_of_sound; | ||||
| Context not available. | |||||
| float m_doppler_factor; | float m_doppler_factor; | ||||
| /// Distance model. | /// Distance model. | ||||
| AUD_DistanceModel m_distance_model; | DistanceModel m_distance_model; | ||||
| /// Rendering flags | /// Rendering flags | ||||
| int m_flags; | int m_flags; | ||||
| /// Synchronizer. | |||||
| DefaultSynchronizer m_synchronizer; | |||||
| // delete copy constructor and operator= | |||||
| SoftwareDevice(const SoftwareDevice&) = delete; | |||||
| SoftwareDevice& operator=(const SoftwareDevice&) = delete; | |||||
| public: | public: | ||||
| /** | /** | ||||
| Context not available. | |||||
| * \param handle The handle to set the panning from. | * \param handle The handle to set the panning from. | ||||
| * \param pan The new panning value, should be in the range [-2, 2]. | * \param pan The new panning value, should be in the range [-2, 2]. | ||||
| */ | */ | ||||
| static void setPanning(AUD_IHandle* handle, float pan); | static void setPanning(IHandle* handle, float pan); | ||||
| /** | /** | ||||
| * Sets the resampling quality. | * Sets the resampling quality. | ||||
| Context not available. | |||||
| */ | */ | ||||
| void setQuality(bool quality); | void setQuality(bool quality); | ||||
| 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); | ||||
| }; | }; | ||||
| #endif //__AUD_SOFTWAREDEVICE_H__ | AUD_NAMESPACE_END | ||||
| Context not available. | |||||