Skip to content

Commit 55cdc0c

Browse files
committed
Remove unused code from Synthesizer.Play
After recent refactorings some code was no longer needed.
1 parent 2391487 commit 55cdc0c

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

audio/synth.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,20 @@ func (c *channel) moveToNextNote(sfx SoundEffect) {
9494
}
9595

9696
func (s *Synthesizer) Play(sfxNo, ch, offset, length int) {
97-
if sfxNo == -2 {
98-
s.disableLooping(ch)
97+
if ch < -1 || ch > 3 {
9998
return
10099
}
101100

102-
if ch >= -2 && ch <= 3 {
103-
s.Stop(sfxNo)
101+
if sfxNo < 0 || sfxNo > maxSfxNo {
102+
return
104103
}
105104

105+
s.Stop(sfxNo)
106+
106107
if ch == -1 {
107108
ch = s.findAvailableChannel()
108109
}
109110

110-
if ch < 0 || ch > 3 {
111-
return
112-
}
113-
114-
if sfxNo == -1 {
115-
s.channels[ch].playing = false
116-
return
117-
}
118-
119111
offset = pi.MidInt(offset, 0, 31)
120112

121113
s.channels[ch].playing = true

audio/synth_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,30 @@ func TestSynthesizer_PlayStop(t *testing.T) {
595595
}
596596
})
597597

598+
t.Run("should not stop playing sfx when sfx is invalid", func(t *testing.T) {
599+
sfxNumbers := []int{math.MinInt, -1, maxSfxNo + 1, math.MaxInt}
600+
601+
for _, sfxNo := range sfxNumbers {
602+
testName := fmt.Sprintf("%d", sfxNo)
603+
t.Run(testName, func(t *testing.T) {
604+
synth := &audio.Synthesizer{}
605+
var e audio.SoundEffect
606+
e.Speed = 1
607+
e.Notes[0].Volume = audio.VolumeLoudest
608+
synth.SetSfx(0, e)
609+
610+
synth.Play(0, 0, 0, 1)
611+
// when
612+
synth.Play(sfxNo, 0, 0, 1)
613+
// then
614+
stat := synth.Stat()
615+
assert.Equal(t, 0, stat.Sfx[0])
616+
// and
617+
assertNotSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne))
618+
})
619+
}
620+
})
621+
598622
sfxOffsetLengthTest(t)
599623
sfxLoopTest(t)
600624
sfxLengthTest(t)

0 commit comments

Comments
 (0)