Hi all!
I'm working on a small Playdate project where an audio sequence is played by turning the crank. As this requires manual control over the timing of the audio playback I ended up with a solution using the sound.sequence.goToStep
function.
All seemed fine until updating to the latest playdate and SDK versions (1.12.2) where now suddently, the audio doesn't sound right anymore and often stutters and crackles. Here is a short example that I recorded.
I believe this is a bug with the current SDK version and it goes away again when I downgrade back to SDK 1.11.0.
Some more details:
- The problem happens both in the simulator (I'm on macOS) and on the Playdate itself.
- I'm using
sound.sequence
with multiple tracks. - Each track has a
sound.synth
with asound.sample
that is loaded from a short .aif file. When not providing a sample (i.e. the synth uses one of the built-in waveforms) it seems to also work correctly. - Unfortunately, the problem isn't trivial to reproduce as the problem doesn't happen every time the program runs. On average I'd say the bug is triggered every second time or so---but sometimes it doesn't happen a few times in a row and other times it happens almost every time.
Here is a simplified version of my code that simply plays the sequence once but still triggers the issue:
Example code
import "CoreLibs/timer"
local snd <const> = playdate.sound
local timer <const> = playdate.timer
length = 10
n_notes = 9
noteLabels = {}
noteLabels[1] = "C4"
noteLabels[2] = "E4"
noteLabels[3] = "G4"
noteLabels[4] = "C6"
noteLabels[5] = "E6"
noteLabels[6] = "G6"
noteLabels[7] = "C8"
noteLabels[8] = "E8"
noteLabels[9] = "G8"
sample = snd.sample.new("sample.aif")
sequence = snd.sequence.new()
for i=1,n_notes do
local track = snd.track.new()
local notes = {}
for j=1,length do
local tmp = {}
tmp.step = j
tmp.note = noteLabels[i]
tmp.velocity = 1.0
tmp.length = 15
notes[j] = tmp
end
track:setNotes(notes)
-- Create synth from audio sample.
local synth = snd.synth.new(sample)
-- Alternatively, a standard synth without sample sounds just fine:
-- local synth = snd.synth.new()
-- synth:setADSR(0.1, 0.1, 0.0, 0.5)
synth:setVolume(0.2)
track:setInstrument(synth)
sequence:addTrack(track)
end
sequence:setTempo(1)
sequence:stop()
played = false
function playdate.update()
if not played then
sequence:goToStep(1, false)
sequence:play()
played = true
end
end
See also this zip file that includes the .pdx, the makefile, and the "sample.aif" file.
I'd appreciate any help!
Thanks,
Tizian