![]() |
Ryle Radio 1.0.1
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
|
The main scene component for a radio that plays it through an AudioSource. More...
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< RadioTrackPlayer > | players = 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< RadioObserver > | Observers = 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. | |
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.
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.
|
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.
|
private |
Called when tune is modified in the inspector.
Definition at line 110 of file RadioOutput.cs.
| 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.
|
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.
|
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!
| _data | Whatever other audio is playing from the AudioSource- preferably nothing |
| _channels | The 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.
|
protected |
Sets up and stores a new RadioTrackPlayer and alerts any RadioObserver of its creation.
| _player | The new player to set up |
Definition at line 205 of file RadioOutput.cs.
Referenced by PlayLoop(), PlayOneShot(), and StartPlayers().
| RadioTrackPlayer RyleRadio.Components.RadioOutput.PlayLoop | ( | string | _id | ) |
Plays a track as a loop. A loop restarts when the track ends, then continues to play.
| _id |
Definition at line 303 of file RadioOutput.cs.
| RadioTrackPlayer RyleRadio.Components.RadioOutput.PlayOneShot | ( | string | _id | ) |
Plays a track as a one-shot. A one-shot destroys itself when its track ends.
| _id |
Definition at line 268 of file RadioOutput.cs.
Referenced by TryGetPlayer().
|
private |
Creates every RadioTrackPlayer that this output needs for playback.
Definition at line 246 of file RadioOutput.cs.
Referenced by Init().
| bool RyleRadio.Components.RadioOutput.TryGetPlayer | ( | string | _trackID, |
| out RadioTrackPlayer | _player, | ||
| bool | _createNew = false, | ||
| MultiplePlayersSelector | _multiplePlayerSelector = MultiplePlayersSelector::Youngest ) |
Gets an active RadioTrackPlayer from this output.
| _trackID | The ID of the track used by the player |
| _player | Output parameter containing the found player |
| _createNew | Whether or not a new player should be created if one can't be found. Players created this way are always one-shots |
| _multiplePlayerSelector | How a player is selected when multiple are present for the same track |
Definition at line 336 of file RadioOutput.cs.
|
protectedvirtual |
Updates cachedPos.
Definition at line 120 of file RadioOutput.cs.
|
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().
|
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().
|
protected |
The players used by this output.
Definition at line 43 of file RadioOutput.cs.
Referenced by OnAudioFilterRead(), PlayerCreation(), PlayOneShot(), and TryGetPlayer().
|
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().
|
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().
|
get |
Tune with limited decimal points- looks better when displayed, more like an actual radio
Definition at line 102 of file RadioOutput.cs.
|
getprivate set |
Every RadioObserver associated with this output.
Definition at line 63 of file RadioOutput.cs.
Referenced by PlayerCreation().
|
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.
|
getset |
Event called whenever Tune is changed.
Definition at line 68 of file RadioOutput.cs.
Referenced by ExecOnTune(), and Init().
|
getset |
The tune clamped to the full range.
Definition at line 78 of file RadioOutput.cs.
Referenced by OnAudioFilterRead().
|
get |
Tune scaled to [0 - 1], useful for UI
Definition at line 94 of file RadioOutput.cs.