fixed audio sync issues

This commit is contained in:
Dom Harris 2021-01-07 10:05:19 +00:00
parent eb7826c7c7
commit 3df705dfe5
8 changed files with 83 additions and 24 deletions

View File

@ -73,7 +73,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Path: Assets/FMOD/Desktop/Master.bank Path: Assets/FMOD/Desktop/Master.bank
Name: Master Name: Master
lastModified: 637455820886389038 lastModified: 637456045920000000
LoadResult: 0 LoadResult: 0
FileSizes: [] FileSizes: []
Exists: 1 Exists: 1
@ -122,7 +122,7 @@ MonoBehaviour:
- {fileID: -4840949124066270359} - {fileID: -4840949124066270359}
StringsBanks: StringsBanks:
- {fileID: 2930724805879487167} - {fileID: 2930724805879487167}
stringsBankWriteTime: 637455820886398947 stringsBankWriteTime: 637456045920000000
cacheVersion: 4 cacheVersion: 4
--- !u!114 &2930724805879487167 --- !u!114 &2930724805879487167
MonoBehaviour: MonoBehaviour:
@ -138,7 +138,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Path: Assets/FMOD/Desktop/Master.strings.bank Path: Assets/FMOD/Desktop/Master.strings.bank
Name: Master.strings Name: Master.strings
lastModified: 637455820886398947 lastModified: 637456045920000000
LoadResult: 0 LoadResult: 0
FileSizes: FileSizes:
- Name: - Name:

View File

@ -135,6 +135,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 331122d8907f44ed9b0f8f2337d176b9, type: 3} m_Script: {fileID: 11500000, guid: 331122d8907f44ed9b0f8f2337d176b9, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
beatsBeforeMove: 160 beatsBeforeMove: 16
scaleAmount: 1.5 scaleAmount: 1.5
numBeatsAfterScale: 0 numBeatsAfterScale: 0

View File

@ -243,9 +243,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4f8399031f014bee928b07d26fe8ee4c, type: 3} m_Script: {fileID: 11500000, guid: 4f8399031f014bee928b07d26fe8ee4c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
pauseOnBeat: 160 pauseOnBeat: 16
pauseLengthInBeats: 72 pauseLengthInBeats: 8
beatOffset: 16 beatOffset: 2
--- !u!20 &502054319 stripped --- !u!20 &502054319 stripped
Camera: Camera:
m_CorrespondingSourceObject: {fileID: 3397488660173986648, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} m_CorrespondingSourceObject: {fileID: 3397488660173986648, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
@ -527,7 +527,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} - target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
propertyPath: m_LocalScale.x propertyPath: m_LocalScale.x
value: 2085.424 value: 1847.5209
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3} - target: {fileID: 3397488660842926093, guid: 1f82f952c53fc7449a0091cf29ba3def, type: 3}
propertyPath: m_LocalScale.y propertyPath: m_LocalScale.y
@ -774,9 +774,9 @@ MonoBehaviour:
m_StringArgument: m_StringArgument:
m_BoolArgument: 0 m_BoolArgument: 0
m_CallState: 2 m_CallState: 2
shootOnBeat: 160 shootOnBeat: 16
noTargetLengthInBeats: 72 noTargetLengthInBeats: 8
beatOffset: 16 beatOffset: 2
--- !u!1 &1215971662 --- !u!1 &1215971662
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,32 +1,51 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using DG.Tweening;
using FMOD;
using FMODUnity;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using Debug = UnityEngine.Debug;
public class AudioBeatManager : MonoBehaviour, IAudioBeatManager public class AudioBeatManager : MonoBehaviour, IAudioBeatManager
{ {
[SerializeField] private float bpm; [SerializeField] private float bpm;
public float TimeBetweenBeats => _bps * Time.deltaTime; public float TimeBetweenBeats => _secPerBeat;
private float _bps; private float _bps;
private int _currentBeat = 0; private int _currentBeat = 0;
private float _timer; private float _timer;
private float _secPerBeat;
[SerializeField] [FormerlySerializedAs("OnBeat")] [SerializeField] [FormerlySerializedAs("OnBeat")]
private IntEvent _onBeat; private IntEvent _onBeat;
public IntEvent OnBeat => _onBeat; public IntEvent OnBeat => _onBeat;
public event Action<int> OnBeatEvent; public event Action<int> OnBeatEvent;
private ChannelGroup _channelGroup;
private ulong _dspClock;
private int _sampleRate;
private float _initialPower;
public float DspTime => _dspClock / (float)_sampleRate;
private void Awake() private void Awake()
{ {
_bps = bpm / 60f; _bps = bpm / 60f;
_secPerBeat = 60f / bpm;
_timer = 0; _timer = 0;
RuntimeManager.CoreSystem.getMasterChannelGroup(out _channelGroup);
RuntimeManager.CoreSystem.getSoftwareFormat(out _sampleRate, out _, out _);
DOTween.SetTweensCapacity(2000,100);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
_channelGroup.getDSPClock(out _dspClock, out _);
_timer += Time.deltaTime; _timer += Time.deltaTime;
if (_timer >= TimeBetweenBeats) if (_timer >= TimeBetweenBeats)
{ {

View File

@ -32,8 +32,8 @@ public class DisableOnDeath : MonoBehaviour
var oldName = gameObject.name; var oldName = gameObject.name;
gameObject.name = "disabled"; gameObject.name = "disabled";
_renderer.material.DOColor(Color.white, 0.1f); _renderer.material.DOColor(Color.white, 0.1f);
_renderer.material.DOFade(0, 0.2f).SetDelay(0.3f); _renderer.material.DOFade(0, 0.1f).SetDelay(0.2f);
transform.DOScale(Vector3.one * 1.5f, 0.5f).SetEase(Ease.OutQuint).OnComplete(() => transform.DOScale(Vector3.one * 1.5f, 0.3f).SetEase(Ease.OutQuint).OnComplete(() =>
{ {
gameObject.name = oldName; gameObject.name = oldName;
gameObject.SetActive(false); gameObject.SetActive(false);

View File

@ -1,9 +1,7 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using DG.Tweening; using DG.Tweening;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random; using Utils;
public class MoveAfterDelay : MonoBehaviour public class MoveAfterDelay : MonoBehaviour
{ {
@ -33,10 +31,50 @@ public class MoveAfterDelay : MonoBehaviour
{ {
if (beat % beatsBeforeMove != 0) return; if (beat % beatsBeforeMove != 0) return;
DOTween.Sequence() var pos = transform.localPosition;
.Append(transform.DOScale(Vector3.one * scaleAmount, _audio.TimeBetweenBeats*16).SetEase(Ease.InQuint)) pos.z = 0;
.Append(transform.DOScale(Vector3.one, _audio.TimeBetweenBeats*16).SetEase(Ease.OutQuint)) var dir = pos.normalized;
.Append(transform.DOMoveZ(-30, 1.0f).SetEase(Ease.InOutQuint).SetDelay(_audio.TimeBetweenBeats * numBeatsAfterScale)) pos = transform.localPosition;
.Play();
DoAnim(pos, dir).Run();
}
private IEnumerator DoAnim(Vector3 pos, Vector3 dir)
{
var keepGoing = true;
var startTime = _audio.DspTime;
var targetDSPTime = _audio.TimeBetweenBeats * .25f;
while (keepGoing)
{
var currentDSPTime = _audio.DspTime - startTime;
var t = currentDSPTime / targetDSPTime;
transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * scaleAmount, 1 - Mathf.Pow(1 - t, 5));
transform.localPosition = Vector3.Lerp(pos, pos + dir * 4, t);
if (currentDSPTime >= targetDSPTime)
keepGoing = false;
yield return null;
}
startTime = _audio.DspTime;
keepGoing = true;
targetDSPTime = _audio.TimeBetweenBeats * .25f;
while (keepGoing)
{
var currentDSPTime = _audio.DspTime - startTime;
var t = currentDSPTime / targetDSPTime;
transform.localScale = Vector3.Lerp(Vector3.one* scaleAmount, Vector3.one, t*t*t*t*t);
transform.localPosition = Vector3.Lerp(pos + dir * 4, pos, t);
if (currentDSPTime >= targetDSPTime)
keepGoing = false;
yield return null;
}
yield return new WaitForSeconds(_audio.TimeBetweenBeats);
transform.DOMoveZ(-30, _audio.TimeBetweenBeats * 2).SetEase(Ease.OutQuint);
} }
} }

View File

@ -106,7 +106,7 @@ MonoBehaviour:
m_Bits: 64 m_Bits: 64
accuracy: 0 accuracy: 0
zone: zone:
numToSpawn: 1 numToSpawn: 10
offset: {x: 0, y: 0} offset: {x: 0, y: 0}
spawnType: 0 spawnType: 0
spawnDir: 0 spawnDir: 0

View File

@ -128,7 +128,9 @@ PlayerSettings:
16:9: 1 16:9: 1
Others: 1 Others: 1
bundleVersion: 0.1 bundleVersion: 0.1
preloadedAssets: [] preloadedAssets:
- {fileID: 0}
- {fileID: 0}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1