![]() |
Ryle Radio 1.0.0
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
|
A class that plays a certain RadioTrack at runtime. It's created newly for each track on each RadioOutput, and manages the playback entirely. More...
Public Types | |
| enum | PlayerType { Loop , OneShot } |
| The different types of Player- mainly changes what it does when the end of the track is reached. More... | |
Public Member Functions | |
| RadioTrackPlayer (RadioTrackWrapper _trackW, PlayerType _playerType, float _baseSampleRate) | |
| Creates a new player for the provided track. | |
| void | UpdateSampleIncrement () |
| Updates the sampleIncrement variable to match the current track. | |
| float | GetSample (float _tune, Vector3 _receiverPosition, float _otherVolume, out float _outVolume, bool _applyVolume=true) |
| Gets the current sample from the track according to playback. I would recommend reading the code comments for this method as they explain how the entire sample playback and evaluation process works | |
| void | IncrementSample () |
| Move this player to the next sample. | |
| void | Stop () |
| Stop playback and destroy this player. Make sure any references to it are removed as well. | |
| void | ResetProgress () |
| Resets the Progress of this player to 0. | |
| void | Destroy () |
| Invokes DoDestroy, destroying the player. | |
| float | GetBroadcastPower (Vector3 _receiverPosition) |
| Gets the broadcast power of this player using the position of the Output and any any RadioBroadcaster. | |
| float | GetInsulation (Vector3 _receiverPosition) |
| Gets the insulation multiplier of this player using the position of the output and the bounds of any RadioInsulator. | |
Properties | |
| RadioTrackWrapper | TrackW [get, private set] |
| The track that this player is associated with and plays during runtime. | |
| double | Progress = 0 [get, private set] |
| How many samples through the track this player is- not a whole number as we increment it with different values depending on the track's sample rate. | |
| float | ProgressFraction [get] |
| How far through the track this player is, from [0 - 1]. | |
| PlayerType | PlayType [get, private set] |
| The type of player this is- what happens when the track ends. | |
| Action< RadioTrackPlayer > | DoDestroy = new(_ => { }) [get, set] |
| Event called in order to destroy this player- this can either be invoked directly or as part of the Destroy() method. | |
| Action< RadioTrackPlayer > | OnPlay = new(_ => { }) [get, set] |
| Event called when the player starts playing. | |
| Action< RadioTrackPlayer > | OnStop = new(_ => { }) [get, set] |
| Event called when the player is stopped through Stop() | |
| Action< RadioTrackPlayer, bool > | OnPause = new((_, _) => { }) [get, set] |
| Event called when the player's pause state is changed- the bool is true if the player is being paused, false if unpaused. | |
| Action< RadioTrackPlayer > | OnSample = new(_ => { }) [get, set] |
| Event called when this player retreieves a sample from its track. | |
| Action< RadioTrackPlayer > | OnEnd [get, set] |
| Event called when the player reaches the end of its track naturally, before it takes an action depending on the PlayType (e.g: looping). This is not invoked when the player is stopped or reset. | |
| Action< RadioTrackPlayer, float > | OnVolume = new((_, _) => { }) [get, set] |
| Event called when the volume of this player is captured for a sample. Volume is the product of Tune power, Broadcast power, and Insulation. | |
| Action< RadioTrackPlayer, float > | OnGain = new((_, _) => { }) [get, set] |
| Event called when the gain for this player is captured for a sample. Gain is a direct change to the loudness of a track. | |
| Action< RadioTrackPlayer, float > | OnTunePower = new((_, _) => { }) [get, set] |
| Event called when the tune power for this player is captured for a sample. Tune power is the loudness of a track based on the Tune value of the RadioOutput. | |
| Action< RadioTrackPlayer, float > | OnBroadcastPower = new((_, _) => { }) [get, set] |
| Event called when the broadcast power for this player is captured for a sample. Broadcast power is the loudness of a track based on the position of the RadioOutput relative to any RadioBroadcaster. | |
| Action< RadioTrackPlayer, float > | OnInsulation = new((_, _) => { }) [get, set] |
| Event called when the insulation for this player is captured for a sample. Insulation is the quietness of a track based on the position of the RadioOutput relative to any RadioInsulator. | |
| bool | Paused [get, set] |
| Whether or not this player has been paused, temporarily halting playback of the track. Changing this value pauses/unpauses the player. | |
Private Attributes | |
| float | sampleIncrement |
| The amount that Progress is increased by every sample- the ratio of the track's sample speed to the baseSampleRate. | |
| float | baseSampleRate |
| The sample rate of the RadioOutput that this player is used by- that is, the sample rate of the radio. | |
| bool | isStopped = false |
| Whether or not this player has been stopped- prevents it from being stopped multiple times. | |
A class that plays a certain RadioTrack at runtime. It's created newly for each track on each RadioOutput, and manages the playback entirely.
As such, this script is a central point for information about the playback process.
Definition at line 13 of file RadioTrackPlayer.cs.
The different types of Player- mainly changes what it does when the end of the track is reached.
| Enumerator | |
|---|---|
| Loop | When it ends, the player goes back to the start and plays the track again. |
| OneShot | When it ends, the player destroys itself and stops playing. |
Definition at line 18 of file RadioTrackPlayer.cs.
| RyleRadio.Tracks.RadioTrackPlayer.RadioTrackPlayer | ( | RadioTrackWrapper | _trackW, |
| PlayerType | _playerType, | ||
| float | _baseSampleRate ) |
Creates a new player for the provided track.
| _trackW | The track for this player to play |
| _playerType | The type of player this is (what happens when the track ends) |
| _baseSampleRate | The sample rate of the RadioOutput using this Player |
Definition at line 136 of file RadioTrackPlayer.cs.
| void RyleRadio.Tracks.RadioTrackPlayer.Destroy | ( | ) |
Invokes DoDestroy, destroying the player.
Definition at line 339 of file RadioTrackPlayer.cs.
Referenced by Stop().
| float RyleRadio.Tracks.RadioTrackPlayer.GetBroadcastPower | ( | Vector3 | _receiverPosition | ) |
Gets the broadcast power of this player using the position of the Output and any any RadioBroadcaster.
| _receiverPosition | The position of the Output |
Definition at line 349 of file RadioTrackPlayer.cs.
Referenced by GetSample().
| float RyleRadio.Tracks.RadioTrackPlayer.GetInsulation | ( | Vector3 | _receiverPosition | ) |
Gets the insulation multiplier of this player using the position of the output and the bounds of any RadioInsulator.
| _receiverPosition | The position of the Output |
Definition at line 385 of file RadioTrackPlayer.cs.
Referenced by GetSample().
| float RyleRadio.Tracks.RadioTrackPlayer.GetSample | ( | float | _tune, |
| Vector3 | _receiverPosition, | ||
| float | _otherVolume, | ||
| out float | _outVolume, | ||
| bool | _applyVolume = true ) |
Gets the current sample from the track according to playback. I would recommend reading the code comments for this method as they explain how the entire sample playback and evaluation process works
| _tune | The tune value of the Output |
| _receiverPosition | The position of the Output |
| _otherVolume | The sum of the samples of previous tracks, according to the order in RadioData. See: RadioTrack.attenuation |
| _outVolume | The volume of this sample to be added to _otherVolume |
| _applyVolume | Whether or not Volume (tune power * broadcast power * insulation) should be applied |
Definition at line 187 of file RadioTrackPlayer.cs.
Referenced by RyleRadio.Components.RadioOutput.OnAudioFilterRead().
| void RyleRadio.Tracks.RadioTrackPlayer.IncrementSample | ( | ) |
Move this player to the next sample.
Definition at line 259 of file RadioTrackPlayer.cs.
Referenced by RyleRadio.Components.RadioOutput.OnAudioFilterRead().
| void RyleRadio.Tracks.RadioTrackPlayer.ResetProgress | ( | ) |
Resets the Progress of this player to 0.
Definition at line 331 of file RadioTrackPlayer.cs.
| void RyleRadio.Tracks.RadioTrackPlayer.Stop | ( | ) |
Stop playback and destroy this player. Make sure any references to it are removed as well.
Definition at line 313 of file RadioTrackPlayer.cs.
Referenced by IncrementSample().
| void RyleRadio.Tracks.RadioTrackPlayer.UpdateSampleIncrement | ( | ) |
Updates the sampleIncrement variable to match the current track.
Definition at line 154 of file RadioTrackPlayer.cs.
Referenced by IncrementSample(), and RadioTrackPlayer().
|
private |
The sample rate of the RadioOutput that this player is used by- that is, the sample rate of the radio.
Definition at line 122 of file RadioTrackPlayer.cs.
Referenced by RadioTrackPlayer(), and UpdateSampleIncrement().
|
private |
Whether or not this player has been stopped- prevents it from being stopped multiple times.
Definition at line 127 of file RadioTrackPlayer.cs.
Referenced by GetSample(), IncrementSample(), and Stop().
|
private |
The amount that Progress is increased by every sample- the ratio of the track's sample speed to the baseSampleRate.
Definition at line 117 of file RadioTrackPlayer.cs.
Referenced by IncrementSample(), and UpdateSampleIncrement().
|
getset |
Event called in order to destroy this player- this can either be invoked directly or as part of the Destroy() method.
We're using an event here so that other scripts can add their own functions to be called when this player is destroyed- e.g: removing one-shot players from a RadioOutput
Definition at line 64 of file RadioTrackPlayer.cs.
Referenced by Destroy().
|
getset |
Event called when the broadcast power for this player is captured for a sample. Broadcast power is the loudness of a track based on the position of the RadioOutput relative to any RadioBroadcaster.
Definition at line 93 of file RadioTrackPlayer.cs.
Referenced by GetSample().
|
getset |
Event called when the player reaches the end of its track naturally, before it takes an action depending on the PlayType (e.g: looping). This is not invoked when the player is stopped or reset.
Definition at line 80 of file RadioTrackPlayer.cs.
Referenced by IncrementSample().
|
getset |
Event called when the gain for this player is captured for a sample. Gain is a direct change to the loudness of a track.
Definition at line 89 of file RadioTrackPlayer.cs.
Referenced by GetSample().
|
getset |
Event called when the insulation for this player is captured for a sample. Insulation is the quietness of a track based on the position of the RadioOutput relative to any RadioInsulator.
Definition at line 95 of file RadioTrackPlayer.cs.
Referenced by GetSample().
|
getset |
Event called when the player's pause state is changed- the bool is true if the player is being paused, false if unpaused.
Definition at line 71 of file RadioTrackPlayer.cs.
|
getset |
Event called when the player starts playing.
Definition at line 67 of file RadioTrackPlayer.cs.
Referenced by IncrementSample().
|
getset |
Event called when this player retreieves a sample from its track.
Definition at line 73 of file RadioTrackPlayer.cs.
Referenced by IncrementSample().
|
getset |
Event called when the player is stopped through Stop()
Definition at line 69 of file RadioTrackPlayer.cs.
Referenced by Stop().
|
getset |
Event called when the tune power for this player is captured for a sample. Tune power is the loudness of a track based on the Tune value of the RadioOutput.
Definition at line 91 of file RadioTrackPlayer.cs.
Referenced by GetSample().
|
getset |
Event called when the volume of this player is captured for a sample. Volume is the product of Tune power, Broadcast power, and Insulation.
Definition at line 87 of file RadioTrackPlayer.cs.
Referenced by GetSample().
|
getset |
Whether or not this player has been paused, temporarily halting playback of the track. Changing this value pauses/unpauses the player.
Definition at line 104 of file RadioTrackPlayer.cs.
Referenced by GetSample(), and IncrementSample().
|
getprivate set |
The type of player this is- what happens when the track ends.
Definition at line 57 of file RadioTrackPlayer.cs.
Referenced by IncrementSample(), and RadioTrackPlayer().
|
getprivate set |
How many samples through the track this player is- not a whole number as we increment it with different values depending on the track's sample rate.
This is stored as a double for greater precision with sample rates- using a float here causes clipping or distortion.
We could use a decimal here, but we're opting to change sample rates of the tracks rather than messing with them here
Definition at line 36 of file RadioTrackPlayer.cs.
Referenced by GetSample(), IncrementSample(), RadioTrackPlayer(), and ResetProgress().
|
get |
How far through the track this player is, from [0 - 1].
Definition at line 41 of file RadioTrackPlayer.cs.
Referenced by IncrementSample().
|
getprivate set |
The track that this player is associated with and plays during runtime.
Definition at line 27 of file RadioTrackPlayer.cs.
Referenced by GetBroadcastPower(), GetInsulation(), GetSample(), IncrementSample(), and RadioTrackPlayer().