RigsofRods
Soft-body Physics Simulation
Sound.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifdef USE_OPENAL
22 
23 #pragma once
24 
25 #include "Application.h"
26 #include "RefCountingObject.h"
27 
28 #ifdef __APPLE__
29 # include <OpenAL/al.h>
30 #else
31 # include <AL/al.h>
32 #endif // __APPLE__
33 
34 namespace RoR {
35 
38 
39 class Sound : public RefCountingObject<Sound>
40 {
41  friend class SoundManager;
42 
43 public:
44  Sound(ALuint buffer, SoundManager* soundManager, int sourceIndex);
45  virtual ~Sound() override {};
46 
47  void setPitch(float pitch);
48  void setGain(float gain);
49  void setPosition(Ogre::Vector3 pos);
50  void setVelocity(Ogre::Vector3 vel);
51  void setLoop(bool loop);
52  void setEnabled(bool e);
53  void play();
54  void stop();
55 
56  bool getEnabled();
57  bool isPlaying();
58  float getAudibility() { return audibility; }
59  float getGain() { return gain; }
60  float getPitch() { return pitch; }
61  bool getLoop() { return loop; }
63  ALuint getBuffer() { return buffer; }
64  Ogre::Vector3 getPosition() { return position; }
65  Ogre::Vector3 getVelocity() { return velocity; }
66  int getSourceIndex() { return source_index; }
67 
69  {
77  };
78 
79 private:
80  void computeAudibility(Ogre::Vector3 pos);
81 
82  float audibility;
83  float gain;
84  float pitch;
85  bool loop;
86  bool enabled;
88 
89  // this value is changed dynamically, depending on whether the input is played or not.
91  ALuint buffer;
92 
93  Ogre::Vector3 position;
94  Ogre::Vector3 velocity;
95 
97  // must not be changed during the lifetime of this object
99 };
100 
102 
103 } // namespace RoR
104 
105 #endif // USE_OPENAL
RoR::Sound::~Sound
virtual ~Sound() override
Definition: Sound.h:45
RoR::Sound::REASON_PTCH
@ REASON_PTCH
Definition: Sound.h:74
RoR::Sound::RecomputeSource
RecomputeSource
Definition: Sound.h:68
RoR::SoundManager
Definition: SoundManager.h:44
RoR::Sound::getEnabled
bool getEnabled()
Definition: Sound.cpp:108
RoR::Sound::setEnabled
void setEnabled(bool e)
Definition: Sound.cpp:99
RoR::Sound::enabled
bool enabled
Definition: Sound.h:86
RoR::Sound::getPitch
float getPitch()
Definition: Sound.h:60
RoR::Sound::pitch
float pitch
Definition: Sound.h:84
RoR::Sound::loop
bool loop
Definition: Sound.h:85
RoR::Sound
Definition: Sound.h:39
RoR::Sound::position
Ogre::Vector3 position
Definition: Sound.h:93
RoR::Sound::audibility
float audibility
Definition: Sound.h:82
RoR::Sound::setPosition
void setPosition(Ogre::Vector3 pos)
Definition: Sound.cpp:152
RoR::Sound::getBuffer
ALuint getBuffer()
Definition: Sound.h:63
RoR::Sound::setLoop
void setLoop(bool loop)
Definition: Sound.cpp:134
RoR::Sound::source_index
int source_index
Definition: Sound.h:98
RoR::Sound::should_play
bool should_play
Definition: Sound.h:87
RoR::Sound::isPlaying
bool isPlaying()
Definition: Sound.cpp:88
RoR::Sound::getLoop
bool getLoop()
Definition: Sound.h:61
RoR::Sound::setPitch
void setPitch(float pitch)
Definition: Sound.cpp:143
RoR::Sound::getGain
float getGain()
Definition: Sound.h:59
RoR::Sound::REASON_LOOP
@ REASON_LOOP
Definition: Sound.h:73
RoR::Sound::REASON_PLAY
@ REASON_PLAY
Definition: Sound.h:70
RoR::Sound::getCurrentHardwareIndex
int getCurrentHardwareIndex()
Definition: Sound.h:62
RefCountingObject.h
Application.h
Central state/object manager and communications hub.
RoR::Sound::REASON_STOP
@ REASON_STOP
Definition: Sound.h:71
RoR::Sound::setGain
void setGain(float gain)
Definition: Sound.cpp:125
RoR::Sound::stop
void stop()
Definition: Sound.cpp:119
RoR::Sound::setVelocity
void setVelocity(Ogre::Vector3 vel)
Definition: Sound.cpp:161
RoR::Sound::computeAudibility
void computeAudibility(Ogre::Vector3 pos)
Definition: Sound.cpp:45
RoR::Sound::play
void play()
Definition: Sound.cpp:113
RoR::Sound::buffer
ALuint buffer
Definition: Sound.h:91
RoR::Sound::hardware_index
int hardware_index
Definition: Sound.h:90
RoR::Sound::getPosition
Ogre::Vector3 getPosition()
Definition: Sound.h:64
RoR::Sound::getVelocity
Ogre::Vector3 getVelocity()
Definition: Sound.h:65
RefCountingObject
Self reference-counting objects, as requred by AngelScript garbage collector.
Definition: RefCountingObject.h:26
RoR::Sound::REASON_POSN
@ REASON_POSN
Definition: Sound.h:75
RoR::Sound::REASON_GAIN
@ REASON_GAIN
Definition: Sound.h:72
RoR::Sound::Sound
Sound(ALuint buffer, SoundManager *soundManager, int sourceIndex)
Definition: Sound.cpp:29
RoR::Sound::getAudibility
float getAudibility()
Definition: Sound.h:58
RoR::Sound::REASON_VLCT
@ REASON_VLCT
Definition: Sound.h:76
RoR
Definition: AppContext.h:36
RoR::Sound::sound_manager
SoundManager * sound_manager
Definition: Sound.h:96
RoR::Sound::velocity
Ogre::Vector3 velocity
Definition: Sound.h:94
RoR::Sound::gain
float gain
Definition: Sound.h:83
RoR::Sound::getSourceIndex
int getSourceIndex()
Definition: Sound.h:66