Skip to content

Commit

Permalink
[bugfix] Sfx() does not work after it the loop was stop previously
Browse files Browse the repository at this point in the history
Sfx(0,0,0,2)
Sfx(-2,0,0,0)
Sfx(0,0,0,2)

Last command results in silence.
  • Loading branch information
elgopher committed Sep 3, 2023
1 parent 7bcc46f commit 14f09c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions audio/synth.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (s *Synthesizer) Sfx(sfxNo int, ch Channel, offset, length int) {
s.channels[ch].frame = 0
s.channels[ch].noteNo = offset
s.channels[ch].notesToGo = length
s.channels[ch].loopingDisabled = false

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

Expand Down
19 changes: 19 additions & 0 deletions audio/synth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,25 @@ func sfxLoopTest(t *testing.T) {
})
}
})

t.Run("should loop sfx after it the loop was stopped previously", func(t *testing.T) {
var e audio.SoundEffect
e.Notes[0].Volume = audio.VolumeLoudest
e.Speed = 1
e.LoopStart = 0
e.LoopStop = 1

synth := &audio.Synthesizer{}
synth.SetSfx(0, e)
synth.Sfx(0, 0, 0, 2) // start the loop
synth.Sfx(-2, 0, 0, 0) // stop the loop
// when
synth.Sfx(0, 0, 0, 2) // start the loop again
// then
assertNotSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne)) // play note 0
assertNotSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne)) // play note 0 again
assertSilence(t, readSamples(synth, durationOfNoteWhenSpeedIsOne))
})
}

func sfxLengthTest(t *testing.T) {
Expand Down

0 comments on commit 14f09c7

Please sign in to comment.