Skip to content
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

Major output and vorbis improvements #1

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version: '1.20'

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
run: sudo apt-get update && sudo apt-get install -y libasound2-dev libvorbis-dev libogg-dev

- name: Build daemon
run: go build -v ./cmd/daemon
Expand Down
15 changes: 8 additions & 7 deletions cmd/daemon/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,12 @@ func (s *Session) loadCurrentTrack() error {
},
})

stream, err := s.player.NewStream(trackId, s.app.cfg.Bitrate)
stream, err := s.player.NewStream(trackId, s.app.cfg.Bitrate, trackPosition)
if err != nil {
return fmt.Errorf("failed creating stream: %w", err)
}

log.Debugf("seek track to %dms", trackPosition)
if err := stream.SeekMs(trackPosition); err != nil {
return fmt.Errorf("failed seeking track: %w", err)
}
log.Infof("loaded track \"%s\" (position: %dms, duration: %dms)", *stream.Track.Name, trackPosition, *stream.Track.Duration)

s.updateState(func(s *State) {
s.playerState.Duration = int64(*stream.Track.Duration)
Expand All @@ -216,10 +213,10 @@ func (s *Session) play() error {
return fmt.Errorf("no stream")
}

log.Debug("resume track")
s.stream.Play()

streamPos := s.stream.PositionMs()
log.Debugf("resume track at %dms", streamPos)

s.updateState(func(s *State) {
s.playerState.Timestamp = time.Now().UnixMilli()
Expand All @@ -234,10 +231,10 @@ func (s *Session) pause() error {
return fmt.Errorf("no stream")
}

log.Debug("pause track")
s.stream.Pause()

streamPos := s.stream.PositionMs()
log.Debugf("pause track at %dms", streamPos)

s.updateState(func(s *State) {
s.playerState.Timestamp = time.Now().UnixMilli()
Expand Down Expand Up @@ -280,6 +277,10 @@ func (s *Session) seek(position int64) error {
}

func (s *Session) skipPrev() error {
if s.stream.PositionMs() > 3000 {
return s.seek(0)
}

var paused bool
s.withState(func(s *State) {
paused = s.playerState.IsPaused
Expand Down
1 change: 0 additions & 1 deletion cmd/daemon/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func (s *Session) handlePlayerCommand(req dealer.RequestPayload) error {

return nil
case "skip_prev":
// TODO: handle rewinding track if pos < 3000ms
return s.skipPrev()
case "skip_next":
return s.skipNext()
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/devgianlu/shannon v0.0.0-20230613115856-82ec90b7fa7e
github.com/grandcat/zeroconf v1.0.0
github.com/hajimehoshi/oto/v2 v2.4.0
github.com/jfreymuth/oggvorbis v1.0.5
github.com/sirupsen/logrus v1.9.3
github.com/xlab/vorbis-go v0.0.0-20210911202351-b5b85f1ec645
golang.org/x/crypto v0.10.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
google.golang.org/protobuf v1.30.0
Expand All @@ -18,14 +17,10 @@ require (

require (
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/ebitengine/purego v0.4.0-alpha.5 // indirect
github.com/jfreymuth/vorbis v1.0.2 // indirect
github.com/klauspost/compress v1.10.3 // indirect
github.com/miekg/dns v1.1.54 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/tools v0.10.0 // indirect
)

replace github.com/hajimehoshi/oto/v2 v2.4.0 => github.com/devgianlu/oto/v2 v2.0.0-20230905080002-01f543acf2b9
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devgianlu/oto/v2 v2.0.0-20230905080002-01f543acf2b9 h1:gRg5jfSLzb4xZpmm9dWSzS/4RsCPkitljfq/dH7QKho=
github.com/devgianlu/oto/v2 v2.0.0-20230905080002-01f543acf2b9/go.mod h1:XoAqcfGced8SVzCvx7DO2YA69Zpr1NiHNhnxJawxaZ0=
github.com/devgianlu/shannon v0.0.0-20230613115856-82ec90b7fa7e h1:OoETp+L//8ZDtd5BWKaogHQjgA104yF4a2yqjfaG3mE=
github.com/devgianlu/shannon v0.0.0-20230613115856-82ec90b7fa7e/go.mod h1:m5DMFz6BcaKJwxxPaSh9MxwPzK2GPSt1KRFC8Imf0ik=
github.com/ebitengine/purego v0.4.0-alpha.5 h1:1jd+ClW6gD2x2F/+j4lCGc3TQMWL3hNYgLu/xF9Jz0g=
github.com/ebitengine/purego v0.4.0-alpha.5/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
Expand Down Expand Up @@ -74,6 +70,8 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/xlab/vorbis-go v0.0.0-20210911202351-b5b85f1ec645 h1:lYg/+vV/Fd5WM1+Ptg54Am3y4mDXaMSrT+mKUHV5uVc=
github.com/xlab/vorbis-go v0.0.0-20210911202351-b5b85f1ec645/go.mod h1:AMqfx3jFwPqem3u8mF2lsRodZs30jG/Mag5HZ3mB3sA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
Expand Down
16 changes: 16 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package go_librespot

type Float32Reader interface {
Read([]float32) (n int, err error)
}

type AudioSource interface {
// SetPositionMs sets the new position in samples
SetPositionMs(int64) error

// PositionMs gets the position in samples
PositionMs() int64

// Read reads 32bit little endian floats from the stream
Read([]float32) (int, error)
}
Loading