All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpenAL.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 
31 #ifdef HAVE_OPENAL
32 
33 struct ALCcontext_struct;
34 struct ALCdevice_struct;
35 
36 namespace gazebo
37 {
38  namespace util
39  {
40  class OpenALIface;
41  class OpenALSource;
42  class OpenALSink;
43 
46 
49  class OpenAL : public SingletonT<OpenAL>
50  {
52  private: OpenAL();
53 
55  private: virtual ~OpenAL();
56 
59  public: bool Load(sdf::ElementPtr _sdf = sdf::ElementPtr());
60 
62  public: void Fini();
63 
67  public: OpenALSourcePtr CreateSource(sdf::ElementPtr _sdf);
68 
73  public: OpenALSinkPtr CreateSink(sdf::ElementPtr _sdf);
74 
76  private: ALCcontext_struct *context;
77 
79  private: ALCdevice_struct *audioDevice;
80 
82  private: OpenALSinkPtr sink;
83 
85  private: friend class SingletonT<OpenAL>;
86  };
87 
90  class OpenALSink
91  {
93  public: OpenALSink();
94 
96  public: virtual ~OpenALSink();
97 
101  public: bool SetPose(const math::Pose &_pose);
102 
106  public: bool SetVelocity(const math::Vector3 &_vel);
107  };
108 
112  {
114  public: OpenALSource();
115 
117  public: virtual ~OpenALSource();
118 
122  public: bool Load(sdf::ElementPtr _sdf);
123 
127  public: bool SetPose(const math::Pose &_pose);
128 
132  public: bool SetVelocity(const math::Vector3 &_vel);
133 
137  public: bool SetPitch(float _p);
138 
142  public: bool SetGain(float _g);
143 
147  public: bool SetLoop(bool _state);
148 
154  public: bool GetOnContact() const;
155 
159  public: std::vector<std::string> GetCollisionNames() const;
160 
164  public: bool HasCollisionName(const std::string &_name) const;
165 
167  public: void Play();
168 
170  public: void Pause();
171 
173  public: void Stop();
174 
176  public: void Rewind();
177 
179  public: bool IsPlaying();
180 
186  public: bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount,
187  int _sampleRate);
188 
191  public: void FillBufferFromFile(const std::string &_audioFile);
192 
194  private: unsigned int alSource;
195 
197  private: unsigned int alBuffer;
198 
201  private: std::vector<std::string> collisionNames;
202  };
204  }
205 }
206 #endif
207 #endif