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 <string>
21 #include <vector>
22 #include <sdf/sdf.hh>
23 
24 #include <ignition/math/Vector3.hh>
25 #include <ignition/math/Pose3.hh>
26 
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  private: std::unique_ptr<OpenALPrivate> dataPtr;
80 
82  private: friend class SingletonT<OpenAL>;
83  };
84 
88  {
90  public: OpenALSink();
91 
93  public: virtual ~OpenALSink();
94 
98  public: bool SetPose(const ignition::math::Pose3d &_pose);
99 
103  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
104  };
105 
109  {
111  public: OpenALSource();
112 
114  public: virtual ~OpenALSource();
115 
119  public: bool Load(sdf::ElementPtr _sdf);
120 
124  public: bool SetPose(const ignition::math::Pose3d &_pose);
125 
129  public: bool SetVelocity(const ignition::math::Vector3d &_vel);
130 
134  public: bool SetPitch(float _p);
135 
139  public: bool SetGain(float _g);
140 
144  public: bool SetLoop(bool _state);
145 
152  public: bool GetOnContact() const GAZEBO_DEPRECATED(7.0);
153 
159  public: bool OnContact() const;
160 
165  public: std::vector<std::string> GetCollisionNames() const
166  GAZEBO_DEPRECATED(7.0);
167 
171  public: std::vector<std::string> CollisionNames() const;
172 
176  public: bool HasCollisionName(const std::string &_name) const;
177 
179  public: void Play();
180 
182  public: void Pause();
183 
185  public: void Stop();
186 
188  public: void Rewind();
189 
191  public: bool IsPlaying();
192 
198  public: bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount,
199  int _sampleRate);
200 
203  public: void FillBufferFromFile(const std::string &_audioFile);
204 
207  private: std::unique_ptr<OpenALSourcePrivate> dataPtr;
208  };
210  }
211 }
212 #endif
213 #endif
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
std::shared_ptr< OpenALSink > OpenALSinkPtr
Definition: UtilTypes.hh:44
Singleton template class.
Definition: SingletonT.hh:33
#define GZ_UTIL_VISIBLE
Definition: system.hh:234
OpenAL Source.
Definition: OpenAL.hh:108
std::shared_ptr< OpenALSource > OpenALSourcePtr
Definition: UtilTypes.hh:48
3D audio setup and playback.
Definition: OpenAL.hh:51
OpenAL Listener.
Definition: OpenAL.hh:87