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

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< RadioTrackPlayerDoDestroy = 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< RadioTrackPlayerOnPlay = new(_ => { }) [get, set]
 Event called when the player starts playing.
Action< RadioTrackPlayerOnStop = 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< RadioTrackPlayerOnSample = new(_ => { }) [get, set]
 Event called when this player retreieves a sample from its track.
Action< RadioTrackPlayerOnEnd [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.

Detailed Description

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.

Member Enumeration Documentation

◆ PlayerType

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.

Constructor & Destructor Documentation

◆ RadioTrackPlayer()

RyleRadio.Tracks.RadioTrackPlayer.RadioTrackPlayer ( RadioTrackWrapper _trackW,
PlayerType _playerType,
float _baseSampleRate )

Creates a new player for the provided track.

Parameters
_trackWThe track for this player to play
_playerTypeThe type of player this is (what happens when the track ends)
_baseSampleRateThe sample rate of the RadioOutput using this Player

Definition at line 136 of file RadioTrackPlayer.cs.

Member Function Documentation

◆ Destroy()

void RyleRadio.Tracks.RadioTrackPlayer.Destroy ( )

Invokes DoDestroy, destroying the player.

Definition at line 339 of file RadioTrackPlayer.cs.

Referenced by Stop().

◆ GetBroadcastPower()

float RyleRadio.Tracks.RadioTrackPlayer.GetBroadcastPower ( Vector3 _receiverPosition)

Gets the broadcast power of this player using the position of the Output and any any RadioBroadcaster.

Parameters
_receiverPositionThe position of the Output
Returns
The broadcast power- higher the closer the Output is to broadcasters

Definition at line 349 of file RadioTrackPlayer.cs.

Referenced by GetSample().

◆ GetInsulation()

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.

Parameters
_receiverPositionThe position of the Output
Returns
The insulation multiplier- the more insulated the Output is, the lower the multiplier

Definition at line 385 of file RadioTrackPlayer.cs.

Referenced by GetSample().

◆ 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

Parameters
_tuneThe tune value of the Output
_receiverPositionThe position of the Output
_otherVolumeThe sum of the samples of previous tracks, according to the order in RadioData.
See: RadioTrack.attenuation
_outVolumeThe volume of this sample to be added to _otherVolume
_applyVolumeWhether or not Volume (tune power * broadcast power * insulation) should be applied
Returns
The current sample

Definition at line 187 of file RadioTrackPlayer.cs.

Referenced by RyleRadio.Components.RadioOutput.OnAudioFilterRead().

◆ IncrementSample()

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().

◆ ResetProgress()

void RyleRadio.Tracks.RadioTrackPlayer.ResetProgress ( )

Resets the Progress of this player to 0.

Definition at line 331 of file RadioTrackPlayer.cs.

◆ Stop()

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().

◆ UpdateSampleIncrement()

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().

Member Data Documentation

◆ baseSampleRate

float RyleRadio.Tracks.RadioTrackPlayer.baseSampleRate
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().

◆ isStopped

bool RyleRadio.Tracks.RadioTrackPlayer.isStopped = false
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().

◆ sampleIncrement

float RyleRadio.Tracks.RadioTrackPlayer.sampleIncrement
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().

Property Documentation

◆ DoDestroy

Action<RadioTrackPlayer> RyleRadio.Tracks.RadioTrackPlayer.DoDestroy = new(_ => { })
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().

◆ OnBroadcastPower

Action<RadioTrackPlayer, float> RyleRadio.Tracks.RadioTrackPlayer.OnBroadcastPower = new((_, _) => { })
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().

◆ OnEnd

Action<RadioTrackPlayer> RyleRadio.Tracks.RadioTrackPlayer.OnEnd
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().

◆ OnGain

Action<RadioTrackPlayer, float> RyleRadio.Tracks.RadioTrackPlayer.OnGain = new((_, _) => { })
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().

◆ OnInsulation

Action<RadioTrackPlayer, float> RyleRadio.Tracks.RadioTrackPlayer.OnInsulation = new((_, _) => { })
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().

◆ OnPause

Action<RadioTrackPlayer, bool> RyleRadio.Tracks.RadioTrackPlayer.OnPause = new((_, _) => { })
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.

◆ OnPlay

Action<RadioTrackPlayer> RyleRadio.Tracks.RadioTrackPlayer.OnPlay = new(_ => { })
getset

Event called when the player starts playing.

Definition at line 67 of file RadioTrackPlayer.cs.

Referenced by IncrementSample().

◆ OnSample

Action<RadioTrackPlayer> RyleRadio.Tracks.RadioTrackPlayer.OnSample = new(_ => { })
getset

Event called when this player retreieves a sample from its track.

Definition at line 73 of file RadioTrackPlayer.cs.

Referenced by IncrementSample().

◆ OnStop

Action<RadioTrackPlayer> RyleRadio.Tracks.RadioTrackPlayer.OnStop = new(_ => { })
getset

Event called when the player is stopped through Stop()

Definition at line 69 of file RadioTrackPlayer.cs.

Referenced by Stop().

◆ OnTunePower

Action<RadioTrackPlayer, float> RyleRadio.Tracks.RadioTrackPlayer.OnTunePower = new((_, _) => { })
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().

◆ OnVolume

Action<RadioTrackPlayer, float> RyleRadio.Tracks.RadioTrackPlayer.OnVolume = new((_, _) => { })
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().

◆ Paused

bool RyleRadio.Tracks.RadioTrackPlayer.Paused
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().

◆ PlayType

PlayerType RyleRadio.Tracks.RadioTrackPlayer.PlayType
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().

◆ Progress

double RyleRadio.Tracks.RadioTrackPlayer.Progress = 0
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().

◆ ProgressFraction

float RyleRadio.Tracks.RadioTrackPlayer.ProgressFraction
get

How far through the track this player is, from [0 - 1].

Definition at line 41 of file RadioTrackPlayer.cs.

Referenced by IncrementSample().

◆ TrackW

RadioTrackWrapper RyleRadio.Tracks.RadioTrackPlayer.TrackW
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().


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