Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
sound::OpenALSoundManager Class Referencefinal

#include <sound_manager.h>

+ Inheritance diagram for sound::OpenALSoundManager:
+ Collaboration diagram for sound::OpenALSoundManager:

Public Member Functions

 OpenALSoundManager (SoundManagerSingleton *smg, std::unique_ptr< SoundFallbackPathProvider > fallback_path_provider)
 
 ~OpenALSoundManager () override
 
- Public Member Functions inherited from Thread
 Thread (const std::string &name="")
 
virtual ~Thread ()
 
bool start ()
 
bool stop ()
 
bool wait ()
 
bool isCurrentThread ()
 
bool isRunning ()
 
bool stopRequested ()
 
std::thread::id getThreadId ()
 
bool getReturnValue (void **ret)
 
bool bindToProcessor (unsigned int proc_number)
 
bool setPriority (int prio)
 

Public Attributes

MutexedQueue< SoundManagerMsgToMgrm_queue_to_mgr
 
MutexedQueue< SoundManagerMsgToProxym_queue_to_proxy
 

Protected Member Functions

void * run () override
 

Private Member Functions

void stepStreams (f32 dtime)
 
void doFades (f32 dtime)
 
std::shared_ptr< ISoundDataOpenopenSingleSound (const std::string &sound_name)
 Gives the open sound for a loaded sound.
 
std::string getLoadedSoundNameFromGroup (const std::string &group_name)
 Gets a random sound name from a group.
 
std::string getOrLoadLoadedSoundNameFromGroup (const std::string &group_name)
 Same as getLoadedSoundNameFromGroup, but if sound does not exist, try to load from local files.
 
std::shared_ptr< PlayingSoundcreatePlayingSound (const std::string &sound_name, bool loop, f32 volume, f32 pitch, f32 start_time, const std::optional< std::pair< v3f, v3f > > &pos_vel_opt)
 
void playSoundGeneric (sound_handle_t id, const std::string &group_name, bool loop, f32 volume, f32 fade, f32 pitch, bool use_local_fallback, f32 start_time, const std::optional< std::pair< v3f, v3f > > &pos_vel_opt)
 
int removeDeadSounds ()
 Deletes sounds that are dead (=finished).
 
void step (f32 dtime)
 
void pauseAll ()
 
void resumeAll ()
 
void updateListener (const v3f &pos_, const v3f &vel_, const v3f &at_, const v3f &up_)
 
void setListenerGain (f32 gain)
 
bool loadSoundFile (const std::string &name, const std::string &filepath)
 
bool loadSoundData (const std::string &name, std::string &&filedata)
 
void loadSoundFileNoCheck (const std::string &name, const std::string &filepath)
 
void loadSoundDataNoCheck (const std::string &name, std::string &&filedata)
 
void addSoundToGroup (const std::string &sound_name, const std::string &group_name)
 
void playSound (sound_handle_t id, const SoundSpec &spec)
 
void playSoundAt (sound_handle_t id, const SoundSpec &spec, const v3f &pos_, const v3f &vel_)
 
void stopSound (sound_handle_t sound)
 
void fadeSound (sound_handle_t soundid, f32 step, f32 target_gain)
 
void updateSoundPosVel (sound_handle_t sound, const v3f &pos_, const v3f &vel_)
 
void send (SoundManagerMsgToProxy msg)
 
void reportRemovedSound (sound_handle_t id)
 

Private Attributes

std::unique_ptr< SoundFallbackPathProviderm_fallback_path_provider
 
ALCdevice *const m_device
 
ALCcontext *const m_context
 
const ALExtensions m_exts
 
f32 m_time_until_dead_removal = REMOVE_DEAD_SOUNDS_INTERVAL
 
std::unordered_map< std::string, std::unique_ptr< ISoundDataUnopen > > m_sound_datas_unopen
 
std::unordered_map< std::string, std::shared_ptr< ISoundDataOpen > > m_sound_datas_open
 
std::unordered_map< std::string, std::vector< std::string > > m_sound_groups
 
std::unordered_map< sound_handle_t, std::shared_ptr< PlayingSound > > m_sounds_playing
 
std::vector< std::weak_ptr< PlayingSound > > m_sounds_streaming_current_bigstep
 
std::vector< std::weak_ptr< PlayingSound > > m_sounds_streaming_next_bigstep
 
f32 m_stream_timer = STREAM_BIGSTEP_TIME
 
std::vector< std::weak_ptr< PlayingSound > > m_sounds_fading
 
bool m_is_paused = false
 
std::unordered_set< std::string > m_warned_positional_stereo_sounds
 

Additional Inherited Members

- Static Public Member Functions inherited from Thread
static ThreadgetCurrentThread ()
 
static void setName (const std::string &name)
 
static unsigned int getNumberOfProcessors ()
 
- Protected Attributes inherited from Thread
std::string m_name
 

Constructor & Destructor Documentation

◆ OpenALSoundManager()

sound::OpenALSoundManager::OpenALSoundManager ( SoundManagerSingleton * smg,
std::unique_ptr< SoundFallbackPathProvider > fallback_path_provider )

◆ ~OpenALSoundManager()

sound::OpenALSoundManager::~OpenALSoundManager ( )
override

References infostream.

Member Function Documentation

◆ addSoundToGroup()

void sound::OpenALSoundManager::addSoundToGroup ( const std::string & sound_name,
const std::string & group_name )
private

References m_sound_groups.

Referenced by getOrLoadLoadedSoundNameFromGroup(), and run().

+ Here is the caller graph for this function:

◆ createPlayingSound()

std::shared_ptr< PlayingSound > sound::OpenALSoundManager::createPlayingSound ( const std::string & sound_name,
bool loop,
f32 volume,
f32 pitch,
f32 start_time,
const std::optional< std::pair< v3f, v3f > > & pos_vel_opt )
private

References errorstream, infostream, m_exts, m_warned_positional_stereo_sounds, openSingleSound(), sound::warn_if_al_error(), and warningstream.

Referenced by playSoundGeneric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doFades()

void sound::OpenALSoundManager::doFades ( f32 dtime)
private

References m_sounds_fading.

Referenced by step().

+ Here is the caller graph for this function:

◆ fadeSound()

void sound::OpenALSoundManager::fadeSound ( sound_handle_t soundid,
f32 step,
f32 target_gain )
private

References m_sounds_fading, m_sounds_playing, and step().

Referenced by playSoundGeneric(), and run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLoadedSoundNameFromGroup()

std::string sound::OpenALSoundManager::getLoadedSoundNameFromGroup ( const std::string & group_name)
private

Gets a random sound name from a group.

Parameters
group_nameThe name of the sound group.
Returns
The name of a sound in the group, or "" on failure. Getting the sound with openSingleSound directly afterwards will not fail.

References m_sound_groups, myrand(), and openSingleSound().

Referenced by getOrLoadLoadedSoundNameFromGroup(), and playSoundGeneric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrLoadLoadedSoundNameFromGroup()

std::string sound::OpenALSoundManager::getOrLoadLoadedSoundNameFromGroup ( const std::string & group_name)
private

Same as getLoadedSoundNameFromGroup, but if sound does not exist, try to load from local files.

References addSoundToGroup(), getLoadedSoundNameFromGroup(), SoundFallbackPathProvider::getLocalFallbackPathsForSoundname(), loadSoundFile(), and m_fallback_path_provider.

Referenced by playSoundGeneric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadSoundData()

bool sound::OpenALSoundManager::loadSoundData ( const std::string & name,
std::string && filedata )
private

References loadSoundDataNoCheck(), m_sound_datas_open, and m_sound_datas_unopen.

+ Here is the call graph for this function:

◆ loadSoundDataNoCheck()

void sound::OpenALSoundManager::loadSoundDataNoCheck ( const std::string & name,
std::string && filedata )
private

References m_sound_datas_unopen.

Referenced by loadSoundData(), and run().

+ Here is the caller graph for this function:

◆ loadSoundFile()

bool sound::OpenALSoundManager::loadSoundFile ( const std::string & name,
const std::string & filepath )
private

References fs::IsFile(), loadSoundFileNoCheck(), m_sound_datas_open, and m_sound_datas_unopen.

Referenced by getOrLoadLoadedSoundNameFromGroup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadSoundFileNoCheck()

void sound::OpenALSoundManager::loadSoundFileNoCheck ( const std::string & name,
const std::string & filepath )
private

References m_sound_datas_unopen.

Referenced by loadSoundFile(), and run().

+ Here is the caller graph for this function:

◆ openSingleSound()

std::shared_ptr< ISoundDataOpen > sound::OpenALSoundManager::openSingleSound ( const std::string & sound_name)
private

Gives the open sound for a loaded sound.

Opens the sound if currently unopened.

Parameters
sound_nameName of the sound.
Returns
The open sound.

References m_sound_datas_open, and m_sound_datas_unopen.

Referenced by createPlayingSound(), and getLoadedSoundNameFromGroup().

+ Here is the caller graph for this function:

◆ pauseAll()

void sound::OpenALSoundManager::pauseAll ( )
private

References m_is_paused, m_sounds_playing, and sound::PlayingSound::pause().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ playSound()

void sound::OpenALSoundManager::playSound ( sound_handle_t id,
const SoundSpec & spec )
private

References SoundSpec::fade, SoundSpec::gain, SoundSpec::loop, SoundSpec::name, SoundSpec::pitch, playSoundGeneric(), SoundSpec::start_time, and SoundSpec::use_local_fallback.

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ playSoundAt()

void sound::OpenALSoundManager::playSoundAt ( sound_handle_t id,
const SoundSpec & spec,
const v3f & pos_,
const v3f & vel_ )
private

References SoundSpec::fade, SoundSpec::gain, SoundSpec::loop, SoundSpec::name, SoundSpec::pitch, playSoundGeneric(), SoundSpec::start_time, sound::swap_handedness(), and SoundSpec::use_local_fallback.

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ playSoundGeneric()

void sound::OpenALSoundManager::playSoundGeneric ( sound_handle_t id,
const std::string & group_name,
bool loop,
f32 volume,
f32 fade,
f32 pitch,
bool use_local_fallback,
f32 start_time,
const std::optional< std::pair< v3f, v3f > > & pos_vel_opt )
private

References createPlayingSound(), fadeSound(), getLoadedSoundNameFromGroup(), getOrLoadLoadedSoundNameFromGroup(), infostream, m_sounds_playing, m_sounds_streaming_next_bigstep, reportRemovedSound(), and warningstream.

Referenced by playSound(), and playSoundAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeDeadSounds()

int sound::OpenALSoundManager::removeDeadSounds ( )
private

Deletes sounds that are dead (=finished).

Returns
Number of removed sounds.

References m_sounds_playing, and reportRemovedSound().

Referenced by step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reportRemovedSound()

void sound::OpenALSoundManager::reportRemovedSound ( sound_handle_t id)
inlineprivate

References send().

Referenced by playSoundGeneric(), removeDeadSounds(), and stopSound().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resumeAll()

void sound::OpenALSoundManager::resumeAll ( )
private

References m_is_paused, m_sounds_playing, and sound::PlayingSound::resume().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void * sound::OpenALSoundManager::run ( )
overrideprotectedvirtual

Implements Thread.

References addSoundToGroup(), fadeSound(), porting::getTimeMs(), loadSoundDataNoCheck(), loadSoundFileNoCheck(), m_queue_to_mgr, pauseAll(), playSound(), playSoundAt(), MutexedQueue< T >::pop_frontNoEx(), resumeAll(), send(), setListenerGain(), sound::SOUNDTHREAD_DTIME, FrameMarker::started(), step(), stopSound(), updateListener(), and updateSoundPosVel().

+ Here is the call graph for this function:

◆ send()

void sound::OpenALSoundManager::send ( SoundManagerMsgToProxy msg)
inlineprivate

References m_queue_to_proxy, and MutexedQueue< T >::push_back().

Referenced by reportRemovedSound(), and run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setListenerGain()

void sound::OpenALSoundManager::setListenerGain ( f32 gain)
private

Referenced by run().

+ Here is the caller graph for this function:

◆ step()

void sound::OpenALSoundManager::step ( f32 dtime)
private

References doFades(), m_sound_datas_open, m_sound_datas_unopen, m_sound_groups, m_sounds_playing, m_time_until_dead_removal, sound::REMOVE_DEAD_SOUNDS_INTERVAL, removeDeadSounds(), stepStreams(), and verbosestream.

Referenced by fadeSound(), and run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stepStreams()

void sound::OpenALSoundManager::stepStreams ( f32 dtime)
private

References m_sounds_streaming_current_bigstep, m_sounds_streaming_next_bigstep, m_stream_timer, and sound::STREAM_BIGSTEP_TIME.

Referenced by step().

+ Here is the caller graph for this function:

◆ stopSound()

void sound::OpenALSoundManager::stopSound ( sound_handle_t sound)
private

References m_sounds_playing, and reportRemovedSound().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateListener()

void sound::OpenALSoundManager::updateListener ( const v3f & pos_,
const v3f & vel_,
const v3f & at_,
const v3f & up_ )
private

References sound::swap_handedness(), and sound::warn_if_al_error().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateSoundPosVel()

void sound::OpenALSoundManager::updateSoundPosVel ( sound_handle_t sound,
const v3f & pos_,
const v3f & vel_ )
private

References m_sounds_playing, and sound::swap_handedness().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_context

ALCcontext* const sound::OpenALSoundManager::m_context
private

◆ m_device

ALCdevice* const sound::OpenALSoundManager::m_device
private

◆ m_exts

const ALExtensions sound::OpenALSoundManager::m_exts
private

Referenced by createPlayingSound().

◆ m_fallback_path_provider

std::unique_ptr<SoundFallbackPathProvider> sound::OpenALSoundManager::m_fallback_path_provider
private

◆ m_is_paused

bool sound::OpenALSoundManager::m_is_paused = false
private

Referenced by pauseAll(), and resumeAll().

◆ m_queue_to_mgr

MutexedQueue<SoundManagerMsgToMgr> sound::OpenALSoundManager::m_queue_to_mgr

◆ m_queue_to_proxy

◆ m_sound_datas_open

std::unordered_map<std::string, std::shared_ptr<ISoundDataOpen> > sound::OpenALSoundManager::m_sound_datas_open
private

◆ m_sound_datas_unopen

std::unordered_map<std::string, std::unique_ptr<ISoundDataUnopen> > sound::OpenALSoundManager::m_sound_datas_unopen
private

◆ m_sound_groups

std::unordered_map<std::string, std::vector<std::string> > sound::OpenALSoundManager::m_sound_groups
private

◆ m_sounds_fading

std::vector<std::weak_ptr<PlayingSound> > sound::OpenALSoundManager::m_sounds_fading
private

Referenced by doFades(), and fadeSound().

◆ m_sounds_playing

std::unordered_map<sound_handle_t, std::shared_ptr<PlayingSound> > sound::OpenALSoundManager::m_sounds_playing
private

◆ m_sounds_streaming_current_bigstep

std::vector<std::weak_ptr<PlayingSound> > sound::OpenALSoundManager::m_sounds_streaming_current_bigstep
private

Referenced by stepStreams().

◆ m_sounds_streaming_next_bigstep

std::vector<std::weak_ptr<PlayingSound> > sound::OpenALSoundManager::m_sounds_streaming_next_bigstep
private

Referenced by playSoundGeneric(), and stepStreams().

◆ m_stream_timer

f32 sound::OpenALSoundManager::m_stream_timer = STREAM_BIGSTEP_TIME
private

Referenced by stepStreams().

◆ m_time_until_dead_removal

f32 sound::OpenALSoundManager::m_time_until_dead_removal = REMOVE_DEAD_SOUNDS_INTERVAL
private

Referenced by step().

◆ m_warned_positional_stereo_sounds

std::unordered_set<std::string> sound::OpenALSoundManager::m_warned_positional_stereo_sounds
private

Referenced by createPlayingSound().


The documentation for this class was generated from the following files: