RigsofRods
Soft-body Physics Simulation
SoundManager.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  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifdef USE_OPENAL
23 
24 #pragma once
25 
26 #include "Application.h"
27 
28 #include <OgreVector3.h>
29 #include <OgreString.h>
30 
31 #ifdef __APPLE__
32  #include <OpenAL/al.h>
33  #include <OpenAL/alc.h>
34 #else
35  #include <AL/al.h>
36  #include <AL/alc.h>
37 #endif // __APPLE__
38 
39 namespace RoR {
40 
43 
45 {
46  friend class Sound;
47 
48 public:
49  SoundManager();
50  ~SoundManager();
51 
56  SoundPtr createSound(Ogre::String filename, Ogre::String resource_group_name = "");
57 
58  void setCamera(Ogre::Vector3 position, Ogre::Vector3 direction, Ogre::Vector3 up, Ogre::Vector3 velocity);
59  void pauseAllSounds();
60  void resumeAllSounds();
61  void setMasterVolume(float v);
62 
63  bool isDisabled() { return audio_device == 0; }
64 
66 
67  static const float MAX_DISTANCE;
68  static const float ROLLOFF_FACTOR;
69  static const float REFERENCE_DISTANCE;
70  static const unsigned int MAX_HARDWARE_SOURCES = 32;
71  static const unsigned int MAX_AUDIO_BUFFERS = 8192;
72 
73 private:
74  void recomputeAllSources();
75  void recomputeSource(int source_index, int reason, float vfl, Ogre::Vector3 *vvec);
76  ALuint getHardwareSource(int hardware_index) { return hardware_sources[hardware_index]; };
77 
78  void assign(int source_index, int hardware_index);
79  void retire(int source_index);
80 
81  bool loadWAVFile(Ogre::String filename, ALuint buffer, Ogre::String resource_group_name = "");
82 
83  // active audio sources (hardware sources)
84  int hardware_sources_num = 0; // total number of available hardware sources < MAX_HARDWARE_SOURCES
86  int hardware_sources_map[MAX_HARDWARE_SOURCES]; // stores the hardware index for each source. -1 = unmapped
87  ALuint hardware_sources[MAX_HARDWARE_SOURCES]; // this buffer contains valid AL handles up to m_hardware_sources_num
88 
89  // audio sources
91  // helper for calculating the most audible sources
93 
94  // audio buffers: Array of AL buffers and filenames
98 
99  Ogre::Vector3 camera_position = Ogre::Vector3::ZERO;
100  ALCdevice* audio_device = nullptr;
101  ALCcontext* sound_context = nullptr;
102 };
103 
105 
106 } // namespace RoR
107 
108 #endif // USE_OPENAL
RoR::SoundManager::pauseAllSounds
void pauseAllSounds()
Definition: SoundManager.cpp:329
RoR::SoundManager::audio_buffers_in_use_count
int audio_buffers_in_use_count
Definition: SoundManager.h:95
RoR::SoundManager::MAX_HARDWARE_SOURCES
static const unsigned int MAX_HARDWARE_SOURCES
Definition: SoundManager.h:70
RoR::SoundManager
Definition: SoundManager.h:44
RoR::SoundManager::loadWAVFile
bool loadWAVFile(Ogre::String filename, ALuint buffer, Ogre::String resource_group_name="")
Definition: SoundManager.cpp:397
RoR::SoundManager::assign
void assign(int source_index, int hardware_index)
Definition: SoundManager.cpp:291
RoR::SoundManager::setMasterVolume
void setMasterVolume(float v)
Definition: SoundManager.cpp:345
RoR::SoundManager::recomputeSource
void recomputeSource(int source_index, int reason, float vfl, Ogre::Vector3 *vvec)
Definition: SoundManager.cpp:208
RoR::SoundManager::getHardwareSource
ALuint getHardwareSource(int hardware_index)
Definition: SoundManager.h:76
RoR::SoundManager::hardware_sources
ALuint hardware_sources[MAX_HARDWARE_SOURCES]
Definition: SoundManager.h:87
RoR::SoundManager::REFERENCE_DISTANCE
static const float REFERENCE_DISTANCE
Definition: SoundManager.h:69
RoR::Sound
Definition: Sound.h:39
RoR::SoundManager::MAX_AUDIO_BUFFERS
static const unsigned int MAX_AUDIO_BUFFERS
Definition: SoundManager.h:71
RoR::SoundManager::hardware_sources_num
int hardware_sources_num
Definition: SoundManager.h:84
RefCountingObjectPtr< Sound >
RoR::SoundManager::retire
void retire(int source_index)
Definition: SoundManager.cpp:317
RoR::SoundManager::createSound
SoundPtr createSound(Ogre::String filename, Ogre::String resource_group_name="")
Definition: SoundManager.cpp:354
RoR::SoundManager::audio_device
ALCdevice * audio_device
Definition: SoundManager.h:100
RoR::SoundManager::audio_sources
SoundPtr audio_sources[MAX_AUDIO_BUFFERS]
Definition: SoundManager.h:90
RoR::SoundManager::getNumHardwareSources
int getNumHardwareSources()
Definition: SoundManager.h:65
RoR::SoundManager::resumeAllSounds
void resumeAllSounds()
Definition: SoundManager.cpp:337
RoR::SoundManager::hardware_sources_map
int hardware_sources_map[MAX_HARDWARE_SOURCES]
Definition: SoundManager.h:86
Application.h
Central state/object manager and communications hub.
RoR::SoundManager::hardware_sources_in_use_count
int hardware_sources_in_use_count
Definition: SoundManager.h:85
RoR::SoundManager::recomputeAllSources
void recomputeAllSources()
Definition: SoundManager.cpp:166
RoR::SoundManager::sound_context
ALCcontext * sound_context
Definition: SoundManager.h:101
RoR::SoundManager::camera_position
Ogre::Vector3 camera_position
Definition: SoundManager.h:99
RoR::SoundManager::SoundManager
SoundManager()
Definition: SoundManager.cpp:55
RoR::SoundManager::isDisabled
bool isDisabled()
Definition: SoundManager.h:63
RoR::SoundManager::MAX_DISTANCE
static const float MAX_DISTANCE
Definition: SoundManager.h:67
RoR::SoundManager::setCamera
void setCamera(Ogre::Vector3 position, Ogre::Vector3 direction, Ogre::Vector3 up, Ogre::Vector3 velocity)
Definition: SoundManager.cpp:138
RoR::SoundManager::audio_buffers
ALuint audio_buffers[MAX_AUDIO_BUFFERS]
Definition: SoundManager.h:96
RoR::SoundManager::audio_buffer_file_name
Ogre::String audio_buffer_file_name[MAX_AUDIO_BUFFERS]
Definition: SoundManager.h:97
RoR::SoundManager::audio_sources_most_audible
std::pair< int, float > audio_sources_most_audible[MAX_AUDIO_BUFFERS]
Definition: SoundManager.h:92
RoR::SoundManager::~SoundManager
~SoundManager()
Definition: SoundManager.cpp:120
RoR
Definition: AppContext.h:36
RoR::SoundManager::ROLLOFF_FACTOR
static const float ROLLOFF_FACTOR
Definition: SoundManager.h:68