CAudioSource.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.1.1 $Rev: 1244 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CAudioSourceH
46 #define CAudioSourceH
47 //------------------------------------------------------------------------------
48 #include "audio/CAudioBuffer.h"
49 //------------------------------------------------------------------------------
50 
51 //------------------------------------------------------------------------------
52 namespace chai3d {
53 //------------------------------------------------------------------------------
54 
55 //==============================================================================
62 //==============================================================================
63 
64 //==============================================================================
77 //==============================================================================
79 {
80  //--------------------------------------------------------------------------
81  // CONSTRUCTOR & DESTRUCTOR:
82  //--------------------------------------------------------------------------
83 
84 public:
85 
87  cAudioSource();
88 
90  virtual ~cAudioSource();
91 
92 
93  //--------------------------------------------------------------------------
94  // PUBLIC METHODS:
95  //--------------------------------------------------------------------------
96 
97 public:
98 
100  bool setAudioBuffer(cAudioBuffer* a_audioBuffer);
101 
104 
106  bool play();
107 
109  bool isPlaying();
110 
112  bool pause();
113 
115  bool stop();
116 
118  bool rewind();
119 
121  bool setPosTime(const float a_time);
122 
124  float getPosTime();
125 
127  bool setPitch(const float a_pitch);
128 
130  float getPitch() { return (m_pitch); }
131 
133  bool setGain(const float a_gain);
134 
136  float getGain() { return (m_gain); }
137 
139  bool setSourcePos(const cVector3d a_sourcePos);
140 
143 
145  bool setSourceVel(const cVector3d a_sourceVel);
146 
149 
151  bool setLoop(const bool a_loop);
152 
154  bool getLoop() { return (m_loop); }
155 
156 
157  //--------------------------------------------------------------------------
158  // PROTECTED METHODS:
159  //--------------------------------------------------------------------------
160 
161 protected:
162 
164  bool checkError();
165 
166 
167  //--------------------------------------------------------------------------
168  // PROTECTED MEMBERS:
169  //--------------------------------------------------------------------------
170 
171 protected:
172 
174  unsigned int m_source;
175 
177  float m_pitch;
178 
180  float m_gain;
181 
184 
187 
189  bool m_loop;
190 
193 };
194 
195 //------------------------------------------------------------------------------
196 } // namespace chai3d
197 //------------------------------------------------------------------------------
198 
199 //------------------------------------------------------------------------------
200 #endif
201 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
cVector3d m_sourcePos
Position of source in world coordinates.
Definition: CAudioSource.h:183
bool play()
This method plays the audio buffer.
Definition: CAudioSource.cpp:116
bool setAudioBuffer(cAudioBuffer *a_audioBuffer)
This method sets the audio buffer.
Definition: CAudioSource.cpp:98
bool rewind()
This method rewinds the audio source.
Definition: CAudioSource.cpp:189
bool checkError()
This method checks for any OpenAL errors.
Definition: CAudioSource.cpp:367
Implements an audio Buffer.
This class implements an audio source.
Definition: CAudioSource.h:78
float m_pitch
Audio pitch value.
Definition: CAudioSource.h:177
bool isPlaying()
This method returns true if the audio source is currently playing, false otherwise.
Definition: CAudioSource.cpp:133
unsigned int m_source
OpenAL audio source ID.
Definition: CAudioSource.h:174
cAudioBuffer * getAudioBuffer()
This method returns the audio buffer.
Definition: CAudioSource.h:103
virtual ~cAudioSource()
Destructor of cAudioSource.
Definition: CAudioSource.cpp:81
bool setPitch(const float a_pitch)
This method sets the audio pitch. The default value is 1.0.
Definition: CAudioSource.cpp:243
bool getLoop()
This method returns the status of loop playing.
Definition: CAudioSource.h:154
This class implements an audio buffer.
Definition: CAudioBuffer.h:78
float getGain()
This method returns the audio gain value.
Definition: CAudioSource.h:136
cAudioBuffer * m_audioBuffer
Audio buffer.
Definition: CAudioSource.h:192
bool stop()
This method stops the audio source from playing.
Definition: CAudioSource.cpp:172
float getPitch()
This method returns the audio pitch value.
Definition: CAudioSource.h:130
bool m_loop
Loop playing mode.
Definition: CAudioSource.h:189
float getPosTime()
This method returns the current playing position on audio buffer.
Definition: CAudioSource.cpp:226
float m_gain
Audio gain value.
Definition: CAudioSource.h:180
bool setLoop(const bool a_loop)
This method enables or disables loop playing.
Definition: CAudioSource.cpp:340
bool setSourceVel(const cVector3d a_sourceVel)
This method sets the velocity of the audio source in world coordinates.
Definition: CAudioSource.cpp:313
cVector3d getSourcePos()
This method returns the position of the audio source in world coordinates.
Definition: CAudioSource.h:142
bool setGain(const float a_gain)
This method sets the audio gain value. Set value to 0.0 to disable sound.
Definition: CAudioSource.cpp:265
bool setSourcePos(const cVector3d a_sourcePos)
This method sets the position of the audio source in world coordinates.
Definition: CAudioSource.cpp:287
cVector3d getSourceVel()
This method returns the velocity of the audio source in world coordinates.
Definition: CAudioSource.h:148
Definition: CAudioBuffer.cpp:56
cVector3d m_sourceVel
Velocity of source in world coordinates.
Definition: CAudioSource.h:186
bool setPosTime(const float a_time)
This method set the current playing position of the audio buffer.
Definition: CAudioSource.cpp:209
bool pause()
This method pauses the audio source from playing.
Definition: CAudioSource.cpp:155
cAudioSource()
Constructor of cAudioSource.
Definition: CAudioSource.cpp:60