CAudioDevice.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 CAudioDeviceH
46 #define CAudioDeviceH
47 //------------------------------------------------------------------------------
48 #include "audio/CAudioBuffer.h"
49 #include "audio/CAudioSource.h"
50 //------------------------------------------------------------------------------
51 #include <vector>
52 //------------------------------------------------------------------------------
53 
54 //------------------------------------------------------------------------------
55 namespace chai3d {
56 //------------------------------------------------------------------------------
57 
58 //==============================================================================
65 //==============================================================================
66 
67 //==============================================================================
80 //==============================================================================
82 {
83  //--------------------------------------------------------------------------
84  // CONSTRUCTOR & DESTRUCTOR:
85  //--------------------------------------------------------------------------
86 
87 public:
88 
90  cAudioDevice();
91 
93  virtual ~cAudioDevice();
94 
95 
96  //--------------------------------------------------------------------------
97  // PUBLIC METHODS:
98  //--------------------------------------------------------------------------
99 
100 public:
101 
103  bool setListenerPos(const cVector3d& a_listenerPos);
104 
107 
109  bool setListenerRot(const cMatrix3d& a_listenerRot);
110 
112  bool setListenerRot(const cVector3d& a_lookAt, const cVector3d& a_up);
113 
116 
118  bool setListenerVel(const cVector3d& a_listenerVel);
119 
122 
125 
127  bool deleteAudioBuffer(cAudioBuffer* a_audioBuffer);
128 
130  void deleteAllAudioBuffers();
131 
134 
136  bool deleteAudioSource(cAudioSource* a_audioSource);
137 
139  void deleteAllAudioSources();
140 
141 
142  //--------------------------------------------------------------------------
143  // PROTECTED METHODS:
144  //--------------------------------------------------------------------------
145 
146 protected:
147 
149  bool open();
150 
152  bool close();
153 
155  bool checkError();
156 
157 
158  //--------------------------------------------------------------------------
159  // PROTECTED MEMBERS:
160  //--------------------------------------------------------------------------
161 
162 protected:
163 
165  void* m_device;
166 
168  void* m_context;
169 
172 
175 
178 
180  bool m_active;
181 
183  std::vector<cAudioBuffer*> m_audioBuffers;
184 
186  std::vector<cAudioSource*> m_audioSources;
187 };
188 
189 //------------------------------------------------------------------------------
190 } // namespace chai3d
191 //------------------------------------------------------------------------------
192 
193 //------------------------------------------------------------------------------
194 #endif
195 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
bool open()
This method opens this audio device context.
Definition: CAudioDevice.cpp:98
bool deleteAudioSource(cAudioSource *a_audioSource)
This method deletes an audio source passed as argument.
Definition: CAudioDevice.cpp:369
bool close()
This method closes this audio device context.
Definition: CAudioDevice.cpp:129
cVector3d m_listenerPos
Position of listener in world coordinates.
Definition: CAudioDevice.h:171
Implements an audio Buffer.
This class implements an audio source.
Definition: CAudioSource.h:78
void deleteAllAudioBuffers()
This method deletes all allocated audio buffers.
Definition: CAudioDevice.cpp:326
Implements of an audio source.
cAudioBuffer * newAudioBuffer()
This method creates a new audio buffer that holds audio data.
Definition: CAudioDevice.cpp:273
bool setListenerPos(const cVector3d &a_listenerPos)
This method sets the position of the listener in world coordinates.
Definition: CAudioDevice.cpp:165
bool setListenerRot(const cMatrix3d &a_listenerRot)
This method sets the orientation of the listener in world coordinates.
Definition: CAudioDevice.cpp:194
std::vector< cAudioBuffer * > m_audioBuffers
List of allocated audio buffers.
Definition: CAudioDevice.h:183
This class implements an audio buffer.
Definition: CAudioBuffer.h:78
cMatrix3d getListenerRot()
This method returns the position of the listener in world coordinates.
Definition: CAudioDevice.h:115
This class implements a 3D matrix.
Definition: CMatrix3d.h:97
virtual ~cAudioDevice()
Destructor of cAudioDevice.
Definition: CAudioDevice.cpp:84
void * m_device
Audio device (of type ALCdevice*).
Definition: CAudioDevice.h:165
cAudioDevice()
Constructor of cAudioDevice.
Definition: CAudioDevice.cpp:62
std::vector< cAudioSource * > m_audioSources
List of allocated audio sources.
Definition: CAudioDevice.h:186
cVector3d getListenerVel()
This method sets the linear velocity of the listener in world coordinates.
Definition: CAudioDevice.h:121
cMatrix3d m_listenerRot
Orientation of listener in world coordinates.
Definition: CAudioDevice.h:174
This class implements an audio device context.
Definition: CAudioDevice.h:81
cAudioSource * newAudioSource()
This method creates a new audio source.
Definition: CAudioDevice.cpp:347
void * m_context
Audio context (of type ALCcontext*).
Definition: CAudioDevice.h:168
bool deleteAudioBuffer(cAudioBuffer *a_audioBuffer)
This method deletes an audio buffer passed as argument.
Definition: CAudioDevice.cpp:295
cVector3d m_listenerVel
Linear velocity of listener in world coordinates.
Definition: CAudioDevice.h:177
Definition: CAudioBuffer.cpp:56
cVector3d getListenerPos()
This method returns the position of the listener in world coordinates.
Definition: CAudioDevice.h:106
bool setListenerVel(const cVector3d &a_listenerVel)
This method sets the linear velocity of the listener in world coordinates.
Definition: CAudioDevice.cpp:246
bool m_active
Flag that indicates if the connection to audio device was opened successfully by calling method open(...
Definition: CAudioDevice.h:180
void deleteAllAudioSources()
This method deletes all audio buffers.
Definition: CAudioDevice.cpp:399
bool checkError()
This method checks for any OpenAL errors.
Definition: CAudioDevice.cpp:421