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
30
31#include "gazebo/gazebo_config.h"
32#include "gazebo/util/system.hh"
33
34#ifdef HAVE_OPENAL
35
37GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, OpenAL)
38
39namespace 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
util
Definition Diagnostics.hh:33
gazebo
Definition OpenAL.hh:37
util
Definition OpenAL.hh:37
Singleton template class.
Definition SingletonT.hh:34
OpenAL Listener.
Definition OpenAL.hh:95
OpenALSink()
Constructor.
virtual ~OpenALSink()
Destructor.
bool SetVelocity(const ignition::math::Vector3d &_vel)
Set the velocity of the sink.
bool SetPose(const ignition::math::Pose3d &_pose)
Set the position of the sink.
OpenAL Source.
Definition OpenAL.hh:116
std::vector< std::string > CollisionNames() const
Get a vector of all the collision names.
void Play()
Play a sound.
void Stop()
Stop a sound.
void Rewind()
Rewind the sound to the beginning.
void FillBufferFromFile(const std::string &_audioFile)
Fill the OpenAL audio buffer with data from a sound file.
void Pause()
Pause a sound.
bool IsPlaying()
Is the audio playing.
bool OnContact() const
Return true if the audio source is played on contact with another object.
bool SetVelocity(const ignition::math::Vector3d &_vel)
Set the velocity of the source.
bool FillBufferFromPCM(uint8_t *_pcmData, unsigned int _dataCount, int _sampleRate)
Fill the OpenAL audio buffer from PCM data.
bool SetGain(float _g)
Set the pitch of the source.
bool SetLoop(bool _state)
Set whether the source loops the audio.
bool Load(sdf::ElementPtr _sdf)
Load the source from sdf.
bool SetPitch(float _p)
Set the pitch of the source.
virtual ~OpenALSource()
Destructor.
bool HasCollisionName(const std::string &_name) const
Get whether the source has a collision name set.
bool SetPose(const ignition::math::Pose3d &_pose)
Set the position of the source.
3D audio setup and playback.
Definition OpenAL.hh:55
void Fini()
Finalize.
OpenALSourcePtr CreateSource(sdf::ElementPtr _sdf)
Create an OpenALSource object.
OpenALSinkPtr CreateSink(sdf::ElementPtr _sdf)
Create an audio listener.
std::set< std::string > DeviceList() const
Get a list of available audio devices.
bool Load(sdf::ElementPtr _sdf=sdf::ElementPtr())
Load the OpenAL server.
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition SingletonT.hh:58
std::shared_ptr< OpenALSource > OpenALSourcePtr
Definition UtilTypes.hh:48
std::shared_ptr< OpenALSink > OpenALSinkPtr
Definition UtilTypes.hh:44
Forward declarations for the common classes.
Definition Animation.hh:27