remove more files
This commit is contained in:
parent
5ad54b348c
commit
88ed365629
|
@ -1,140 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio
|
||||
{
|
||||
public class AudioDspTimeKeeper : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<double> xValuesL = new List<double>();
|
||||
[SerializeField] private List<double> yValuesL = new List<double>();
|
||||
|
||||
private double coeff1, coeff2;
|
||||
|
||||
private double audioDspStartTime;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
public double currentSmoothedDSPTime;
|
||||
|
||||
public double dspTime;
|
||||
public float audioTime;
|
||||
|
||||
private double musicDrift;
|
||||
|
||||
private Conductor conductor;
|
||||
|
||||
public float latencyAdjustment;
|
||||
|
||||
public void Play()
|
||||
{
|
||||
audioSource.PlayScheduled(audioDspStartTime);
|
||||
audioDspStartTime = AudioSettings.dspTime;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
conductor = GetComponent<Conductor>();
|
||||
audioSource = conductor.musicSource;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!audioSource.isPlaying) return;
|
||||
|
||||
float currentGameTime = Time.realtimeSinceStartup;
|
||||
double currentDspTime = AudioSettings.dspTime;
|
||||
|
||||
// Update our linear regression model by adding another data point.
|
||||
UpdateLinearRegression(currentGameTime, currentDspTime);
|
||||
CheckForDrift();
|
||||
|
||||
dspTime = GetCurrentTimeInSong();
|
||||
audioTime = audioSource.time;
|
||||
}
|
||||
|
||||
public double SmoothedDSPTime()
|
||||
{
|
||||
double result = Time.unscaledTimeAsDouble * coeff1 + coeff2;
|
||||
if (result > currentSmoothedDSPTime)
|
||||
{
|
||||
currentSmoothedDSPTime = result;
|
||||
}
|
||||
return currentSmoothedDSPTime;
|
||||
}
|
||||
|
||||
public double GetCurrentTimeInSong()
|
||||
{
|
||||
return this.SmoothedDSPTime() - audioDspStartTime - latencyAdjustment;
|
||||
}
|
||||
|
||||
private void CheckForDrift()
|
||||
{
|
||||
double timeFromDSP = this.SmoothedDSPTime() - audioDspStartTime;
|
||||
double timeFromAudioSource = audioSource.timeSamples / (float)audioSource.clip.frequency;
|
||||
|
||||
double drift = timeFromDSP - timeFromAudioSource;
|
||||
musicDrift = drift;
|
||||
|
||||
if (Mathf.Abs((float)drift) > 0.05)
|
||||
{
|
||||
Debug.LogWarningFormat("Music drift of {0} detected, resyncing!", musicDrift);
|
||||
audioDspStartTime += musicDrift;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLinearRegression(float currentGameTime, double currentDspTime)
|
||||
{
|
||||
if (xValuesL.Count > 3000)
|
||||
{
|
||||
xValuesL.RemoveRange(0, 2000);
|
||||
yValuesL.RemoveRange(0, 2000);
|
||||
}
|
||||
|
||||
xValuesL.Add((double)currentGameTime);
|
||||
var xVals = xValuesL.ToArray();
|
||||
|
||||
yValuesL.Add((double)currentDspTime);
|
||||
var yVals = yValuesL.ToArray();
|
||||
|
||||
if (xVals.Length != yVals.Length)
|
||||
{
|
||||
throw new Exception("Input values should be with the same length.");
|
||||
}
|
||||
|
||||
double sumOfX = 0;
|
||||
double sumOfY = 0;
|
||||
double sumOfXSq = 0;
|
||||
double sumOfYSq = 0;
|
||||
double sumCodeviates = 0;
|
||||
|
||||
for (var i = 0; i < xVals.Length; i++)
|
||||
{
|
||||
var x = xVals[i];
|
||||
var y = yVals[i];
|
||||
sumCodeviates += x * y;
|
||||
sumOfX += x;
|
||||
sumOfY += y;
|
||||
sumOfXSq += x * x;
|
||||
sumOfYSq += y * y;
|
||||
}
|
||||
|
||||
var count = xVals.Length;
|
||||
var ssX = sumOfXSq - ((sumOfX * sumOfX) / count);
|
||||
var ssY = sumOfYSq - ((sumOfY * sumOfY) / count);
|
||||
|
||||
var rNumerator = (count * sumCodeviates) - (sumOfX * sumOfY);
|
||||
var rDenom = (count * sumOfXSq - (sumOfX * sumOfX)) * (count * sumOfYSq - (sumOfY * sumOfY));
|
||||
var sCo = sumCodeviates - ((sumOfX * sumOfY) / count);
|
||||
|
||||
var meanX = sumOfX / count;
|
||||
var meanY = sumOfY / count;
|
||||
var dblR = rNumerator / Math.Sqrt(rDenom);
|
||||
|
||||
// coeff1 = dblR * dblR;
|
||||
coeff2 = meanY - ((sCo / ssX) * meanX);
|
||||
coeff1 = sCo / ssX;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2e012d929a258243a865112df346c34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,12 +0,0 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Util
|
||||
{
|
||||
public class Audio
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ecc1c133593e69141b1824b99aace736
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,21 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
// this is a script for testing
|
||||
|
||||
using HeavenStudio.Editor;
|
||||
|
||||
namespace HeavenStudio.Tests
|
||||
{
|
||||
public class WTF : MonoBehaviour
|
||||
{
|
||||
public GameObject test;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Z))
|
||||
{
|
||||
GetComponent<CommandManager>().Execute(new TestCommand(test, new Vector3(Random.Range(-8f, 8f), Random.Range(-6f, 6f))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 490e729f742a40644a3a2abd88fce1a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue