![]() |
Ryle Radio 1.0.0
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. | |
| 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. | |
| 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 20 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 25 of file RadioOutput.cs.
|
private |
Called when tune is modified in the inspector.
Definition at line 103 of file RadioOutput.cs.
| override void RyleRadio.Components.RadioOutput.Init | ( | ) |
Initializes the output itself, and creates all required every required RadioTrackPlayer.
Definition at line 143 of file RadioOutput.cs.
|
protected |
Initializes the RadioData- this needs to be separated from Init() as it would be recursive otherwise.
Definition at line 132 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 358 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 158 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 256 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 221 of file RadioOutput.cs.
Referenced by TryGetPlayer().
|
private |
Creates every RadioTrackPlayer that this output needs for playback.
Definition at line 199 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 289 of file RadioOutput.cs.
|
protectedvirtual |
Updates cachedPos.
Definition at line 113 of file RadioOutput.cs.
|
private |
The normal sample rate of this output, applied to each RadioTrackPlayer.
Definition at line 51 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 46 of file RadioOutput.cs.
Referenced by OnAudioFilterRead(), and Update().
|
protected |
The players used by this output.
Definition at line 41 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 56 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 36 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 95 of file RadioOutput.cs.
|
getprivate set |
Every RadioObserver associated with this output.
Definition at line 61 of file RadioOutput.cs.
Referenced by PlayerCreation().
|
getset |
Event called whenever Tune is changed.
Definition at line 66 of file RadioOutput.cs.
Referenced by ExecOnTune(), and Init().
|
getset |
The tune clamped to the full range.
Definition at line 71 of file RadioOutput.cs.
Referenced by OnAudioFilterRead().
|
get |
Tune scaled to [0 - 1], useful for UI
Definition at line 87 of file RadioOutput.cs.