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

chore(examples): update all examples to use Loop2 instead of deprecated Loop method #201

Merged
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
16 changes: 12 additions & 4 deletions examples/speedy-player/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ type audioPanel struct {
volume *effects.Volume
}

func newAudioPanel(sampleRate beep.SampleRate, streamer beep.StreamSeeker) *audioPanel {
ctrl := &beep.Ctrl{Streamer: beep.Loop(-1, streamer)}
func newAudioPanel(sampleRate beep.SampleRate, streamer beep.StreamSeeker) (*audioPanel, error) {
loopStreamer, err := beep.Loop2(streamer)
if err != nil {
return nil, err
}

ctrl := &beep.Ctrl{Streamer: loopStreamer}
resampler := beep.ResampleRatio(4, 1, ctrl)
volume := &effects.Volume{Streamer: resampler, Base: 2}
return &audioPanel{sampleRate, streamer, ctrl, resampler, volume}
return &audioPanel{sampleRate, streamer, ctrl, resampler, volume}, nil
}

func (ap *audioPanel) play() {
Expand Down Expand Up @@ -172,7 +177,10 @@ func main() {
}
defer screen.Fini()

ap := newAudioPanel(format.SampleRate, streamer)
ap, err := newAudioPanel(format.SampleRate, streamer)
if err != nil {
report(err)
}

screen.Clear()
ap.draw(screen)
Expand Down
7 changes: 5 additions & 2 deletions examples/tutorial/2-composing-and-controlling/b/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ func main() {

speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))

loop := beep.Loop(3, streamer)
fast := beep.ResampleRatio(4, 5, loop)
loopStreamer, err := beep.Loop2(streamer, beep.LoopTimes(2))
if err != nil {
log.Fatal(err)
}
fast := beep.ResampleRatio(4, 5, loopStreamer)

done := make(chan bool)
speaker.Play(beep.Seq(fast, beep.Callback(func() {
Expand Down
7 changes: 6 additions & 1 deletion examples/tutorial/2-composing-and-controlling/c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ func main() {

speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))

ctrl := &beep.Ctrl{Streamer: beep.Loop(-1, streamer), Paused: false}
loopStreamer, err := beep.Loop2(streamer)
if err != nil {
log.Fatal(err)
}

ctrl := &beep.Ctrl{Streamer: loopStreamer, Paused: false}
speaker.Play(ctrl)

for {
Expand Down
6 changes: 5 additions & 1 deletion examples/tutorial/2-composing-and-controlling/d/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ func main() {
defer streamer.Close()

speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
loopStreamer, err := beep.Loop2(streamer)
if err != nil {
log.Fatal(err)
}

ctrl := &beep.Ctrl{Streamer: beep.Loop(-1, streamer), Paused: false}
ctrl := &beep.Ctrl{Streamer: loopStreamer, Paused: false}
volume := &effects.Volume{
Streamer: ctrl,
Base: 2,
Expand Down
Loading