Ryle Radio 1.0.1
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RyleRadio.Components.RadioOutput Class Reference

The main scene component for a radio that plays it through an AudioSource. More...

Inheritance diagram for RyleRadio.Components.RadioOutput:

Public Types

enum  MultiplePlayersSelector { Youngest , Oldest , Random }
 The method by which a RadioTrackPlayer is chosen from this output. Really only matters when you're playing the same track repeatedly causing overlaps. More...

Public Member Functions

override void Init ()
 Initializes the output itself, and creates all required every required RadioTrackPlayer.
RadioTrackPlayer PlayOneShot (string _id)
 Plays a track as a one-shot. A one-shot destroys itself when its track ends.
RadioTrackPlayer PlayLoop (string _id)
 Plays a track as a loop. A loop restarts when the track ends, then continues to play.
bool TryGetPlayer (string _trackID, out RadioTrackPlayer _player, bool _createNew=false, MultiplePlayersSelector _multiplePlayerSelector=MultiplePlayersSelector.Youngest)
 Gets an active RadioTrackPlayer from this output.
Public Member Functions inherited from RyleRadio.Components.Base.RadioComponent
void Init ()
 Initialises this component.

Protected Member Functions

virtual void Update ()
 Updates cachedPos.
void LocalInit ()
 Initializes the RadioData- this needs to be separated from Init() as it would be recursive otherwise.
void PlayerCreation (RadioTrackPlayer _player)
 Sets up and stores a new RadioTrackPlayer and alerts any RadioObserver of its creation.
virtual void OnAudioFilterRead (float[] _data, int _channels)
 Gets a set of samples from the radio to play from the AudioSource- this preserves the settings on the Source, e.g: volume, 3D. This is the main driving method for the radio's playback.

Protected Attributes

float tune
 The current tune value of this output- akin to the frequency of a real radio. Controls what tracks can be heard through tune power. Never modify this directly except for in the inspector, use Tune instead.
List< RadioTrackPlayerplayers = new()
 The players used by this output.
Vector3 cachedPos
 The position of this object as of the last frame update. We can't access transform.position from the audio thread, so we cache it here.
Protected Attributes inherited from RyleRadio.Components.Base.RadioComponent
RadioData data
 The RadioData (aka just radio) that this component is linked to.

Properties

List< RadioObserverObservers = new() [get, private set]
 Every RadioObserver associated with this output.
Action< float > OnTune = new(_ => { }) [get, set]
 Event called whenever Tune is changed.
Action OnInit = new(() => { }) [get, set]
 Event called when this output is finished initializing- mainly useful for WebGL when we use AwaitLoadingThenInit.
float Tune [get, set]
 The tune clamped to the full range.
float Tune01 [get]
 Tune scaled to [0 - 1], useful for UI
float DisplayTune [get]
 Tune with limited decimal points- looks better when displayed, more like an actual radio
Properties inherited from RyleRadio.Components.Base.RadioComponent
RadioData Data [get]
 Read-only accessor for data.

Private Member Functions

void ExecOnTune ()
 Called when tune is modified in the inspector.
IEnumerator AwaitLoadingThenInit ()
 Waits for all AudioClips used in this radio to be loaded before initializing the radio. This is used as WebGL will cause errors if a clip is used before it's fully loaded.
void StartPlayers ()
 Creates every RadioTrackPlayer that this output needs for playback.

Private Attributes

float baseSampleRate
 The normal sample rate of this output, applied to each RadioTrackPlayer.
Action playEvents = () => { }
 Called at the end of every audio cycle so that we don't interrupt threads when manipulating RadioTrackPlayers.

Detailed Description

The main scene component for a radio that plays it through an AudioSource.

See RadioTrackPlayer as well for more info on how playback works

Definition at line 22 of file RadioOutput.cs.

Member Enumeration Documentation

◆ MultiplePlayersSelector

The method by which a RadioTrackPlayer is chosen from this output. Really only matters when you're playing the same track repeatedly causing overlaps.

Enumerator
Youngest 

Selects the youngest player.

Oldest 

Selects the oldest player.

Random 

Selects a random player (probably useless but funny to have)

Definition at line 27 of file RadioOutput.cs.

Member Function Documentation

◆ AwaitLoadingThenInit()

IEnumerator RyleRadio.Components.RadioOutput.AwaitLoadingThenInit ( )
private

Waits for all AudioClips used in this radio to be loaded before initializing the radio. This is used as WebGL will cause errors if a clip is used before it's fully loaded.

Definition at line 143 of file RadioOutput.cs.

◆ ExecOnTune()

void RyleRadio.Components.RadioOutput.ExecOnTune ( )
private

Called when tune is modified in the inspector.

Definition at line 110 of file RadioOutput.cs.

◆ Init()

override void RyleRadio.Components.RadioOutput.Init ( )

Initializes the output itself, and creates all required every required RadioTrackPlayer.

Definition at line 190 of file RadioOutput.cs.

◆ LocalInit()

void RyleRadio.Components.RadioOutput.LocalInit ( )
protected

Initializes the RadioData- this needs to be separated from Init() as it would be recursive otherwise.

Definition at line 179 of file RadioOutput.cs.

◆ OnAudioFilterRead()

virtual void RyleRadio.Components.RadioOutput.OnAudioFilterRead ( float[] _data,
int _channels )
protectedvirtual

Gets a set of samples from the radio to play from the AudioSource- this preserves the settings on the Source, e.g: volume, 3D. This is the main driving method for the radio's playback.

The method itself appears to have been initially introduced so devs could create custom audio filters, but it just so happens we can use it for direct output of samples too!

Parameters
_dataWhatever other audio is playing from the AudioSource- preferably nothing
_channelsThe number of channels the AudioSource is using- the radio itself is limited to one channel, but still outputs as two- they'll just be identical.

Definition at line 405 of file RadioOutput.cs.

◆ PlayerCreation()

void RyleRadio.Components.RadioOutput.PlayerCreation ( RadioTrackPlayer _player)
protected

Sets up and stores a new RadioTrackPlayer and alerts any RadioObserver of its creation.

Parameters
_playerThe new player to set up

Definition at line 205 of file RadioOutput.cs.

Referenced by PlayLoop(), PlayOneShot(), and StartPlayers().

◆ PlayLoop()

RadioTrackPlayer RyleRadio.Components.RadioOutput.PlayLoop ( string _id)

Plays a track as a loop. A loop restarts when the track ends, then continues to play.

Parameters
_id
Returns

Definition at line 303 of file RadioOutput.cs.

◆ PlayOneShot()

RadioTrackPlayer RyleRadio.Components.RadioOutput.PlayOneShot ( string _id)

Plays a track as a one-shot. A one-shot destroys itself when its track ends.

Parameters
_id
Returns

Definition at line 268 of file RadioOutput.cs.

Referenced by TryGetPlayer().

◆ StartPlayers()

void RyleRadio.Components.RadioOutput.StartPlayers ( )
private

Creates every RadioTrackPlayer that this output needs for playback.

Definition at line 246 of file RadioOutput.cs.

Referenced by Init().

◆ TryGetPlayer()

bool RyleRadio.Components.RadioOutput.TryGetPlayer ( string _trackID,
out RadioTrackPlayer _player,
bool _createNew = false,
MultiplePlayersSelector _multiplePlayerSelector = MultiplePlayersSelector::Youngest )

Gets an active RadioTrackPlayer from this output.

Parameters
_trackIDThe ID of the track used by the player
_playerOutput parameter containing the found player
_createNewWhether or not a new player should be created if one can't be found. Players created this way are always one-shots
_multiplePlayerSelectorHow a player is selected when multiple are present for the same track
Returns
True if a player was found or created, false if not

Definition at line 336 of file RadioOutput.cs.

◆ Update()

virtual void RyleRadio.Components.RadioOutput.Update ( )
protectedvirtual

Updates cachedPos.

Definition at line 120 of file RadioOutput.cs.

Member Data Documentation

◆ baseSampleRate

float RyleRadio.Components.RadioOutput.baseSampleRate
private

The normal sample rate of this output, applied to each RadioTrackPlayer.

Definition at line 53 of file RadioOutput.cs.

Referenced by Init(), PlayLoop(), PlayOneShot(), and StartPlayers().

◆ cachedPos

Vector3 RyleRadio.Components.RadioOutput.cachedPos
protected

The position of this object as of the last frame update. We can't access transform.position from the audio thread, so we cache it here.

Definition at line 48 of file RadioOutput.cs.

Referenced by OnAudioFilterRead(), and Update().

◆ players

List<RadioTrackPlayer> RyleRadio.Components.RadioOutput.players = new()
protected

The players used by this output.

Definition at line 43 of file RadioOutput.cs.

Referenced by OnAudioFilterRead(), PlayerCreation(), PlayOneShot(), and TryGetPlayer().

◆ playEvents

Action RyleRadio.Components.RadioOutput.playEvents = () => { }
private

Called at the end of every audio cycle so that we don't interrupt threads when manipulating RadioTrackPlayers.

Definition at line 58 of file RadioOutput.cs.

Referenced by OnAudioFilterRead(), PlayLoop(), and PlayOneShot().

◆ tune

float RyleRadio.Components.RadioOutput.tune
protected

The current tune value of this output- akin to the frequency of a real radio. Controls what tracks can be heard through tune power. Never modify this directly except for in the inspector, use Tune instead.

Definition at line 38 of file RadioOutput.cs.

Referenced by ExecOnTune(), and Init().

Property Documentation

◆ DisplayTune

float RyleRadio.Components.RadioOutput.DisplayTune
get

Tune with limited decimal points- looks better when displayed, more like an actual radio

Definition at line 102 of file RadioOutput.cs.

◆ Observers

List<RadioObserver> RyleRadio.Components.RadioOutput.Observers = new()
getprivate set

Every RadioObserver associated with this output.

Definition at line 63 of file RadioOutput.cs.

Referenced by PlayerCreation().

◆ OnInit

Action RyleRadio.Components.RadioOutput.OnInit = new(() => { })
getset

Event called when this output is finished initializing- mainly useful for WebGL when we use AwaitLoadingThenInit.

Definition at line 73 of file RadioOutput.cs.

◆ OnTune

Action<float> RyleRadio.Components.RadioOutput.OnTune = new(_ => { })
getset

Event called whenever Tune is changed.

Definition at line 68 of file RadioOutput.cs.

Referenced by ExecOnTune(), and Init().

◆ Tune

float RyleRadio.Components.RadioOutput.Tune
getset

The tune clamped to the full range.

Definition at line 78 of file RadioOutput.cs.

Referenced by OnAudioFilterRead().

◆ Tune01

float RyleRadio.Components.RadioOutput.Tune01
get

Tune scaled to [0 - 1], useful for UI

Definition at line 94 of file RadioOutput.cs.


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