zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Sound_Source.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
54 #ifndef ZENI_SOUND_SOURCE_H
55 #define ZENI_SOUND_SOURCE_H
56 
57 #include <Zeni/Coordinate.h>
58 #include <Zeni/Error.h>
59 #include <Zeni/Sound.h>
60 #include <Zeni/Timer_HQ.h>
61 #include <Zeni/Vector3f.h>
62 
63 #include <Zeni/Define.h>
64 
65 namespace Zeni {
66 
67  class ZENI_AUDIO_DLL Sound_Source_Pool;
68 
69  class ZENI_AUDIO_DLL Sound_Source_HW {
70  friend class ZENI_AUDIO_DLL Sound_Source_Pool;
71 
72  Sound_Source_HW(const Sound_Source_HW &rhs);
73  Sound_Source_HW & operator=(const Sound_Source_HW &rhs);
74 
77  const float &pitch = ZENI_DEFAULT_PITCH,
78  const float &gain = ZENI_DEFAULT_GAIN,
79  const Point3f &position = Point3f(),
80  const Vector3f &velocity = Vector3f(),
81  const bool &looping = false);
82  ~Sound_Source_HW();
83 
84  static Sound_Source_HW * Try_Construct();
85 
86  public:
87  enum STATE {STOPPED, PAUSED, PLAYING};
88 
89  void set_buffer(const Sound_Buffer &buffer);
90  void set_pitch(const float &pitch = ZENI_DEFAULT_PITCH);
91  void set_gain(const float &gain = ZENI_DEFAULT_GAIN);
92  void set_position(const Point3f &position);
93  void set_velocity(const Vector3f &velocity);
94  void set_looping(const bool &looping);
95  void set_time(const float &time);
96  void set_reference_distance(const float &reference_distance = ZENI_DEFAULT_REFERENCE_DISTANCE); // Set the near clamping distance
97  void set_max_distance(const float &max_distance = ZENI_DEFAULT_MAX_SOUND_DISTANCE); // Set the far clamping distance
98  void set_rolloff(const float &rolloff = ZENI_DEFAULT_ROLLOFF); // Set the maximum reduction in volume due to distance
99 
100  const Sound_Buffer & get_buffer() const;
101  float get_duration() const;
102  float get_pitch() const;
103  float get_gain() const;
104  Point3f get_position() const;
105  Vector3f get_velocity() const;
106  bool is_looping() const;
107  float get_time() const;
108  float get_reference_distance() const; // Get the near clamping distance
109  float get_max_distance() const; // Get the far clamping distance
110  float get_rolloff() const; // Get the maximum reduction in volume due to distance
111 
112  void play();
113  void pause();
114  void stop();
115 
116  STATE get_state() const;
117  bool is_playing() const;
118  bool is_paused() const;
119  bool is_stopped() const;
120 
121  private:
122  void init(const Sound_Buffer &buffer,
123  const float &pitch = ZENI_DEFAULT_PITCH,
124  const float &gain = ZENI_DEFAULT_GAIN,
125  const Point3f &position = Point3f(),
126  const Vector3f &velocity = Vector3f(),
127  const bool &looping = false);
128  void uninit();
129 
130 #ifndef DISABLE_AL
131  mutable ALuint m_source;
132 #endif
133 #ifdef ENABLE_SLES
134  SLDataLocator_OutputMix loc_outmix;
135  SLDataSink audioSnk;
136 
137  SLObjectItf fdPlayerObject;
138  SLPlayItf fdPlayerPlay;
139  SLSeekItf fdPlayerSeek;
140  SLMuteSoloItf fdPlayerMuteSolo;
141  SLVolumeItf fdPlayerVolume;
142 #endif
143 
144  mutable const Sound_Buffer * m_buffer;
145  };
146 
147  class ZENI_AUDIO_DLL Sound_Source {
148  friend class ZENI_AUDIO_DLL Sound_Source_Pool;
149 
150  Sound_Source(const Sound_Source &rhs);
151  Sound_Source & operator=(const Sound_Source &rhs);
152 
153  public:
154  Sound_Source();
155  Sound_Source(const Sound_Buffer &buffer,
156  const float &pitch = ZENI_DEFAULT_PITCH,
157  const float &gain = ZENI_DEFAULT_GAIN,
158  const Point3f &position = Point3f(),
159  const Vector3f &velocity = Vector3f(),
160  const bool &looping = false);
161  ~Sound_Source();
162 
163  inline void set_priority(const int &priority = ZENI_DEFAULT_SOUND_PRIORITY);
164  inline void set_buffer(const Sound_Buffer &buffer);
165  inline void set_pitch(const float &pitch = ZENI_DEFAULT_PITCH);
166  inline void set_gain(const float &gain = ZENI_DEFAULT_GAIN);
167  inline void set_position(const Point3f &position);
168  inline void set_velocity(const Vector3f &velocity);
169  inline void set_looping(const bool &looping);
170  inline void set_time(const float &time);
171  inline void set_reference_distance(const float &reference_distance = ZENI_DEFAULT_REFERENCE_DISTANCE); // Set the near clamping distance
172  inline void set_max_distance(const float &max_distance = ZENI_DEFAULT_MAX_SOUND_DISTANCE); // Set the far clamping distance
173  inline void set_rolloff(const float &rolloff = ZENI_DEFAULT_ROLLOFF); // Set the maximum reduction in volume due to distance
174 
175  inline int get_priority() const;
176  inline Time_HQ get_unstop_time() const;
177  inline const Sound_Buffer & get_buffer() const;
178  inline float get_duration() const;
179  inline float get_pitch() const;
180  inline float get_gain() const;
181  inline Point3f get_position() const;
182  inline Vector3f get_velocity() const;
183  inline bool is_looping() const;
184  float get_time() const;
185  inline float get_reference_distance() const; // Get the near clamping distance
186  inline float get_max_distance() const; // Get the far clamping distance
187  inline float get_rolloff() const; // Get the maximum reduction in volume due to distance
188 
189  inline void play();
190  inline void pause();
191  inline void stop();
192 
193  inline bool is_playing() const;
194  inline bool is_paused() const;
195  inline bool is_stopped() const;
196 
197  float calculate_gain(const Point3f &listener_position) const;
198 
199  inline bool is_assigned() const;
200 
201  private:
202  void assign(Sound_Source_HW &hw);
203  Sound_Source_HW * unassign();
204 
205  void update_state() const;
206  void update_state(const Sound_Source_HW::STATE &state) const;
207 
208  Sound_Source_HW * m_hw;
209  int m_priority;
210  Time_HQ m_unstop_time;
211 
212  const Sound_Buffer * m_buffer;
213  mutable float m_duration;
214  float m_pitch;
215  float m_gain;
216  Point3f m_position;
217  Vector3f m_velocity;
218  bool m_looping;
219  float m_reference_distance;
220  float m_max_distance;
221  float m_rolloff;
222 
223  mutable Time_HQ m_play_time;
224  mutable float m_play_position;
225 
226  mutable bool m_playing;
227  mutable bool m_paused;
228  mutable bool m_stopped;
229 
230  bool m_remove_from_Pool_on_destruction;
231  };
232 
233  struct ZENI_AUDIO_DLL Sound_Source_HW_Init_Failure : public Error {
234  Sound_Source_HW_Init_Failure() : Error("Zeni Sound Source Hardware Failed to Initialize Correctly") {}
235  };
236 
237 }
238 
239 #include <Zeni/Undefine.h>
240 
241 #endif
#define AL_NONE
Definition: al.h:80
A Snapshot of the Timer_HQ.
Definition: Timer_HQ.h:79
#define ZENI_DEFAULT_PITCH
Definition: Define.h:54
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
#define ZENI_DEFAULT_GAIN
Definition: Define.h:55
A 3D Point represented with floats.
Definition: Coordinate.h:133
static long get_time(void)
Definition: test_bbox.c:16
#define ZENI_DEFAULT_MAX_SOUND_DISTANCE
Definition: Define.h:57
Plays Sound Data.
Definition: Sound_Source.h:69
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
Plays Sound Data.
Definition: Sound_Source.h:147
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
#define ZENI_DEFAULT_REFERENCE_DISTANCE
Definition: Define.h:56
unsigned int ALuint
Definition: al.h:59
Stores Sound Data.
Definition: Sound_Buffer.h:83
#define ZENI_DEFAULT_ROLLOFF
Definition: Define.h:58
This class manages Sound_Sources.
#define ZENI_DEFAULT_SOUND_PRIORITY
Definition: Define.h:59
The Error Class.
Definition: Error.h:52
GLsizei GLsizei GLchar * source
Definition: gl2ext.h:994