Audaspace 1.7.0
A high level audio library.
Loading...
Searching...
No Matches
SoftwareDevice.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright 2009-2016 Jörg Müller
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16
17#pragma once
18
24
25#include "devices/IDevice.h"
26#include "devices/IHandle.h"
27#include "devices/I3DDevice.h"
28#include "devices/I3DHandle.h"
29#include "util/Buffer.h"
30
31#include <list>
32#include <mutex>
33
35
36class Mixer;
37class PitchReader;
38class ResampleReader;
40
51{
52protected:
54 class AUD_API SoftwareHandle : public IHandle, public I3DHandle
55 {
56 private:
57 // delete copy constructor and operator=
58 SoftwareHandle(const SoftwareHandle&) = delete;
59 SoftwareHandle& operator=(const SoftwareHandle&) = delete;
60
61 public:
63 std::shared_ptr<IReader> m_reader;
64
66 std::shared_ptr<PitchReader> m_pitch;
67
69 std::shared_ptr<ResampleReader> m_resampler;
70
72 std::shared_ptr<ChannelMapperReader> m_mapper;
73
76
78 bool m_keep;
79
82
85
88
90 float m_volume;
91
94
97
100
103
106
109
112
115
118
121
124
127
130
133
136
139
142
145
148
154 bool pause(bool keep);
155
156 public:
166 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);
167
171 void update();
172
177 void setSpecs(Specs specs);
178
179 virtual ~SoftwareHandle() {}
180 virtual bool pause();
181 virtual bool resume();
182 virtual bool stop();
183 virtual bool getKeep();
184 virtual bool setKeep(bool keep);
185 virtual bool seek(double position);
186 virtual double getPosition();
187 virtual Status getStatus();
188 virtual float getVolume();
189 virtual bool setVolume(float volume);
190 virtual float getPitch();
191 virtual bool setPitch(float pitch);
192 virtual int getLoopCount();
193 virtual bool setLoopCount(int count);
194 virtual bool setStopCallback(stopCallback callback = 0, void* data = 0);
195
197 virtual bool setLocation(const Vector3& location);
199 virtual bool setVelocity(const Vector3& velocity);
201 virtual bool setOrientation(const Quaternion& orientation);
202 virtual bool isRelative();
203 virtual bool setRelative(bool relative);
204 virtual float getVolumeMaximum();
205 virtual bool setVolumeMaximum(float volume);
206 virtual float getVolumeMinimum();
207 virtual bool setVolumeMinimum(float volume);
208 virtual float getDistanceMaximum();
209 virtual bool setDistanceMaximum(float distance);
210 virtual float getDistanceReference();
211 virtual bool setDistanceReference(float distance);
212 virtual float getAttenuation();
213 virtual bool setAttenuation(float factor);
214 virtual float getConeAngleOuter();
215 virtual bool setConeAngleOuter(float angle);
216 virtual float getConeAngleInner();
217 virtual bool setConeAngleInner(float angle);
218 virtual float getConeVolumeOuter();
219 virtual bool setConeVolumeOuter(float volume);
220 };
221
226
230 std::shared_ptr<Mixer> m_mixer;
231
236
240 void create();
241
245 void destroy();
246
252 void mix(data_t* buffer, int length);
253
259 virtual void playing(bool playing)=0;
260
265 void setSpecs(Specs specs);
266
272
278
279private:
283 Buffer m_buffer;
284
288 std::list<std::shared_ptr<SoftwareHandle> > m_playingSounds;
289
293 std::list<std::shared_ptr<SoftwareHandle> > m_pausedSounds;
294
298 bool m_playback;
299
303 std::recursive_mutex m_mutex;
304
308 float m_volume;
309
311 Vector3 m_location;
312
314 Vector3 m_velocity;
315
317 Quaternion m_orientation;
318
320 float m_speed_of_sound;
321
323 float m_doppler_factor;
324
326 DistanceModel m_distance_model;
327
329 int m_flags;
330
332 uint64_t m_synchronizerPosition{0};
333 int m_synchronizerState{0};
334
335 // delete copy constructor and operator=
336 SoftwareDevice(const SoftwareDevice&) = delete;
337 SoftwareDevice& operator=(const SoftwareDevice&) = delete;
338
339public:
340
346 static void setPanning(IHandle* handle, float pan);
347
353
354 virtual DeviceSpecs getSpecs() const;
355 virtual std::shared_ptr<IHandle> play(std::shared_ptr<IReader> reader, bool keep = false);
356 virtual std::shared_ptr<IHandle> play(std::shared_ptr<ISound> sound, bool keep = false);
357 virtual void stopAll();
358 virtual void lock();
359 virtual void unlock();
360 virtual float getVolume() const;
361 virtual void setVolume(float volume);
362
364 virtual void setListenerLocation(const Vector3& location);
366 virtual void setListenerVelocity(const Vector3& velocity);
368 virtual void setListenerOrientation(const Quaternion& orientation);
369 virtual float getSpeedOfSound() const;
370 virtual void setSpeedOfSound(float speed);
371 virtual float getDopplerFactor() const;
372 virtual void setDopplerFactor(float factor);
374 virtual void setDistanceModel(DistanceModel model);
375
376 virtual void seekSynchronizer(double time);
377 virtual double getSynchronizerPosition();
378 virtual void playSynchronizer();
379 virtual void stopSynchronizer();
380 virtual void setSyncCallback(syncFunction function, void* data);
381 virtual int isSynchronizerPlaying();
382};
383
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition Audaspace.h:119
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition Audaspace.h:116
#define AUD_API
Used for exporting symbols in the shared library.
Definition Audaspace.h:93
unsigned char data_t
Sample data type (format samples)
Definition Audaspace.h:129
The Buffer class.
Defines the I3DDevice interface as well as the different distance models.
DistanceModel
Possible distance models for the 3D device.
Definition I3DDevice.h:35
The I3DHandle interface.
The IDevice interface.
Defines the IHandle interface as well as possible states of the handle.
Status
Status of a playback handle.
Definition IHandle.h:31
void(* stopCallback)(void *)
The stopCallback is called when a handle reaches the end of the stream and thus gets stopped.
Definition IHandle.h:42
ResampleQuality
Resampling algorithm and quality.
Definition Specification.h:88
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality.
Definition Buffer.h:34
This class maps a sound source's channels to a specific output channel count.
Definition ChannelMapperReader.h:35
The I3DDevice interface represents an output device for 3D sound.
Definition I3DDevice.h:53
The I3DHandle interface represents a playback handle for 3D sources.
Definition I3DHandle.h:39
The IDevice interface represents an output device for sound sources.
Definition IDevice.h:46
void(* syncFunction)(void *, int, float)
The syncFunction is called when a synchronization event happens.
Definition IDevice.h:120
The IHandle interface represents a playback handles of a specific device.
Definition IHandle.h:49
This abstract class is able to mix audiosignals with same channel count and sample rate and convert i...
Definition Mixer.h:40
This class reads another reader and changes it's pitch.
Definition PitchReader.h:33
This class represents a quaternion used for 3D rotations.
Definition Math3D.h:206
This is the base class for all resampling readers.
Definition ResampleReader.h:33
virtual bool isRelative()
Checks whether the source location, velocity and orientation are relative to the listener.
virtual bool setVolumeMaximum(float volume)
Sets the maximum volume of a source.
virtual bool setPitch(float pitch)
Sets the pitch of a playing sound.
float m_distance_reference
Reference distance;.
Definition SoftwareDevice.h:120
virtual bool setStopCallback(stopCallback callback=0, void *data=0)
Sets the callback function that's called when the end of a playing sound is reached.
virtual bool setVolume(float volume)
Sets the volume of a playing sound.
virtual bool setLocation(const Vector3 &location)
Sets the location of the source.
virtual float getVolumeMinimum()
Retrieves the minimum volume of a source.
std::shared_ptr< ResampleReader > m_resampler
The resample reader in between.
Definition SoftwareDevice.h:69
float m_old_volume
The previous calculated final volume of the source.
Definition SoftwareDevice.h:93
virtual bool setLoopCount(int count)
Sets the loop count of a playing sound.
SoftwareDevice * m_device
Own device.
Definition SoftwareDevice.h:147
std::shared_ptr< PitchReader > m_pitch
The pitch reader in between.
Definition SoftwareDevice.h:66
float m_user_pan
The user set panning for non-3D sources.
Definition SoftwareDevice.h:87
virtual bool seek(double position)
Seeks in a played back sound.
float m_attenuation
Attenuation.
Definition SoftwareDevice.h:123
virtual Status getStatus()
Returns the status of a played back sound.
virtual double getPosition()
Retrieves the current playback position of a sound.
virtual bool getKeep()
Gets the behaviour of the device for a played back sound when the sound doesn't return any more sampl...
virtual bool stop()
Stops a played back or paused sound.
void setSpecs(Specs specs)
Sets the audio output specification of the readers.
float m_volume
The calculated final volume of the source.
Definition SoftwareDevice.h:90
std::shared_ptr< ChannelMapperReader > m_mapper
The channel mapper reader in between.
Definition SoftwareDevice.h:72
int m_flags
Rendering flags.
Definition SoftwareDevice.h:135
virtual bool pause()
Pauses a played back sound.
Quaternion m_orientation
Orientation in 3D Space.
Definition SoftwareDevice.h:105
Vector3 m_velocity
Velocity in 3D Space.
Definition SoftwareDevice.h:102
bool m_first_reading
Whether the source is being read for the first time.
Definition SoftwareDevice.h:75
virtual bool setConeAngleOuter(float angle)
Sets the outer opening angle of the cone of a source.
virtual float getVolumeMaximum()
Retrieves the maximum volume of a source.
bool m_relative
Whether the position to the listener is relative or absolute.
Definition SoftwareDevice.h:108
virtual bool setConeAngleInner(float angle)
Sets the inner opening angle of the cone of a source.
int m_loopcount
The loop count of the source.
Definition SoftwareDevice.h:96
virtual float getPitch()
Retrieves the pitch of a playing sound.
float m_cone_angle_inner
Cone inner angle.
Definition SoftwareDevice.h:129
virtual bool setVelocity(const Vector3 &velocity)
Sets the velocity of the source.
float m_volume_max
Maximum volume.
Definition SoftwareDevice.h:111
virtual bool setDistanceMaximum(float distance)
Sets the maximum distance of a source.
virtual Vector3 getLocation()
Retrieves the location of the source.
virtual bool setDistanceReference(float distance)
Sets the reference distance of a source.
Vector3 m_location
Location in 3D Space.
Definition SoftwareDevice.h:99
virtual bool setAttenuation(float factor)
Sets the attenuation of a source.
virtual bool setRelative(bool relative)
Sets whether the source location, velocity and orientation are relative to the listener.
virtual bool setOrientation(const Quaternion &orientation)
Sets the orientation of the source.
virtual Quaternion getOrientation()
Retrieves the orientation of the source.
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)
Creates a new software handle.
virtual float getConeVolumeOuter()
Retrieves the outer volume of the cone of a source.
virtual bool setVolumeMinimum(float volume)
Sets the minimum volume of a source.
virtual float getAttenuation()
Retrieves the attenuation of a source.
float m_cone_angle_outer
Cone outer angle.
Definition SoftwareDevice.h:126
float m_distance_max
Maximum distance.
Definition SoftwareDevice.h:117
void update()
Updates the handle's playback parameters.
float m_user_volume
The user set volume of the source.
Definition SoftwareDevice.h:84
bool pause(bool keep)
This method is for internal use only.
float m_user_pitch
The user set pitch of the source.
Definition SoftwareDevice.h:81
std::shared_ptr< IReader > m_reader
The reader source.
Definition SoftwareDevice.h:63
void * m_stop_data
Stop callback data.
Definition SoftwareDevice.h:141
virtual bool setConeVolumeOuter(float volume)
Sets the outer volume of the cone of a source.
virtual float getDistanceMaximum()
Retrieves the maximum distance of a source.
virtual Vector3 getVelocity()
Retrieves the velocity of the source.
float m_cone_volume_outer
Cone outer volume.
Definition SoftwareDevice.h:132
virtual float getConeAngleOuter()
Retrieves the outer opening angle of the cone of a source.
virtual int getLoopCount()
Retrieves the loop count of a playing sound.
virtual bool setKeep(bool keep)
Sets the behaviour of the device for a played back sound when the sound doesn't return any more sampl...
float m_volume_min
Minimum volume.
Definition SoftwareDevice.h:114
bool m_keep
Whether to keep the source if end of it is reached.
Definition SoftwareDevice.h:78
virtual float getDistanceReference()
Retrieves the reference distance of a source.
Status m_status
Current status of the handle.
Definition SoftwareDevice.h:144
stopCallback m_stop
The stop callback.
Definition SoftwareDevice.h:138
virtual bool resume()
Resumes a paused sound.
virtual float getVolume()
Retrieves the volume of a playing sound.
virtual float getConeAngleInner()
Retrieves the inner opening angle of the cone of a source.
DeviceSpecs m_specs
The specification of the device.
Definition SoftwareDevice.h:225
std::shared_ptr< Mixer > m_mixer
The mixer.
Definition SoftwareDevice.h:230
static void setPanning(IHandle *handle, float pan)
Sets the panning of a specific handle.
virtual float getDopplerFactor() const
Retrieves the doppler factor.
virtual float getVolume() const
Retrieves the overall device volume.
virtual void setListenerLocation(const Vector3 &location)
Sets the listener location.
virtual Quaternion getListenerOrientation() const
Retrieves the listener orientation.
virtual DeviceSpecs getSpecs() const
Returns the specification of the device.
virtual Vector3 getListenerLocation() const
Retrieves the listener location.
void setSpecs(DeviceSpecs specs)
Sets the audio output specification of the device.
virtual void setDopplerFactor(float factor)
Sets the doppler factor.
virtual void setDistanceModel(DistanceModel model)
Sets the distance model.
virtual void lock()
Locks the device.
virtual void setListenerVelocity(const Vector3 &velocity)
Sets the listener velocity.
virtual void unlock()
Unlocks the previously locked device.
virtual std::shared_ptr< IHandle > play(std::shared_ptr< ISound > sound, bool keep=false)
Plays a sound source.
virtual Vector3 getListenerVelocity() const
Retrieves the listener velocity.
void create()
Initializes member variables.
virtual void setListenerOrientation(const Quaternion &orientation)
Sets the listener orientation.
virtual void setVolume(float volume)
Sets the overall device volume.
ResampleQuality m_quality
Resampling quality.
Definition SoftwareDevice.h:235
void setQuality(ResampleQuality quality)
Sets the resampling quality.
void mix(data_t *buffer, int length)
Mixes the next samples into the buffer.
virtual std::shared_ptr< IHandle > play(std::shared_ptr< IReader > reader, bool keep=false)
Plays a sound source.
void destroy()
Uninitializes member variables.
void setSpecs(Specs specs)
Sets the audio output specification of the device.
virtual void setSpeedOfSound(float speed)
Sets the speed of sound.
virtual DistanceModel getDistanceModel() const
Retrieves the distance model.
virtual void stopAll()
Stops all playing sounds.
virtual void playing(bool playing)=0
This function tells the device, to start or pause playback.
SoftwareDevice()
Empty default constructor.
virtual float getSpeedOfSound() const
Retrieves the speed of sound.
This class represents a 3 dimensional vector.
Definition Math3D.h:36
Specification of a sound device.
Definition Specification.h:129
Specification of a sound source.
Definition Specification.h:119