OpenAL.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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_UTIL_OPENAL_HH_
18 #define _GAZEBO_UTIL_OPENAL_HH_
19 
20 #include <set>
21 #include <string>
22 #include <vector>
23 #include <sdf/sdf.hh>
24 
25 #include <ignition/math/Vector3.hh>
26 #include <ignition/math/Pose3.hh>
27 
30 #include "gazebo/util/UtilTypes.hh"
31 
32 #include "gazebo/gazebo_config.h"
33 #include "gazebo/util/system.hh"
34 
35 #ifdef HAVE_OPENAL
36 
37 namespace gazebo
38 {
39  namespace util
40  {
41  // Forward declare private openal data class
42  class OpenALPrivate;
43 
44  // Forward declare private openal sourcedata class
45  class OpenALSourcePrivate;
46 
49 
52  class GZ_UTIL_VISIBLE OpenAL : public SingletonT<OpenAL>
53  {
55  private: OpenAL();
56 
58  private: virtual ~OpenAL();
59 
62  public: bool Load(sdf::ElementPtr _sdf = sdf::ElementPtr());
63 
65  public: void Fini();
66 
70  public: OpenALSourcePtr CreateSource(sdf::ElementPtr _sdf);
71 
76  public: OpenALSinkPtr CreateSink(sdf::ElementPtr _sdf);
77 
80  public: std::set<std::string> DeviceList() const;
81 
84  private: std::unique_ptr<OpenALPrivate> dataPtr;
85 
87  private: friend class SingletonT<OpenAL>;
88  };
89 
92  class GZ_UTIL_VISIBLE OpenALSink
93  {
95  public: OpenALSink();
96 
98  public: virtual ~OpenALSink();
99 
103  public: bool SetPose(const ignition::math::Pose3d &_pose);
104 
108  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
109  };
110 
113  class GZ_UTIL_VISIBLE OpenALSource
114  {
116  public: OpenALSource();
117 
119  public: virtual ~OpenALSource();
120 
124  public: bool Load(sdf::ElementPtr _sdf);
125 
129  public: bool SetPose(const ignition::math::Pose3d &_pose);
130 
134  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
135 
139  public: bool SetPitch(float _p);
140 
144  public: bool SetGain(float _g);
145 
149  public: bool SetLoop(bool _state);
150 
157  public: bool GetOnContact() const GAZEBO_DEPRECATED(7.0);
158 
164  public: bool OnContact() const;
165 
170  public: std::vector<std::string> GetCollisionNames() const
171  GAZEBO_DEPRECATED(7.0);
172 
176  public: std::vector<std::string> CollisionNames() const;
177 
181  public: bool HasCollisionName(const std::string &_name) const;
182 
184  public: void Play();
185 
187  public: void Pause();
188 
190  public: void Stop();
191 
193  public: void Rewind();
194 
196  public: bool IsPlaying();
197 
203  public: bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount,
204  int _sampleRate);
205 
208  public: void FillBufferFromFile(const std::string &_audioFile);
209 
212  private: std::unique_ptr<OpenALSourcePrivate> dataPtr;
213  };
215  }
216 }
217 #endif
218 #endif
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
Singleton template class.
Definition: SingletonT.hh:33
std::shared_ptr< OpenALSource > OpenALSourcePtr
Definition: UtilTypes.hh:48
OpenAL Source.
Definition: OpenAL.hh:113
3D audio setup and playback.
Definition: OpenAL.hh:52
std::shared_ptr< OpenALSink > OpenALSinkPtr
Definition: UtilTypes.hh:44
OpenAL Listener.
Definition: OpenAL.hh:92