File tree 2 files changed +29
-13
lines changed
2 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -94,28 +94,20 @@ func (c *channel) moveToNextNote(sfx SoundEffect) {
94
94
}
95
95
96
96
func (s * Synthesizer ) Play (sfxNo , ch , offset , length int ) {
97
- if sfxNo == - 2 {
98
- s .disableLooping (ch )
97
+ if ch < - 1 || ch > 3 {
99
98
return
100
99
}
101
100
102
- if ch >= - 2 && ch <= 3 {
103
- s . Stop ( sfxNo )
101
+ if sfxNo < 0 || sfxNo > maxSfxNo {
102
+ return
104
103
}
105
104
105
+ s .Stop (sfxNo )
106
+
106
107
if ch == - 1 {
107
108
ch = s .findAvailableChannel ()
108
109
}
109
110
110
- if ch < 0 || ch > 3 {
111
- return
112
- }
113
-
114
- if sfxNo == - 1 {
115
- s .channels [ch ].playing = false
116
- return
117
- }
118
-
119
111
offset = pi .MidInt (offset , 0 , 31 )
120
112
121
113
s .channels [ch ].playing = true
Original file line number Diff line number Diff line change @@ -595,6 +595,30 @@ func TestSynthesizer_PlayStop(t *testing.T) {
595
595
}
596
596
})
597
597
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
+
598
622
sfxOffsetLengthTest (t )
599
623
sfxLoopTest (t )
600
624
sfxLengthTest (t )
You can’t perform that action at this time.
0 commit comments