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.2.0 $Rev: 2017 $
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 
126  // This method returns a left sample at a given time.
127  short getSampleLeft(double a_time);
128 
129  // This method returns a right sample at a given time.
130  short getSampleRight(double a_time);
131 
133  bool setPitch(const float a_pitch);
134 
136  float getPitch() { return (m_pitch); }
137 
139  bool setGain(const float a_gain);
140 
142  float getGain() { return (m_gain); }
143 
145  bool setSourcePos(const cVector3d a_sourcePos);
146 
149 
151  bool setSourceVel(const cVector3d a_sourceVel);
152 
155 
157  bool setLoop(const bool a_loop);
158 
160  bool getLoop() { return (m_loop); }
161 
162 
163  //--------------------------------------------------------------------------
164  // PROTECTED METHODS:
165  //--------------------------------------------------------------------------
166 
167 protected:
168 
170  bool checkError();
171 
172 
173  //--------------------------------------------------------------------------
174  // PROTECTED MEMBERS:
175  //--------------------------------------------------------------------------
176 
177 protected:
178 
180  unsigned int m_source;
181 
183  float m_pitch;
184 
186  float m_gain;
187 
190 
193 
195  bool m_loop;
196 
199 };
200 
201 //------------------------------------------------------------------------------
202 } // namespace chai3d
203 //------------------------------------------------------------------------------
204 
205 //------------------------------------------------------------------------------
206 #endif
207 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
cVector3d m_sourcePos
Position of source in world coordinates.
Definition: CAudioSource.h:189
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:411
Implements an audio Buffer.
This class implements an audio source.
Definition: CAudioSource.h:78
float m_pitch
Audio pitch value.
Definition: CAudioSource.h:183
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:180
cAudioBuffer * getAudioBuffer()
This method returns the audio buffer.
Definition: CAudioSource.h:103
virtual ~cAudioSource()
Destructor of cAudioSource.
Definition: CAudioSource.cpp:81
short getSampleLeft(double a_time)
Definition: CAudioSource.cpp:243
bool setPitch(const float a_pitch)
This method sets the audio pitch. The default value is 1.0.
Definition: CAudioSource.cpp:287
bool getLoop()
This method returns the status of loop playing.
Definition: CAudioSource.h:160
This class implements an audio buffer.
Definition: CAudioBuffer.h:78
float getGain()
This method returns the audio gain value.
Definition: CAudioSource.h:142
cAudioBuffer * m_audioBuffer
Audio buffer.
Definition: CAudioSource.h:198
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:136
bool m_loop
Loop playing mode.
Definition: CAudioSource.h:195
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:186
bool setLoop(const bool a_loop)
This method enables or disables loop playing.
Definition: CAudioSource.cpp:384
bool setSourceVel(const cVector3d a_sourceVel)
This method sets the velocity of the audio source in world coordinates.
Definition: CAudioSource.cpp:357
cVector3d getSourcePos()
This method returns the position of the audio source in world coordinates.
Definition: CAudioSource.h:148
short getSampleRight(double a_time)
Definition: CAudioSource.cpp:265
bool setGain(const float a_gain)
This method sets the audio gain value. Set value to 0.0 to disable sound.
Definition: CAudioSource.cpp:309
bool setSourcePos(const cVector3d a_sourcePos)
This method sets the position of the audio source in world coordinates.
Definition: CAudioSource.cpp:331
cVector3d getSourceVel()
This method returns the velocity of the audio source in world coordinates.
Definition: CAudioSource.h:154
Definition: CAudioBuffer.cpp:56
cVector3d m_sourceVel
Velocity of source in world coordinates.
Definition: CAudioSource.h:192
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