Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RhythmGameUtilities/Scripts/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ internal static class AudioInternal
public static class Audio
{

/// <summary>
/// Converts samples from an audio file into data used to display a waveform.
/// </summary>
///
/// <param name="samples">Array of sample data from an audio file.</param>
/// <param name="width">Width of the waveform.</param>
/// <param name="height">Height of the waveform.</param>
public static int[][] ConvertSamplesToWaveform(float[] samples, int width, int height)
{
var ptr = AudioInternal.ConvertSamplesToWaveform(samples, samples.Length, width, height);
Expand Down
14 changes: 14 additions & 0 deletions RhythmGameUtilities/Scripts/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ public static class CommonInternal
public static class Common
{

/// <summary>
/// Calculates the linear interpolation between two values.
/// </summary>
///
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="t">The value used for interpolation.</param>
public static float Lerp(float a, float b, float t)
{
return CommonInternal.Lerp(a, b, t);
}

/// <summary>
/// Calculates the fraction, based on a value between two values.
/// </summary>
///
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="v">The value in the middle.</param>
public static float InverseLerp(float a, float b, float v)
{
return CommonInternal.InverseLerp(a, b, v);
Expand Down
32 changes: 32 additions & 0 deletions RhythmGameUtilities/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,47 @@ public static class Utilities

public const float SECONDS_PER_MINUTE = 60.0f;

/// <summary>
/// Convert a tick to a 2D/3D position.
/// </summary>
///
/// <param name="tick">The tick.</param>
/// <param name="resolution">The resolution of the song.</param>
public static float ConvertTickToPosition(float tick, int resolution)
{
return UtilitiesInternal.ConvertTickToPosition(tick, resolution);
}

/// <summary>
/// Convert seconds to ticks.
/// </summary>
///
/// <param name="seconds">The seconds to generate ticks with.</param>
/// <param name="resolution">The resolution of the song.</param>
/// <param name="bpmChanges">All BPM changes within the song.</param>
public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionary<int, int> bpmChanges)
{
return UtilitiesInternal.ConvertSecondsToTicksInternal(seconds, resolution, bpmChanges.Keys.ToArray(),
bpmChanges.Values.ToArray(), bpmChanges.Count);
}

/// <summary>
/// Checks to see if the current time of a game or audio file is on the beat.
/// </summary>
///
/// <param name="bpm">The base BPM for a song.</param>
/// <param name="currentTime">A timestamp to compare to the BPM.</param>
public static bool IsOnTheBeat(float bpm, float currentTime)
{
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime);
}

/// <summary>
/// Rounds a value up the nearest multiplier.
/// </summary>
///
/// <param name="value">The value to round.</param>
/// <param name="multiplier">The multiplier to round using.</param>
public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
{
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
Expand Down Expand Up @@ -146,6 +171,13 @@ public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, i
return null;
}

/// <summary>
/// Calculated the accuracy ratio of the current position against a static position.
/// </summary>
///
/// <param name="position">The position to test against.</param>
/// <param name="currentPosition">The current position.</param>
/// <param name="delta">The plus/minus delta to test the current position against.</param>
public static float CalculateAccuracyRatio(int position, int currentPosition, int delta = 50)
{
return UtilitiesInternal.CalculateAccuracyRatio(position, currentPosition, delta);
Expand Down
7 changes: 7 additions & 0 deletions UnityPackage/Scripts/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ internal static class AudioInternal
public static class Audio
{

/// <summary>
/// Converts samples from an audio file into data used to display a waveform.
/// </summary>
///
/// <param name="samples">Array of sample data from an audio file.</param>
/// <param name="width">Width of the waveform.</param>
/// <param name="height">Height of the waveform.</param>
public static int[][] ConvertSamplesToWaveform(float[] samples, int width, int height)
{
var ptr = AudioInternal.ConvertSamplesToWaveform(samples, samples.Length, width, height);
Expand Down
14 changes: 14 additions & 0 deletions UnityPackage/Scripts/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ public static class CommonInternal
public static class Common
{

/// <summary>
/// Calculates the linear interpolation between two values.
/// </summary>
///
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="t">The value used for interpolation.</param>
public static float Lerp(float a, float b, float t)
{
return CommonInternal.Lerp(a, b, t);
}

/// <summary>
/// Calculates the fraction, based on a value between two values.
/// </summary>
///
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="v">The value in the middle.</param>
public static float InverseLerp(float a, float b, float v)
{
return CommonInternal.InverseLerp(a, b, v);
Expand Down
32 changes: 32 additions & 0 deletions UnityPackage/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,47 @@ public static class Utilities

public const float SECONDS_PER_MINUTE = 60.0f;

/// <summary>
/// Convert a tick to a 2D/3D position.
/// </summary>
///
/// <param name="tick">The tick.</param>
/// <param name="resolution">The resolution of the song.</param>
public static float ConvertTickToPosition(float tick, int resolution)
{
return UtilitiesInternal.ConvertTickToPosition(tick, resolution);
}

/// <summary>
/// Convert seconds to ticks.
/// </summary>
///
/// <param name="seconds">The seconds to generate ticks with.</param>
/// <param name="resolution">The resolution of the song.</param>
/// <param name="bpmChanges">All BPM changes within the song.</param>
public static int ConvertSecondsToTicks(float seconds, int resolution, Dictionary<int, int> bpmChanges)
{
return UtilitiesInternal.ConvertSecondsToTicksInternal(seconds, resolution, bpmChanges.Keys.ToArray(),
bpmChanges.Values.ToArray(), bpmChanges.Count);
}

/// <summary>
/// Checks to see if the current time of a game or audio file is on the beat.
/// </summary>
///
/// <param name="bpm">The base BPM for a song.</param>
/// <param name="currentTime">A timestamp to compare to the BPM.</param>
public static bool IsOnTheBeat(float bpm, float currentTime)
{
return UtilitiesInternal.IsOnTheBeat(bpm, currentTime);
}

/// <summary>
/// Rounds a value up the nearest multiplier.
/// </summary>
///
/// <param name="value">The value to round.</param>
/// <param name="multiplier">The multiplier to round using.</param>
public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
{
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
Expand Down Expand Up @@ -146,6 +171,13 @@ public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, i
return null;
}

/// <summary>
/// Calculated the accuracy ratio of the current position against a static position.
/// </summary>
///
/// <param name="position">The position to test against.</param>
/// <param name="currentPosition">The current position.</param>
/// <param name="delta">The plus/minus delta to test the current position against.</param>
public static float CalculateAccuracyRatio(int position, int currentPosition, int delta = 50)
{
return UtilitiesInternal.CalculateAccuracyRatio(position, currentPosition, delta);
Expand Down