Skip to content

Commit 4bb7862

Browse files
committed
oto audio player paused and resumed correctly on state change
this was spotted because running the emulator on the command line would cause the debugger to run a paused state, but the audio player was busy looping and pegging a CPU core
1 parent 69687a9 commit 4bb7862

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

gui/ebiten/audio.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func (a *audioPlayer) setState(state gui.State) {
2222
a.crit.Lock()
2323
defer a.crit.Unlock()
2424
a.state = state
25+
if state == gui.StatePaused {
26+
a.p.Pause()
27+
} else {
28+
a.p.Play()
29+
}
2530
}
2631

2732
func (a *audioPlayer) Read(buf []uint8) (int, error) {

gui/ebiten/gui.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ func (eg *guiEbiten) Update() error {
152152
case <-ready:
153153
eg.audio.r = s.Read
154154
eg.audio.p = ctx.NewPlayer(&eg.audio)
155-
eg.audio.p.Play()
155+
if eg.state == gui.StatePaused {
156+
eg.audio.p.Pause()
157+
} else {
158+
eg.audio.p.Play()
159+
}
156160
case <-eg.endGui:
157161
return ebiten.Termination
158162
}
@@ -305,7 +309,7 @@ func Launch(endGui <-chan bool, g *gui.ChannelsGUI, update func() error) error {
305309
endGui: endGui,
306310
state: gui.StateRunning,
307311
audio: audioPlayer{
308-
state: gui.StateRunning,
312+
state: gui.StatePaused,
309313
},
310314
lastFrame: time.Now(),
311315
update: update,
@@ -317,7 +321,6 @@ func Launch(endGui <-chan bool, g *gui.ChannelsGUI, update func() error) error {
317321
for !done {
318322
select {
319323
case eg.state = <-g.State:
320-
eg.audio.setState(eg.state)
321324
done = true
322325
case <-endGui:
323326
return nil

0 commit comments

Comments
 (0)