Skip to content

Commit

Permalink
Add Toggle in Setting for Audio Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
yojohanshinwataikei committed Nov 10, 2023
1 parent c3ff0e2 commit 1238fb9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Assets/Materials/Player/TrackBorderLeft.mat
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Phase: 0
- _Phase: 0.26213914
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/Materials/Player/TrackBorderRight.mat
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Phase: 0
- _Phase: 0.26213914
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/Materials/Player/TrackMain.mat
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Phase: 0
- _Phase: 0.26213914
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/Misc/BuildTimestamp.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
638313647123095071
638331370734876546
10 changes: 10 additions & 0 deletions Assets/Scripts/Compose/ArcadeComposeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ArcadePreference
public int TargetFrameRate = -1;
public int Velocity = 30;
public uint UndoBufferSize = 200;
public bool PlaybackSync = false;
public bool Auto;
public Arcade.Gameplay.Chart.ChartSortMode ChartSortMode;
}
Expand Down Expand Up @@ -122,6 +123,7 @@ public long BuildTimestamp
public Toggle FullscreenToggle;
public Dropdown TargetFramerateDropdown;
public InputField UndoBufferSizeInput;
public Toggle PlaybackSyncToggle;

public TextAsset ChangeLog;
public TextAsset BuildTimestampText;
Expand Down Expand Up @@ -164,6 +166,12 @@ private void Start()
SavePreferences();
});
UndoBufferSizeInput.onEndEdit.AddListener(SetUndoBufferSize);
PlaybackSyncToggle.onValueChanged.AddListener((bool value) =>
{
ArcadePreference.PlaybackSync = value;
ArcGameplayManager.Instance.EnablePlaybackSync = value;
SavePreferences();
});
LoadPreferences();
SavePreferences();
Pause();
Expand Down Expand Up @@ -528,6 +536,8 @@ public void LoadPreferences()
ArcadePreference.TargetFrameRate = -1;
}
SetTargetFramerate(ArcadePreference.TargetFrameRate);
PlaybackSyncToggle.SetIsOnWithoutNotify(ArcadePreference.PlaybackSync);
ArcGameplayManager.Instance.EnablePlaybackSync = ArcadePreference.PlaybackSync;
}
}
public void SavePreferences()
Expand Down
25 changes: 15 additions & 10 deletions Assets/Scripts/Gameplay/ArcGameplayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public float TimingPointDensityFactor
}
}

public bool EnablePlaybackSync = false;

private double lastDspTime = 0;
private double deltaDspTime = 0;

Expand All @@ -76,17 +78,20 @@ private void Update()
{
float playBackSpeed = ArcAudioManager.Instance.PlayBackSpeed;
timing += Time.deltaTime * playBackSpeed;
float t = ArcAudioManager.Instance.Timing;
if (deltaDspTime > 0f && (timing >= 0 || ArcAudioManager.Instance.Timing > 0))
{
float delta = timing - t;
int bufferLength;
int numBuffers;
AudioSettings.GetDSPBufferSize(out bufferLength, out numBuffers);
float maxDelta = 2 * (float)bufferLength / (float)AudioSettings.outputSampleRate;
if (Mathf.Abs(delta) > maxDelta)
Debug.Log(EnablePlaybackSync);
if(EnablePlaybackSync){
float t = ArcAudioManager.Instance.Timing;
if (deltaDspTime > 0f && (timing >= 0 || ArcAudioManager.Instance.Timing > 0))
{
timing = t;
float delta = timing - t;
int bufferLength;
int numBuffers;
AudioSettings.GetDSPBufferSize(out bufferLength, out numBuffers);
float maxDelta = 2 * (float)bufferLength / (float)AudioSettings.outputSampleRate;
if (Mathf.Abs(delta) > maxDelta)
{
timing = t;
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions Assets/_Scenes/ArcEditor.unity
Original file line number Diff line number Diff line change
Expand Up @@ -34514,6 +34514,7 @@ MonoBehaviour:
OnChartLoad:
m_PersistentCalls:
m_Calls: []
EnablePlaybackSync: 0
--- !u!1 &909681750
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -81190,10 +81191,10 @@ RectTransform:
m_Children: []
m_Father: {fileID: 1707394408}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 400.5, y: -72.258064}
m_SizeDelta: {x: 705, y: 40.258064}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &2105888210
MonoBehaviour:
Expand Down

0 comments on commit 1238fb9

Please sign in to comment.