Skip to content

Commit

Permalink
Merge pull request #28 from SineStriker/master
Browse files Browse the repository at this point in the history
SDL: Use last sample position as current position
  • Loading branch information
LiuYunPlayer authored Jun 7, 2024
2 parents fcf2d3f + 318a1e2 commit b7d9190
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions TuneLab/Audio/SDL2/SDLAudioEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -60,7 +60,6 @@ public void Init(IAudioProcessor processor)
{
context.Post(_ =>
{
_realPosition += val / 2;
if (IsPlaying)
{
ProgressChanged?.Invoke();
Expand Down Expand Up @@ -130,7 +129,7 @@ public void Pause()
public void Seek(double time)
{
_position = (int)(time * SamplingRate);
_realPosition = _position;
_lastPosition = _position;
}

// 获取所有音频设备
Expand Down Expand Up @@ -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;
Expand All @@ -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++)
Expand Down

0 comments on commit b7d9190

Please sign in to comment.