From 90f59aad7c0e4ae7aec9f00d8e4466def38ba779 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 29 Nov 2021 20:56:39 +0900 Subject: [PATCH] audio: Refactoring: Use the underlying source's Seek in Read (reland) --- audio/loop.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/audio/loop.go b/audio/loop.go index db1a060fa..c6e7b52e2 100644 --- a/audio/loop.go +++ b/audio/loop.go @@ -83,11 +83,12 @@ func (i *InfiniteLoop) Read(b []byte) (int, error) { } if err == io.EOF || i.pos == i.length() { - pos, err := i.Seek(i.lstart, io.SeekStart) - if err != nil { + // Ignore the new position returned by Seek since the source position might not be match with the position + // managed by this. + if _, err := i.src.Seek(i.lstart, io.SeekStart); err != nil { return 0, err } - i.pos = pos + i.pos = i.lstart } return n, nil } @@ -110,7 +111,7 @@ func (i *InfiniteLoop) Seek(offset int64, whence int) (int64, error) { if next < 0 { return 0, fmt.Errorf("audio: position must >= 0") } - if next >= i.lstart { + if next > i.lstart { next = ((next - i.lstart) % i.llength) + i.lstart } // Ignore the new position returned by Seek since the source position might not be match with the position