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 "gazebo/math/Vector3.hh"
25 #include "gazebo/math/Pose.hh"
27 #include "gazebo/util/UtilTypes.hh"
28 
29 #include "gazebo/gazebo_config.h"
30 #include "gazebo/util/system.hh"
31 
32 #ifdef HAVE_OPENAL
33 
34 struct ALCcontext_struct;
35 struct ALCdevice_struct;
36 
37 namespace gazebo
38 {
39  namespace util
40  {
41  class OpenALIface;
42  class OpenALSource;
43  class OpenALSink;
44 
47 
50  class GAZEBO_VISIBLE OpenAL : public SingletonT<OpenAL>
51  {
53  private: OpenAL();
54 
56  private: virtual ~OpenAL();
57 
60  public: bool Load(sdf::ElementPtr _sdf = sdf::ElementPtr());
61 
63  public: void Fini();
64 
68  public: OpenALSourcePtr CreateSource(sdf::ElementPtr _sdf);
69 
74  public: OpenALSinkPtr CreateSink(sdf::ElementPtr _sdf);
75 
77  private: ALCcontext_struct *context;
78 
80  private: ALCdevice_struct *audioDevice;
81 
83  private: OpenALSinkPtr sink;
84 
86  private: friend class SingletonT<OpenAL>;
87  };
88 
92  {
94  public: OpenALSink();
95 
97  public: virtual ~OpenALSink();
98 
102  public: bool SetPose(const math::Pose &_pose);
103 
107  public: bool SetVelocity(const math::Vector3 &_vel);
108  };
109 
113  {
115  public: OpenALSource();
116 
118  public: virtual ~OpenALSource();
119 
123  public: bool Load(sdf::ElementPtr _sdf);
124 
128  public: bool SetPose(const math::Pose &_pose);
129 
133  public: bool SetVelocity(const math::Vector3 &_vel);
134 
138  public: bool SetPitch(float _p);
139 
143  public: bool SetGain(float _g);
144 
148  public: bool SetLoop(bool _state);
149 
155  public: bool GetOnContact() const;
156 
160  public: std::vector<std::string> GetCollisionNames() const;
161 
165  public: bool HasCollisionName(const std::string &_name) const;
166 
168  public: void Play();
169 
171  public: void Pause();
172 
174  public: void Stop();
175 
177  public: void Rewind();
178 
180  public: bool IsPlaying();
181 
187  public: bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount,
188  int _sampleRate);
189 
192  public: void FillBufferFromFile(const std::string &_audioFile);
193 
195  private: unsigned int alSource;
196 
198  private: unsigned int alBuffer;
199 
202  private: std::vector<std::string> collisionNames;
203  };
205  }
206 }
207 #endif
208 #endif
boost::shared_ptr< OpenALSource > OpenALSourcePtr
Definition: UtilTypes.hh:46
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
Singleton template class.
Definition: SingletonT.hh:33
boost::shared_ptr< OpenALSink > OpenALSinkPtr
Definition: UtilTypes.hh:42
OpenAL Source.
Definition: OpenAL.hh:112
3D audio setup and playback.
Definition: OpenAL.hh:50
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
OpenAL Listener.
Definition: OpenAL.hh:91