cAudio  2.3.0
3d Audio Engine
IAudioSource.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 "cAudioDefines.h"
8 #include "IRefCounted.h"
9 #include "IAudioDecoder.h"
10 #include "cVector3.h"
11 #include "IEffect.h"
12 #include "IFilter.h"
13 #include "ISourceEventHandler.h"
14 
15 namespace cAudio
16 {
18  class IAudioBuffer : public IRefCounted
19  {
20  public:
21  virtual ~IAudioBuffer() {}
22 
23  virtual bool isValid() const = 0;
24  virtual unsigned getBuffer() const = 0;
25  virtual int getChannels() const = 0;
26 
27  virtual int getTotalAudioSize() const = 0;
28  virtual float getTotalAudioTime() const = 0;
29  };
30 
32  class IAudioSource : public IRefCounted
33  {
34  public:
35  IAudioSource() {}
36  virtual ~IAudioSource() {}
37 
39 
41  virtual bool play() = 0;
42 
44 
47  virtual bool play2d(const bool& toLoop = false) = 0;
48 
50 
55  virtual bool play3d(const cVector3& position, const float& soundstr = 1.0 , const bool& toLoop = false) = 0;
56 
58  virtual void pause() = 0;
59 
61  virtual void stop() = 0;
62 
64 
65  virtual void loop(const bool& toLoop) = 0;
66 
68 
72  virtual bool seek(const float& seconds, bool relative = false) = 0;
73 
75 
77  virtual bool setBuffer(IAudioBuffer* buffer) = 0;
78 
80 
81  virtual IAudioBuffer *getBuffer() = 0;
82 
84  virtual float getTotalAudioTime() = 0;
85 
87  virtual int getTotalAudioSize() = 0;
88 
90  virtual int getCompressedAudioSize() = 0;
91 
93  virtual float getCurrentAudioTime() = 0;
94 
96  virtual int getCurrentAudioPosition() = 0;
97 
99  virtual int getCurrentCompressedAudioPosition() = 0;
100 
102  virtual bool update() = 0;
103 
105  virtual bool isValid() const = 0; //
106 
108  virtual bool isPlaying() const = 0;
109 
111  virtual bool isPaused() const = 0;
112 
114  virtual bool isStopped() const = 0;
115 
117  virtual bool isLooping() const = 0;
118 
120 
122  virtual void setPosition(const cVector3& position) = 0;
123 
125 
127  virtual void setVelocity(const cVector3& velocity) = 0;
128 
130 
132  virtual void setDirection(const cVector3& direction) = 0;
133 
135 
138  virtual void setRolloffFactor(const float& rolloff) = 0;
139 
141 
144  virtual void setStrength(const float& soundstrength) = 0;
145 
147 
149  virtual void setMinDistance(const float& minDistance) = 0;
150 
152 
154  virtual void setMaxAttenuationDistance(const float& maxDistance) = 0;
155 
157 
159  virtual void setPitch(const float& pitch) = 0;
160 
162 
164  virtual void setVolume(const float& volume) = 0;
165 
167 
169  virtual void setMinVolume(const float& minVolume) = 0;
170 
172 
174  virtual void setMaxVolume(const float& maxVolume) = 0;
175 
177 
180  virtual void setInnerConeAngle(const float& innerAngle) = 0;
181 
183 
186  virtual void setOuterConeAngle(const float& outerAngle) = 0;
187 
189 
191  virtual void setOuterConeVolume(const float& outerVolume) = 0;
192 
194 
196  virtual void setDopplerStrength(const float& dstrength) = 0;
197 
199 
201  virtual void setDopplerVelocity(const cVector3& dvelocity) = 0;
202 
204 
206  virtual void move(const cVector3& position) = 0;
207 
209  virtual cVector3 getPosition() const = 0;
210 
212  virtual cVector3 getVelocity() const = 0;
213 
215  virtual cVector3 getDirection() const = 0;
216 
218  virtual float getRolloffFactor() const = 0;
219 
221  virtual float getStrength() const = 0;
222 
224  virtual float getMinDistance() const = 0;
225 
227  virtual float getMaxDistance() const = 0;
228 
230  virtual bool isRelative() const = 0;
231 
233  virtual float calculateGain() const = 0;
234 
236  virtual float getPitch() const = 0;
237 
239  virtual float getVolume() const = 0;
240 
242  virtual float getMinVolume() const = 0;
243 
245  virtual float getMaxVolume() const = 0;
246 
248  virtual float getInnerConeAngle() const = 0;
249 
251  virtual float getOuterConeAngle() const = 0;
252 
254  virtual float getOuterConeVolume() const = 0;
255 
257  virtual float getDopplerStrength() const = 0;
258 
260  virtual cVector3 getDopplerVelocity() const = 0;
261 
263 
265  virtual void registerEventHandler(ISourceEventHandler* handler) = 0;
266 
268 
270  virtual void unRegisterEventHandler(ISourceEventHandler* handler) = 0;
271 
273  virtual void unRegisterAllEventHandlers() = 0;
274 
275 #if CAUDIO_EFX_ENABLED == 1
276  virtual unsigned int getNumEffectSlotsAvailable() const = 0;
278 
280 
284  virtual bool attachEffect(unsigned int slot, IEffect* effect) = 0;
285 
287 
289  virtual void removeEffect(unsigned int slot) = 0;
290 
292 
295  virtual bool attachFilter(IFilter* filter) = 0;
296 
298  virtual void removeFilter() = 0;
299 #endif
300 
301  protected:
302  private:
303  };
304 };
virtual float getMaxVolume() const =0
Returns the maximum volume that the source can achieve.
virtual float getStrength() const =0
Returns the strength of the source.
virtual IAudioBuffer * getBuffer()=0
Get the audio buffer associated with the source.
virtual void setRolloffFactor(const float &rolloff)=0
Sets the factor used in attenuating the source over distance.
virtual float getPitch() const =0
Returns the pitch of the source.
virtual void loop(const bool &toLoop)=0
Controls whether the source should loop or not.
virtual float getMinDistance() const =0
Returns the distance from the source where attenuation will begin.
virtual bool isPlaying() const =0
Returns if the source is playing.
virtual cVector3 getPosition() const =0
Returns the audio objects position.
virtual bool update()=0
Normally called every frame by the audio manager to update the internal buffers. Note: For internal u...
virtual void stop()=0
Stops playback of the sound source.
virtual float getInnerConeAngle() const =0
Returns the angle of the inner sound cone of the source.
virtual void registerEventHandler(ISourceEventHandler *handler)=0
Registers a new event handler to this source.
virtual float getDopplerStrength() const =0
Returns the doppler strength, which enhances or diminishes the doppler effect.
virtual int getCompressedAudioSize()=0
Returns the original size of the audio stream. See IAudioDecoder for details.
virtual bool isRelative() const =0
Return true for 2d sounds, false for 3d sounds.
virtual void setVelocity(const cVector3 &velocity)=0
Sets the current velocity of the source for doppler effects.
virtual float getOuterConeVolume() const =0
Returns how much the volume of the source is scaled in the outer cone.
virtual void setMinDistance(const float &minDistance)=0
Sets the distance from the source where attenuation will begin.
virtual cVector3 getDirection() const =0
Returns the audio objects direction.
virtual void setMinVolume(const float &minVolume)=0
Sets the minimum volume that the source can be attenuated to.
virtual cVector3 getVelocity() const =0
Returns the audio objects velocity.
virtual float calculateGain() const =0
Return gain, taking into account volume as well as distance attenuation.
virtual void setStrength(const float &soundstrength)=0
Sets how well the source carries over distance.
virtual cVector3 getDopplerVelocity() const =0
Returns the override for the doppler velocity vector.
virtual void unRegisterEventHandler(ISourceEventHandler *handler)=0
Removes a specified event handler from this source.
Interface for a single audio source, which allow you to manipulate sound sources (speakers) in 2D or ...
Definition: IAudioSource.h:32
virtual void setVolume(const float &volume)=0
Sets the source volume before attenuation and other effects.
virtual float getRolloffFactor() const =0
Returns the factor used in attenuating the source over distance.
virtual void setDopplerVelocity(const cVector3 &dvelocity)=0
Overrides the doppler velocity vector. It is usually better to let the engine take care of it automat...
virtual void setOuterConeAngle(const float &outerAngle)=0
Sets the angle of the outer sound cone of the source. The cone opens up in the direction of the sourc...
Applies reference counting to certain cAudio objects.
Definition: IRefCounted.h:12
Interface for event handlers on Audio Sources.
virtual float getMinVolume() const =0
Returns the minimum volume that the source can be attenuated to.
virtual float getTotalAudioTime()=0
Returns the total amount of time in the audio stream. See IAudioDecoder for details.
virtual float getCurrentAudioTime()=0
Returns the current position in the audio stream in seconds. See IAudioDecoder for details.
virtual bool isLooping() const =0
Returns if the source is looping.
virtual bool play3d(const cVector3 &position, const float &soundstr=1.0, const bool &toLoop=false)=0
Plays the source in 3D mode.
virtual void setPitch(const float &pitch)=0
Sets the pitch of the source.
virtual bool isStopped() const =0
Returns if the source is stopped.
Class for manipulating vectors in 3D space.
Definition: cVector3.h:22
virtual bool isValid() const =0
Returns if the source is ready to be used.
virtual float getMaxDistance() const =0
Returns the distance from the source where attenuation will stop.
virtual bool seek(const float &seconds, bool relative=false)=0
Seeks through the audio stream to a specific spot.
virtual void setDopplerStrength(const float &dstrength)=0
Sets the doppler strength, which enhances or diminishes the doppler effect. Can be used to exaggerate...
virtual float getOuterConeAngle() const =0
Returns the angle of the outer sound cone of the source.
virtual void setOuterConeVolume(const float &outerVolume)=0
Sets how much the volume of the source is scaled in the outer cone.
virtual void setMaxAttenuationDistance(const float &maxDistance)=0
Sets the distance from the source where attenuation will stop.
virtual void pause()=0
Pauses playback of the sound source.
virtual void setMaxVolume(const float &maxVolume)=0
Sets the maximum volume that the source can achieve.
virtual void setDirection(const cVector3 &direction)=0
Sets the direction the source is facing.
interface for a sample (audio buffer): completely loaded into memory, shareable across sources
Definition: IAudioSource.h:18
virtual void unRegisterAllEventHandlers()=0
Removes all event handlers attached to this source.
virtual void setPosition(const cVector3 &position)=0
Sets the position of the source in 3D space.
virtual bool setBuffer(IAudioBuffer *buffer)=0
Change the audio buffer associated with the source.
virtual bool play2d(const bool &toLoop=false)=0
Plays the source in 2D mode.
virtual bool play()=0
Plays the source with the last set parameters.
virtual void move(const cVector3 &position)=0
Convenience function to automatically set the velocity and position for you in a single call.
virtual float getVolume() const =0
Returns the source volume before attenuation and other effects.
virtual void setInnerConeAngle(const float &innerAngle)=0
Sets the angle of the inner sound cone of the source. The cone opens up in the direction of the sourc...
virtual int getTotalAudioSize()=0
Returns the total decoded size of the audio stream. See IAudioDecoder for details.
virtual int getCurrentAudioPosition()=0
Returns the current position in the decoded audio stream in bytes. See IAudioDecoder for details.
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:15
virtual int getCurrentCompressedAudioPosition()=0
Returns the current position in the original audio stream in bytes. See IAudioDecoder for details.
virtual bool isPaused() const =0
Returns if the source is paused.