Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions vorbis/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

const (
govorbisNumChannels = 2
govorbisPrecision = 2
)

Expand All @@ -31,28 +30,29 @@ func Decode(rc io.ReadCloser) (s beep.StreamSeekCloser, format beep.Format, err
}
format = beep.Format{
SampleRate: beep.SampleRate(d.SampleRate()),
NumChannels: govorbisNumChannels,
NumChannels: d.Channels(),
Precision: govorbisPrecision,
}
return &decoder{rc, d, format, nil}, format, nil
buffer := make([]float32, d.Channels())
return &decoder{rc, d, format, buffer, nil}, format, nil
}

type decoder struct {
closer io.Closer
d *oggvorbis.Reader
f beep.Format
buf []float32
err error
}

func (d *decoder) Stream(samples [][2]float64) (n int, ok bool) {
if d.err != nil {
return 0, false
}
var tmp [2]float32
for i := range samples {
dn, err := d.d.Read(tmp[:])
if dn == 2 {
samples[i][0], samples[i][1] = float64(tmp[0]), float64(tmp[1])
dn, err := d.d.Read(d.buf[:])
if dn == d.f.NumChannels {
samples[i][0], samples[i][1] = float64(d.buf[0]), float64(d.buf[len(d.buf) - 1])
n++
ok = true
}
Expand Down