zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Sound_Source.hxx
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 
18 #ifndef ZENI_SOUND_SOURCE_HXX
19 #define ZENI_SOUND_SOURCE_HXX
20 
21 // HXXed below
22 #include <Zeni/Timer_HQ.h>
23 
24 #include <Zeni/Sound_Source.h>
25 
26 #include <cassert>
27 #include <cmath>
28 
29 #ifndef DISABLE_AL
30 #ifndef AL_SEC_OFFSET
31 #define AL_SEC_OFFSET 0x1024
32 #endif
33 #endif
34 
35 #include <Zeni/Define.h>
36 
37 namespace Zeni {
38 
39  void Sound_Source::set_priority(const int &priority) {m_priority = priority;}
40  void Sound_Source::set_buffer(const Sound_Buffer &buffer) {m_buffer = &buffer; if(m_hw) m_hw->set_buffer(buffer);}
41  void Sound_Source::set_pitch(const float &pitch) {m_pitch = pitch; if(m_hw) m_hw->set_pitch(pitch);}
42  void Sound_Source::set_gain(const float &gain) {m_gain = gain; if(m_hw) m_hw->set_gain(gain);}
43  void Sound_Source::set_position(const Point3f &position) {m_position = position; if(m_hw) m_hw->set_position(position);}
44  void Sound_Source::set_velocity(const Vector3f &velocity) {m_velocity = velocity; if(m_hw) m_hw->set_velocity(velocity);}
45  void Sound_Source::set_looping(const bool &looping) {m_looping = looping; if(m_hw) m_hw->set_looping(looping);}
46 
47  void Sound_Source::set_time(const float &time) {
48  m_play_position = time;
49  if(m_playing)
50  m_play_time.update();
51 
52  if(m_hw)
53  m_hw->set_time(time);
54  }
55 
56  void Sound_Source::set_reference_distance(const float &reference_distance) {m_reference_distance = reference_distance; if(m_hw) m_hw->set_reference_distance(reference_distance);}
57  void Sound_Source::set_max_distance(const float &max_distance) {m_max_distance = max_distance; if(m_hw) m_hw->set_max_distance(max_distance);}
58  void Sound_Source::set_rolloff(const float &rolloff) {m_rolloff = rolloff; if(m_hw) m_hw->set_rolloff(rolloff);}
59 
60  int Sound_Source::get_priority() const {return m_priority;}
61  Time_HQ Sound_Source::get_unstop_time() const {return m_unstop_time;}
62  const Sound_Buffer & Sound_Source::get_buffer() const {assert(m_buffer); return *m_buffer;}
63  float Sound_Source::get_duration() const {if(m_hw) m_duration = m_hw->get_duration(); return m_duration;}
64  float Sound_Source::get_pitch() const {return m_pitch;}
65  float Sound_Source::get_gain() const {return m_gain;}
66  Point3f Sound_Source::get_position() const {return m_position;}
67  Vector3f Sound_Source::get_velocity() const {return m_velocity;}
68  bool Sound_Source::is_looping() const {return m_looping;}
69  float Sound_Source::get_reference_distance() const {return m_reference_distance;}
70  float Sound_Source::get_max_distance() const {return m_max_distance;}
71  float Sound_Source::get_rolloff() const {return m_rolloff;}
72 
73  void Sound_Source::play() {update_state(Sound_Source_HW::PLAYING); if(m_hw) m_hw->play(); m_unstop_time.update();}
74  void Sound_Source::pause() {update_state(Sound_Source_HW::PAUSED); if(m_hw) m_hw->pause(); m_unstop_time.update();}
75  void Sound_Source::stop() {update_state(Sound_Source_HW::STOPPED); if(m_hw) m_hw->stop();}
76 
77  bool Sound_Source::is_playing() const {update_state(); return m_playing;}
78  bool Sound_Source::is_paused() const {update_state(); return m_paused;}
79  bool Sound_Source::is_stopped() const {update_state(); return m_stopped;}
80 
81  bool Sound_Source::is_assigned() const {return m_hw != 0;}
82 
83 }
84 
85 #include <Zeni/Undefine.h>
86 
87 #include <Zeni/Timer_HQ.hxx>
88 
89 #endif
float get_duration() const
Get the duration of the Sound_Buffer in seconds.
void set_buffer(const Sound_Buffer &buffer)
Set the Sound_Buffer to be played.
float get_rolloff() const
void stop()
Stop the Sound_Source. (Essentially the same as pause but resets the current time.)
Vector3f get_velocity() const
Get the velocity of the Sound_Buffer.
float get_pitch() const
Get the pitch.
float get_reference_distance() const
void set_buffer(const Sound_Buffer &buffer)
Set the Sound_Buffer to be played.
A Snapshot of the Timer_HQ.
Definition: Timer_HQ.h:79
float get_gain() const
Get the gain.
bool is_paused() const
Check to see if the Sound_Source is paused.
void set_time(const float &time)
Set the current position in the Sound_Buffer, offset in seconds.
void pause()
Pause the Sound_Source.
void update()
Update to current Time.
Definition: Timer_HQ.hxx:47
int get_priority() const
Get the Sound_Source&#39;s priority.
void stop()
Stop the Sound_Source_HW. (Essentially the same as pause but resets the current time.)
void set_rolloff(const float &rolloff=ZENI_DEFAULT_ROLLOFF)
Time_HQ get_unstop_time() const
Get the Time_HQ at which the Sound_Source was most recently played or unpaused.
void play()
Begin playing or unpause the Sound_Source_HW.
float get_max_distance() const
#define assert(x)
Definition: SDL_malloc.c:1234
void set_gain(const float &gain=ZENI_DEFAULT_GAIN)
Set the gain.
void set_reference_distance(const float &reference_distance=ZENI_DEFAULT_REFERENCE_DISTANCE)
void play()
Begin playing or unpause the Sound_Source.
void set_looping(const bool &looping)
Set whether the Sound_Buffer should loop back to the start once it is done playing.
void set_velocity(const Vector3f &velocity)
Set the velocity of the Sound_Source_HW for the doppler effect.
A 3D Point represented with floats.
Definition: Coordinate.h:133
Point3f get_position() const
Get the position of the Sound_Buffer.
void set_max_distance(const float &max_distance=ZENI_DEFAULT_MAX_SOUND_DISTANCE)
const Sound_Buffer & get_buffer() const
Get the Sound_Buffer&#39;s OpenAL id.
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
void set_rolloff(const float &rolloff=ZENI_DEFAULT_ROLLOFF)
void set_time(const float &time)
Set the current position in the Sound_Buffer, offset in seconds.
void set_max_distance(const float &max_distance=ZENI_DEFAULT_MAX_SOUND_DISTANCE)
void set_priority(const int &priority=ZENI_DEFAULT_SOUND_PRIORITY)
Set the priority that this Sound_Source should have. Higher numbers are more likely to be selected fo...
Stores Sound Data.
Definition: Sound_Buffer.h:83
void set_reference_distance(const float &reference_distance=ZENI_DEFAULT_REFERENCE_DISTANCE)
float get_duration() const
Get the duration of the Sound_Buffer in seconds.
void set_looping(const bool &looping)
Set whether the Sound_Buffer should loop back to the start once it is done playing.
void set_gain(const float &gain=ZENI_DEFAULT_GAIN)
Set the gain.
bool is_stopped() const
Check to see if the Sound_Source is stopped.
bool is_playing() const
Check to see if the Sound_Source is playing.
void set_position(const Point3f &position)
Set the position of the Sound_Source_HW.
void set_pitch(const float &pitch=ZENI_DEFAULT_PITCH)
Set the pitch.
void set_velocity(const Vector3f &velocity)
Set the velocity of the Sound_Source for the doppler effect.
void set_position(const Point3f &position)
Set the position of the Sound_Source.
void pause()
Pause the Sound_Source_HW.
bool is_assigned() const
Check to see if the Sound_Source is assigned to actual hardware.
bool is_looping() const
Check to see if the Sound_Buffer is set to loop back to the start once it is done playing...
void set_pitch(const float &pitch=ZENI_DEFAULT_PITCH)
Set the pitch.