OpenAL.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_OPENAL_HH_
18 #define _GAZEBO_OPENAL_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <sdf/sdf.hh>
23 
24 #include <ignition/math/Vector3.hh>
25 #include <ignition/math/Pose3.hh>
26 
27 #include "gazebo/math/Vector3.hh"
28 #include "gazebo/math/Pose.hh"
31 #include "gazebo/util/UtilTypes.hh"
32 
33 #include "gazebo/gazebo_config.h"
34 #include "gazebo/util/system.hh"
35 
36 #ifdef HAVE_OPENAL
37 
38 struct ALCcontext_struct;
39 struct ALCdevice_struct;
40 
41 namespace gazebo
42 {
43  namespace util
44  {
45  class OpenALIface;
46  class OpenALSource;
47  class OpenALSink;
48 
51 
54  class GZ_UTIL_VISIBLE OpenAL : public SingletonT<OpenAL>
55  {
57  private: OpenAL();
58 
60  private: virtual ~OpenAL();
61 
64  public: bool Load(sdf::ElementPtr _sdf = sdf::ElementPtr());
65 
67  public: void Fini();
68 
72  public: OpenALSourcePtr CreateSource(sdf::ElementPtr _sdf);
73 
78  public: OpenALSinkPtr CreateSink(sdf::ElementPtr _sdf);
79 
81  private: ALCcontext_struct *context;
82 
84  private: ALCdevice_struct *audioDevice;
85 
87  private: OpenALSinkPtr sink;
88 
90  private: friend class SingletonT<OpenAL>;
91  };
92 
96  {
98  public: OpenALSink();
99 
101  public: virtual ~OpenALSink();
102 
108  public: bool SetPose(const math::Pose &_pose) GAZEBO_DEPRECATED(6.0);
109 
113  public: bool SetPose(const ignition::math::Pose3d &_pose);
114 
120  public: bool SetVelocity(const math::Vector3 &_vel)
121  GAZEBO_DEPRECATED(6.0);
122 
126  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
127  };
128 
132  {
134  public: OpenALSource();
135 
137  public: virtual ~OpenALSource();
138 
142  public: bool Load(sdf::ElementPtr _sdf);
143 
149  public: bool SetPose(const math::Pose &_pose) GAZEBO_DEPRECATED(6.0);
150 
154  public: bool SetPose(const ignition::math::Pose3d &_pose);
155 
161  public: bool SetVelocity(const math::Vector3 &_vel)
162  GAZEBO_DEPRECATED(6.0);
163 
167  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
168 
172  public: bool SetPitch(float _p);
173 
177  public: bool SetGain(float _g);
178 
182  public: bool SetLoop(bool _state);
183 
189  public: bool GetOnContact() const;
190 
194  public: std::vector<std::string> GetCollisionNames() const;
195 
199  public: bool HasCollisionName(const std::string &_name) const;
200 
202  public: void Play();
203 
205  public: void Pause();
206 
208  public: void Stop();
209 
211  public: void Rewind();
212 
214  public: bool IsPlaying();
215 
221  public: bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount,
222  int _sampleRate);
223 
226  public: void FillBufferFromFile(const std::string &_audioFile);
227 
229  private: unsigned int alSource;
230 
232  private: unsigned int alBuffer;
233 
236  private: std::vector<std::string> collisionNames;
237  };
239  }
240 }
241 #endif
242 #endif
boost::shared_ptr< OpenALSource > OpenALSourcePtr
Definition: UtilTypes.hh:46
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:47
Singleton template class.
Definition: SingletonT.hh:33
#define GZ_UTIL_VISIBLE
Definition: system.hh:266
boost::shared_ptr< OpenALSink > OpenALSinkPtr
Definition: UtilTypes.hh:42
OpenAL Source.
Definition: OpenAL.hh:131
3D audio setup and playback.
Definition: OpenAL.hh:54
OpenAL Listener.
Definition: OpenAL.hh:95