From 318a1e21c2bdca75b64d69093ee091ded0083b8c Mon Sep 17 00:00:00 2001 From: Sine Striker Date: Fri, 7 Jun 2024 20:50:52 +0800 Subject: [PATCH] SDL: Use last sample position as current position --- TuneLab/Audio/SDL2/SDLAudioEngine.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TuneLab/Audio/SDL2/SDLAudioEngine.cs b/TuneLab/Audio/SDL2/SDLAudioEngine.cs index 280f535..668b2c9 100644 --- a/TuneLab/Audio/SDL2/SDLAudioEngine.cs +++ b/TuneLab/Audio/SDL2/SDLAudioEngine.cs @@ -17,7 +17,7 @@ internal class SDLAudioEngine : IAudioEngine public int SamplingRate => 44100; - public double CurrentTime => (double)_realPosition / SamplingRate; + public double CurrentTime => (double)_lastPosition / SamplingRate; public void Init(IAudioProcessor processor) { @@ -60,7 +60,6 @@ public void Init(IAudioProcessor processor) { context.Post(_ => { - _realPosition += val / 2; if (IsPlaying) { ProgressChanged?.Invoke(); @@ -130,7 +129,7 @@ public void Pause() public void Seek(double time) { _position = (int)(time * SamplingRate); - _realPosition = _position; + _lastPosition = _position; } // 获取所有音频设备 @@ -202,7 +201,7 @@ public void SwitchDriver(string driver) // 成员变量 private IAudioProcessor? _audioProcessor; private int _position = 0; - private int _realPosition = 0; + private int _lastPosition = 0; // SDL 相关 private SDLPlaybackData _d; @@ -216,6 +215,7 @@ public int Read(float[] buffer, int offset, int count) int position = engine._position; int length = count / 2; + engine._lastPosition = position; engine._position += length; for (int i = offset; i < offset + count; i++)