From 3e55b7b894f26fb8f7919024bfbb723bb4ab88f4 Mon Sep 17 00:00:00 2001 From: egor-denysenko <75579636+egor-denysenko@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:41:34 +0100 Subject: [PATCH] chore(examples): update all examples reference to Loop fn to use Loop2 --- examples/speedy-player/main.go | 16 ++++++++++++---- .../2-composing-and-controlling/b/main.go | 7 +++++-- .../2-composing-and-controlling/c/main.go | 7 ++++++- .../2-composing-and-controlling/d/main.go | 6 +++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/examples/speedy-player/main.go b/examples/speedy-player/main.go index 1b05836..f05e490 100644 --- a/examples/speedy-player/main.go +++ b/examples/speedy-player/main.go @@ -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() { @@ -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) diff --git a/examples/tutorial/2-composing-and-controlling/b/main.go b/examples/tutorial/2-composing-and-controlling/b/main.go index f20986f..c5ef60b 100644 --- a/examples/tutorial/2-composing-and-controlling/b/main.go +++ b/examples/tutorial/2-composing-and-controlling/b/main.go @@ -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() { diff --git a/examples/tutorial/2-composing-and-controlling/c/main.go b/examples/tutorial/2-composing-and-controlling/c/main.go index 343a2d9..08723a4 100644 --- a/examples/tutorial/2-composing-and-controlling/c/main.go +++ b/examples/tutorial/2-composing-and-controlling/c/main.go @@ -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 { diff --git a/examples/tutorial/2-composing-and-controlling/d/main.go b/examples/tutorial/2-composing-and-controlling/d/main.go index c19d017..64561eb 100644 --- a/examples/tutorial/2-composing-and-controlling/d/main.go +++ b/examples/tutorial/2-composing-and-controlling/d/main.go @@ -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,