10000 Support single channel ogg/vorbis by omccully · Pull Request #10 · gopxl/beep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Support single channel ogg/vorbis #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023
Merged
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
26 changes: 18 additions & 8 deletions vorbis/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
)

const (
govorbisNumChannels = 2
govorbisPrecision = 2
govorbisPrecision = 2
)

// Decode takes a ReadCloser containing audio data in ogg/vorbis format and returns a StreamSeekCloser,
Expand All @@ -31,7 +30,7 @@ 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
Expand All @@ -50,11 +49,22 @@ func (d *decoder) Stream(samples [][2]float64) (n int, ok bool) {
}
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])
n++
ok = true
var err error
var dn int
if d.d.Channels() == 1 {
dn, err = d.d.Read(tmp[:1])
if dn == 1 {
samples[i][0], samples[i][1] = float64(tmp[0]), float64(tmp[0])
n++
ok = true
}
} else {
dn, err = d.d.Read(tmp[:])
if dn == 2 {
samples[i][0], samples[i][1] = float64(tmp[0]), float64(tmp[1])
n++
ok = true
}
}
if err == io.EOF {
break
Expand Down
0