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 
37 GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, OpenAL)
38 
39 namespace gazebo
40 {
41  namespace util
42  {
43  // Forward declare private openal data class
44  class OpenALPrivate;
45 
46  // Forward declare private openal sourcedata class
47  class OpenALSourcePrivate;
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 
82  public: std::set<std::string> DeviceList() const;
83 
86  private: std::unique_ptr<OpenALPrivate> dataPtr;
87 
89  private: friend class SingletonT<OpenAL>;
90  };
91 
94  class GZ_UTIL_VISIBLE OpenALSink
95  {
97  public: OpenALSink();
98 
100  public: virtual ~OpenALSink();
101 
105  public: bool SetPose(const ignition::math::Pose3d &_pose);
106 
110  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
111  };
112 
115  class GZ_UTIL_VISIBLE OpenALSource
116  {
118  public: OpenALSource();
119 
121  public: virtual ~OpenALSource();
122 
126  public: bool Load(sdf::ElementPtr _sdf);
127 
131  public: bool SetPose(const ignition::math::Pose3d &_pose);
132 
136  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
137 
141  public: bool SetPitch(float _p);
142 
146  public: bool SetGain(float _g);
147 
151  public: bool SetLoop(bool _state);
152 
158  public: bool OnContact() const;
159 
163  public: std::vector<std::string> CollisionNames() const;
164 
168  public: bool HasCollisionName(const std::string &_name) const;
169 
171  public: void Play();
172 
174  public: void Pause();
175 
177  public: void Stop();
178 
180  public: void Rewind();
181 
183  public: bool IsPlaying();
184 
190  public: bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount,
191  int _sampleRate);
192 
195  public: void FillBufferFromFile(const std::string &_audioFile);
196 
199  private: std::unique_ptr<OpenALSourcePrivate> dataPtr;
200  };
202  }
203 }
204 #endif
205 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33
util
Definition: OpenAL.hh:37
std::shared_ptr< OpenALSource > OpenALSourcePtr
Definition: UtilTypes.hh:48
OpenAL Source.
Definition: OpenAL.hh:115
3D audio setup and playback.
Definition: OpenAL.hh:54
std::shared_ptr< OpenALSink > OpenALSinkPtr
Definition: UtilTypes.hh:44
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
OpenAL Listener.
Definition: OpenAL.hh:94