OpenAL.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 
29 #include "gazebo/util/UtilTypes.hh"
30 
31 #include "gazebo/gazebo_config.h"
32 #include "gazebo/util/system.hh"
33 
34 #ifdef HAVE_OPENAL
35 
36 namespace gazebo
37 {
38  namespace util
39  {
40  // Forward declare private openal data class
41  class OpenALPrivate;
42 
43  // Forward declare private openal sourcedata class
44  class OpenALSourcePrivate;
45 
48 
51  class GZ_UTIL_VISIBLE OpenAL : public SingletonT<OpenAL>
52  {
54  private: OpenAL();
55 
57  private: virtual ~OpenAL();
58 
61  public: bool Load(sdf::ElementPtr _sdf = sdf::ElementPtr());
62 
64  public: void Fini();
65 
69  public: OpenALSourcePtr CreateSource(sdf::ElementPtr _sdf);
70 
75  public: OpenALSinkPtr CreateSink(sdf::ElementPtr _sdf);
76 
79  public: std::set<std::string> DeviceList() const;
80 
83  private: std::unique_ptr<OpenALPrivate> dataPtr;
84 
86  private: friend class SingletonT<OpenAL>;
87  };
88 
91  class GZ_UTIL_VISIBLE OpenALSink
92  {
94  public: OpenALSink();
95 
97  public: virtual ~OpenALSink();
98 
102  public: bool SetPose(const ignition::math::Pose3d &_pose);
103 
107  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
108  };
109 
112  class GZ_UTIL_VISIBLE OpenALSource
113  {
115  public: OpenALSource();
116 
118  public: virtual ~OpenALSource();
119 
123  public: bool Load(sdf::ElementPtr _sdf);
124 
128  public: bool SetPose(const ignition::math::Pose3d &_pose);
129 
133  public: bool SetVelocity(const ignition::math::Vector3d &_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 OnContact() const;
156 
160  public: std::vector<std::string> CollisionNames() 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 
196  private: std::unique_ptr<OpenALSourcePrivate> dataPtr;
197  };
199  }
200 }
201 #endif
202 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
Singleton template class.
Definition: SingletonT.hh:33
std::shared_ptr< OpenALSource > OpenALSourcePtr
Definition: UtilTypes.hh:48
OpenAL Source.
Definition: OpenAL.hh:112
3D audio setup and playback.
Definition: OpenAL.hh:51
std::shared_ptr< OpenALSink > OpenALSinkPtr
Definition: UtilTypes.hh:44
OpenAL Listener.
Definition: OpenAL.hh:91