faiface / beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
MIT License
2.08k stars 152 forks source link

Error in mp3.Seeker implementation #39

Closed Hundemeier closed 6 years ago

Hundemeier commented 6 years ago

The Seeker implementation of the mp3 decoder is not fully correct. The Position() method returns incorrect values after seeking.

f, err := os.Open("./test.mp3")
if err != nil {
    log.Fatal(err)
}
s, format, err := mp3.Decode(f)
if err != nil {
    log.Fatal(err)
}
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
speaker.Play(s)
fmt.Println("Position:", s.Position())
time.Sleep(3 * time.Second)
s.Seek(0)
fmt.Println("Position:", s.Position())
select {}

The above example works fine with the wav-decoder.

Expected output:

Position: 0
Position: 0

Real output (with my mp3 testfile):

Position: 0
Position: 145530

A quick fix would be to add the following line to

mp3/decode.go -> Seek()

d.pos = int64(p)*gomp3BytesPerFrame

But I do not know if this has sideffects with the go-mp3 library.

faiface commented 6 years ago

Yes, you're very much right! The fix you proposed is correct. Do you want to submit a PR for the fix?

faiface commented 6 years ago

Fixed by #40