Skip to content

Commit 14f09c7

Browse files
committed
[bugfix] Sfx() does not work after it the loop was stop previously
Sfx(0,0,0,2) Sfx(-2,0,0,0) Sfx(0,0,0,2) Last command results in silence.
1 parent 7bcc46f commit 14f09c7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

audio/synth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func (s *Synthesizer) Sfx(sfxNo int, ch Channel, offset, length int) {
126126
s.channels[ch].frame = 0
127127
s.channels[ch].noteNo = offset
128128
s.channels[ch].notesToGo = length
129+
s.channels[ch].loopingDisabled = false
129130

130131
s.channels[ch].noteEndFrame = singleNoteSamples(sfx.Speed)
131132

audio/synth_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,25 @@ func sfxLoopTest(t *testing.T) {
890890
})
891891
}
892892
})
893+
894+
t.Run("should loop sfx after it the loop was stopped previously", func(t *testing.T) {
895+
var e audio.SoundEffect
896+
e.Notes[0].Volume = audio.VolumeLoudest
897+
e.Speed = 1
898+
e.LoopStart = 0
899+
e.LoopStop = 1
900+
901+
synth := &audio.Synthesizer{}
902+
synth.SetSfx(0, e)
903+
synth.Sfx(0, 0, 0, 2) // start the loop
904+
synth.Sfx(-2, 0, 0, 0) // stop the loop
905+
// when
906+
synth.Sfx(0, 0, 0, 2) // start the loop again
907+
// then
908+
assertNotSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne)) // play note 0
909+
assertNotSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne)) // play note 0 again
910+
assertSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne))
911+
})
893912
}
894913

895914
func sfxLengthTest(t *testing.T) {

0 commit comments

Comments
 (0)