libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::Audio Class Reference

Manages audio playback through a platform-specific AudioPlayer. More...

#include <Audio.h>

Inheritance diagram for Ship::Audio:
[legend]
Collaboration diagram for Ship::Audio:
[legend]

Public Member Functions

 Audio (AudioSettings settings, std::shared_ptr< Config > config=nullptr)
 Constructs an Audio manager with the given initial settings.
 
 ~Audio ()
 
std::shared_ptr< AudioPlayerGetAudioPlayer ()
 Returns the currently active AudioPlayer instance.
 
AudioBackend GetCurrentAudioBackend ()
 Returns the identifier of the currently active audio backend.
 
std::shared_ptr< std::vector< AudioBackend > > GetAvailableAudioBackends ()
 Returns all audio backends available on the current platform.
 
void SetCurrentAudioBackend (AudioBackend backend)
 Switches to a different audio backend, reinitialising the AudioPlayer.
 
void SetAudioChannels (AudioChannelsSetting channels)
 Changes the channel layout and reinitialises the audio player.
 
AudioChannelsSetting GetAudioChannels () const
 Returns the current audio channel configuration.
 
- Public Member Functions inherited from Ship::Component
 Component (const std::string &name, std::shared_ptr< Context > context=nullptr)
 Constructs a Component with the given name.
 
virtual ~Component ()
 
void Init (const nlohmann::json &initArgs=nlohmann::json::object())
 Performs one-time initialization of this component.
 
bool IsInitialized () const
 Returns true once Init() (or MarkInitialized()) has completed successfully.
 
const std::string & GetName () const
 Returns the name of this Component.
 
std::string ToString () const
 Returns a human-readable string representation (e.g. "Name (id)").
 
std::string ToTreeString (int depth=0) const
 Returns a human-readable tree representation of this component and its children.
 
 operator std::string () const
 Conversion operator to std::string; equivalent to ToString().
 
ParentComponentListGetParents ()
 Returns a mutable reference to the parent list.
 
const ParentComponentListGetParents () const
 Returns a const reference to the parent list.
 
ComponentListGetChildren ()
 Returns a mutable reference to the child list.
 
const ComponentListGetChildren () const
 Returns a const reference to the child list.
 
virtual std::shared_ptr< ComponentTryGetSharedComponent () noexcept
 Returns a shared_ptr to this Component when available, otherwise nullptr.
 
virtual std::shared_ptr< ComponentGetSharedComponent ()
 Returns a shared_ptr to this Component via the correct enable_shared_from_this base.
 
template<typename T >
bool HasInChildren () const
 Checks whether any descendant Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInChildren () const
 Returns the first descendant that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInChildren () const
 Returns all descendants that match type T via BFS.
 
template<typename T >
bool HasInParents () const
 Checks whether any ancestor Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInParents () const
 Returns the first ancestor that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInParents () const
 Returns all ancestors that match type T via BFS.
 
- Public Member Functions inherited from Ship::Part
 Part ()
 Constructs a Part and assigns it a unique ID.
 
 Part (std::shared_ptr< Context > context)
 Constructs a Part with an explicit Context reference and unique ID.
 
virtual ~Part ()=default
 
uint64_t GetId () const
 Returns the unique identifier for this Part.
 
bool operator== (const Part &other) const
 Compares two Parts for equality by their unique IDs.
 
std::shared_ptr< ContextGetContext () const
 Returns the Context this Part belongs to, or nullptr if unset.
 
void SetContext (std::shared_ptr< Context > ctx)
 Sets the Context this Part belongs to.
 

Protected Member Functions

void InitAudioPlayer ()
 (Re)initialises the AudioPlayer for the current backend and channel settings.
 
void OnInit (const nlohmann::json &initArgs=nlohmann::json::object()) override
 Implements audio initialization. Called by Component::Init().
 
AudioBackend GetSavedAudioBackend ()
 Reads and validates the audio backend from the persisted config.
 
AudioChannelsSetting GetSavedAudioChannelsSetting ()
 Reads and validates the audio channel layout from the persisted config.
 
- Protected Member Functions inherited from Ship::Component
void MarkInitialized ()
 Marks this component as initialized without going through Init().
 
template<typename T >
std::shared_ptr< T > RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const
 Returns a cached dependency after validating it exists and is initialized.
 
- Protected Member Functions inherited from Ship::Part
virtual void OnAdded (bool forced)
 Called after this Part has been added to a PartList.
 
virtual void OnRemoved (bool forced)
 Called after this Part has been removed from a PartList.
 

Detailed Description

Manages audio playback through a platform-specific AudioPlayer.

Audio selects and initialises an AudioPlayer backend based on the AudioSettings provided at construction. The backend can be switched at runtime via SetCurrentAudioBackend(); the channel layout can be changed via SetAudioChannels() without restarting the application.

Required dependencies (constructor-injected):

  • Config — cached on the class and used by SetCurrentAudioBackend() to load/persist the selected audio backend. Any code path that uses the cached Config validates that it exists and is initialized before use.

Obtain the instance from Context::GetChildren().GetFirst<Audio>().

Constructor & Destructor Documentation

◆ Audio()

Ship::Audio::Audio ( AudioSettings  settings,
std::shared_ptr< Config config = nullptr 
)
inline

Constructs an Audio manager with the given initial settings.

Parameters
settingsInitial audio backend selection and channel configuration.

◆ ~Audio()

Ship::Audio::~Audio ( )

Member Function Documentation

◆ GetAudioChannels()

AudioChannelsSetting Ship::Audio::GetAudioChannels ( ) const

Returns the current audio channel configuration.

◆ GetAudioPlayer()

std::shared_ptr< AudioPlayer > Ship::Audio::GetAudioPlayer ( )

Returns the currently active AudioPlayer instance.

◆ GetAvailableAudioBackends()

std::shared_ptr< std::vector< AudioBackend > > Ship::Audio::GetAvailableAudioBackends ( )

Returns all audio backends available on the current platform.

◆ GetCurrentAudioBackend()

AudioBackend Ship::Audio::GetCurrentAudioBackend ( )

Returns the identifier of the currently active audio backend.

◆ GetSavedAudioBackend()

AudioBackend Ship::Audio::GetSavedAudioBackend ( )
protected

Reads and validates the audio backend from the persisted config.

◆ GetSavedAudioChannelsSetting()

AudioChannelsSetting Ship::Audio::GetSavedAudioChannelsSetting ( )
protected

Reads and validates the audio channel layout from the persisted config.

◆ InitAudioPlayer()

void Ship::Audio::InitAudioPlayer ( )
protected

(Re)initialises the AudioPlayer for the current backend and channel settings.

◆ OnInit()

void Ship::Audio::OnInit ( const nlohmann::json &  initArgs = nlohmann::json::object())
overrideprotectedvirtual

Implements audio initialization. Called by Component::Init().

Reimplemented from Ship::Component.

◆ SetAudioChannels()

void Ship::Audio::SetAudioChannels ( AudioChannelsSetting  channels)

Changes the channel layout and reinitialises the audio player.

Safe to call at runtime without restarting the game.

Parameters
channelsNew channel configuration (stereo, surround, etc.).

◆ SetCurrentAudioBackend()

void Ship::Audio::SetCurrentAudioBackend ( AudioBackend  backend)

Switches to a different audio backend, reinitialising the AudioPlayer.

Parameters
backendThe backend to activate.

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