cAudio 2.3.0
3d Audio Engine
Loading...
Searching...
No Matches
cAudioSource.h
1// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2// This file is part of the "cAudio Engine"
3// For conditions of distribution and use, see copyright notice in cAudio.h
4
5#pragma once
6
7#include <list>
8#include <string>
9#include <vector>
10
11#include "cOpenALUtil.h"
12#include "cMutex.h"
13#include "cEFXFunctions.h"
14#include "cMemoryOverride.h"
15#include "IAudioSource.h"
16#include "cVector3.h"
17#include "ILogger.h"
18#include "cSTLAllocator.h"
19#include "IAudioDeviceContext.h"
20
21namespace cAudio
22{
23
25 {
26 public:
27
28 enum Events{
29 ON_UPDATE,
30 ON_RELEASE,
31 ON_PLAY,
32 ON_PAUSE,
33 ON_STOP,
34 };
35
37 virtual ~cAudioSourceBase();
38
39 virtual bool isPlaying() const;
40 virtual bool isPaused() const;
41 virtual bool isStopped() const;
42
43 virtual void setPosition(const cVector3& position);
44 virtual void setVelocity(const cVector3& velocity);
45 virtual void setDirection(const cVector3& direction);
46
47 virtual void setRolloffFactor(const float& rolloff);
48 virtual void setStrength(const float& soundstrength);
49 virtual void setMinDistance(const float& minDistance);
50 virtual void setMaxAttenuationDistance(const float& maxDistance);
51
52 virtual void setPitch(const float& pitch);
53 virtual void setVolume(const float& volume);
54 virtual void setMinVolume(const float& minVolume);
55 virtual void setMaxVolume(const float& maxVolume);
56
57 virtual void setInnerConeAngle(const float& innerAngle);
58 virtual void setOuterConeAngle(const float& outerAngle);
59 virtual void setOuterConeVolume(const float& outerVolume);
60
61 virtual void setDopplerStrength(const float& dstrength);
62 virtual void setDopplerVelocity(const cVector3& dvelocity);
63
64 virtual void move(const cVector3& position);
65
66 virtual cVector3 getPosition() const;
67 virtual cVector3 getVelocity() const;
68 virtual cVector3 getDirection() const;
69
70 virtual float getRolloffFactor() const;
71 virtual float getStrength() const;
72 virtual float getMinDistance() const;
73 virtual float getMaxDistance() const;
74
75 virtual bool isRelative() const;
76 virtual float calculateGain() const;
77
78 virtual float getPitch() const;
79 virtual float getVolume() const;
80 virtual float getMinVolume() const;
81 virtual float getMaxVolume() const;
82
83 virtual float getInnerConeAngle() const;
84 virtual float getOuterConeAngle() const;
85 virtual float getOuterConeVolume() const;
86
87 virtual float getDopplerStrength() const;
88 virtual cVector3 getDopplerVelocity() const;
89
90 virtual void registerEventHandler(ISourceEventHandler* handler);
91 virtual void unRegisterEventHandler(ISourceEventHandler* handler);
92 virtual void unRegisterAllEventHandlers();
93
94 protected:
97
99 void signalEvent(Events sevent);
100
103
105 float Volume;
106
108 ALuint Source;
109
110 ALenum oldState;
111
113 cAudioVector<ISourceEventHandler*>::Type eventHandlerList;
114 };
115
117 public:
118#if CAUDIO_EFX_ENABLED == 1
119 cAudioSource(IAudioDecoder* decoder, IAudioDeviceContext* context, cEFXFunctions* oALFunctions);
120#else
122#endif
124
125 virtual bool play();
126 virtual bool play2d(const bool& toLoop = false);
127 virtual bool play3d(const cVector3& position, const float& soundstr = 1.0 , const bool& toLoop = false);
128
129 virtual void pause();
130 virtual void stop();
131 virtual void loop(const bool& toLoop);
132 virtual bool seek(const float& seconds, bool relative = false);
133
134 virtual bool setBuffer(IAudioBuffer* buffer) { return false; }
135 virtual IAudioBuffer *getBuffer() { return NULL; }
136
137 virtual float getTotalAudioTime();
138 virtual int getTotalAudioSize();
139 virtual int getCompressedAudioSize();
140
141 virtual float getCurrentAudioTime();
142 virtual int getCurrentAudioPosition();
144
145 virtual bool update();
146
147 virtual bool isValid() const;
148 virtual bool isLooping() const;
149
150 virtual bool drop();
151
152#if CAUDIO_EFX_ENABLED == 1
153 virtual unsigned int getNumEffectSlotsAvailable() const;
154 virtual bool attachEffect(unsigned int slot, IEffect* effect);
155 virtual void removeEffect(unsigned int slot);
156
157 virtual bool attachFilter(IFilter* filter);
158 virtual void removeFilter();
159#endif
160
161 private:
163 void empty();
165 bool stream(ALuint buffer);
166
168 ALuint Buffers[CAUDIO_SOURCE_NUM_BUFFERS];
169
171 IAudioDecoder* Decoder;
172
174 bool Loop;
176 bool Valid;
177
179 float BufferTime;
181 int BufferPosition;
182
183#if CAUDIO_EFX_ENABLED == 1
185 cEFXFunctions* EFX;
187 void updateFilter(bool remove = false);
189 void updateEffect(unsigned int slot, bool remove = false);
190
192 IEffect* Effects[CAUDIO_SOURCE_MAX_EFFECT_SLOTS];
194 unsigned int LastEffectTimeStamp[CAUDIO_SOURCE_MAX_EFFECT_SLOTS];
195
197 IFilter* Filter;
199 unsigned int LastFilterTimeStamp;
200
202 unsigned int EffectSlotsAvailable;
203#endif
204 };
205};
interface for a sample (audio buffer): completely loaded into memory, shareable across sources
Definition: IAudioSource.h:19
Interface for all Audio Decoders in cAudio.
Definition: IAudioDecoder.h:16
Interface for a single audio source, which allow you to manipulate sound sources (speakers) in 2D or ...
Definition: IAudioSource.h:33
Interface for event handlers on Audio Sources.
virtual void setOuterConeVolume(const float &outerVolume)
Sets how much the volume of the source is scaled in the outer cone.
virtual bool isPlaying() const
Returns if the source is playing.
virtual float getOuterConeAngle() const
Returns the angle of the outer sound cone of the source.
virtual void unRegisterAllEventHandlers()
Removes all event handlers attached to this source.
virtual bool isStopped() const
Returns if the source is stopped.
virtual float getMaxVolume() const
Returns the maximum volume that the source can achieve.
void signalEvent(Events sevent)
Signals a event to all event handlers.
virtual void setMaxVolume(const float &maxVolume)
Sets the maximum volume that the source can achieve.
float Volume
Holds the current volume.
Definition: cAudioSource.h:105
virtual void setDopplerVelocity(const cVector3 &dvelocity)
Overrides the doppler velocity vector. It is usually better to let the engine take care of it automat...
virtual float getStrength() const
Returns the strength of the source.
virtual float getMaxDistance() const
Returns the distance from the source where attenuation will stop.
IAudioDeviceContext * Context
The context that owns this source.
Definition: cAudioSource.h:102
virtual float getDopplerStrength() const
Returns the doppler strength, which enhances or diminishes the doppler effect.
virtual float getInnerConeAngle() const
Returns the angle of the inner sound cone of the source.
virtual float getPitch() const
Returns the pitch of the source.
virtual float getOuterConeVolume() const
Returns how much the volume of the source is scaled in the outer cone.
virtual cVector3 getDopplerVelocity() const
Returns the override for the doppler velocity vector.
virtual void setVolume(const float &volume)
Sets the source volume before attenuation and other effects.
virtual float getMinVolume() const
Returns the minimum volume that the source can be attenuated to.
virtual void setMaxAttenuationDistance(const float &maxDistance)
Sets the distance from the source where attenuation will stop.
virtual void setInnerConeAngle(const float &innerAngle)
Sets the angle of the inner sound cone of the source. The cone opens up in the direction of the sourc...
virtual void setRolloffFactor(const float &rolloff)
Sets the factor used in attenuating the source over distance.
virtual void setDirection(const cVector3 &direction)
Sets the direction the source is facing.
virtual void setMinDistance(const float &minDistance)
Sets the distance from the source where attenuation will begin.
virtual void setStrength(const float &soundstrength)
Sets how well the source carries over distance.
virtual void setDopplerStrength(const float &dstrength)
Sets the doppler strength, which enhances or diminishes the doppler effect. Can be used to exaggerate...
virtual bool isRelative() const
Return true for 2d sounds, false for 3d sounds.
virtual float calculateGain() const
Return gain, taking into account volume as well as distance attenuation.
virtual void setOuterConeAngle(const float &outerAngle)
Sets the angle of the outer sound cone of the source. The cone opens up in the direction of the sourc...
virtual void setPosition(const cVector3 &position)
Sets the position of the source in 3D space.
virtual cVector3 getDirection() const
Returns the audio objects direction.
virtual void unRegisterEventHandler(ISourceEventHandler *handler)
Removes a specified event handler from this source.
cAudioVector< ISourceEventHandler * >::Type eventHandlerList
List of registered event handlers.
Definition: cAudioSource.h:113
virtual void setMinVolume(const float &minVolume)
Sets the minimum volume that the source can be attenuated to.
virtual bool isPaused() const
Returns if the source is paused.
virtual float getMinDistance() const
Returns the distance from the source where attenuation will begin.
virtual void move(const cVector3 &position)
Convenience function to automatically set the velocity and position for you in a single call.
virtual void setPitch(const float &pitch)
Sets the pitch of the source.
virtual float getVolume() const
Returns the source volume before attenuation and other effects.
virtual cVector3 getVelocity() const
Returns the audio objects velocity.
virtual void setVelocity(const cVector3 &velocity)
Sets the current velocity of the source for doppler effects.
ALuint Source
OpenAL source.
Definition: cAudioSource.h:108
virtual float getRolloffFactor() const
Returns the factor used in attenuating the source over distance.
cAudioMutex Mutex
Mutex for thread synchronization.
Definition: cAudioSource.h:96
virtual cVector3 getPosition() const
Returns the audio objects position.
virtual void registerEventHandler(ISourceEventHandler *handler)
Registers a new event handler to this source.
virtual void stop()
Stops playback of the sound source.
virtual int getTotalAudioSize()
Returns the total decoded size of the audio stream. See IAudioDecoder for details.
virtual void loop(const bool &toLoop)
Controls whether the source should loop or not.
virtual bool drop()
Decrements the reference count by one. If it hits zero, this object is deleted.
virtual void pause()
Pauses playback of the sound source.
virtual int getCurrentAudioPosition()
Returns the current position in the decoded audio stream in bytes. See IAudioDecoder for details.
virtual bool seek(const float &seconds, bool relative=false)
Seeks through the audio stream to a specific spot.
virtual bool play3d(const cVector3 &position, const float &soundstr=1.0, const bool &toLoop=false)
Plays the source in 3D mode.
virtual bool play2d(const bool &toLoop=false)
Plays the source in 2D mode.
virtual float getCurrentAudioTime()
Returns the current position in the audio stream in seconds. See IAudioDecoder for details.
virtual bool isValid() const
Returns if the source is ready to be used.
virtual bool update()
Normally called every frame by the audio manager to update the internal buffers. Note: For internal u...
virtual float getTotalAudioTime()
Returns the total amount of time in the audio stream. See IAudioDecoder for details.
virtual bool play()
Plays the source with the last set parameters.
virtual IAudioBuffer * getBuffer()
Get the audio buffer associated with the source.
Definition: cAudioSource.h:135
virtual bool setBuffer(IAudioBuffer *buffer)
Change the audio buffer associated with the source.
Definition: cAudioSource.h:134
virtual int getCompressedAudioSize()
Returns the original size of the audio stream. See IAudioDecoder for details.
virtual int getCurrentCompressedAudioPosition()
Returns the current position in the original audio stream in bytes. See IAudioDecoder for details.
virtual bool isLooping() const
Returns if the source is looping.
Overrides the memory allocations for classes derived from it and makes them use the cAudio memory sys...
Class for manipulating vectors in 3D space.
Definition: cVector3.h:23
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:16