Created
January 31, 2021 07:10
-
-
Save NoodleSushi/8ddc9f0de1afe04790d661ee0b3c46e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Godot; | |
using System; | |
public static class Rhythmer | |
{ | |
static double ASPTimeSec(AudioStreamPlayer ASP) | |
{ | |
return ASP.GetPlaybackPosition() + GetPlayLatency(); | |
} | |
static double ASPTimeSec(AudioStreamPlayer ASP, bool isScaled = false) | |
{ | |
return ASPTimeSec(ASP) / (isScaled ? ASP.PitchScale : 1); | |
} | |
static double Beat2Sec(double beat, double bpm) | |
{ | |
return beat * 60 / bpm; | |
} | |
static double Beat2Sec(double beat, double bpm, float timeScale = 1) | |
{ | |
return beat * 60 / bpm * timeScale; | |
} | |
static double Sec2Beat(double sec, double bpm) | |
{ | |
return sec * bpm / 60; | |
} | |
static double Sec2Beat(double sec, double bpm, float timeScale = 1) | |
{ | |
return sec * bpm / 60 * timeScale; | |
} | |
static double GetPlayLatency() | |
{ | |
return AudioServer.GetTimeSinceLastMix() - AudioServer.GetOutputLatency(); | |
} | |
static double GetOffsetTimeSec(double playbackTimeSec, double missionTimeSec, | |
AudioStreamPlayer ASPMusic, AudioStreamPlayer ASPSlave) | |
{ | |
return ((missionTimeSec - playbackTimeSec - AudioServer.GetOutputLatency()) | |
* ASPSlave.PitchScale | |
+ AudioServer.GetTimeSinceLastMix()) / ASPMusic.PitchScale; | |
} | |
static double GetOffsetTimeSec(double playbackTimeSec, double missionTimeSec, | |
float musicPitchScale, float slavePitchScale) | |
{ | |
return ((missionTimeSec - playbackTimeSec - AudioServer.GetOutputLatency()) | |
* slavePitchScale | |
+ AudioServer.GetTimeSinceLastMix()) / musicPitchScale; | |
} | |
static double GetOffsetTimeSec(double playbackTimeSec, double missionTimeSec) | |
{ | |
return missionTimeSec - playbackTimeSec + GetPlayLatency(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment