Mac SDK 1.12.3
In our game Grand Tour Legends we have a ratchet clicking sound effect playing when you're not pedalling - its trigger frequency based on the speed you're going. We tried using playdate.sound.sequence to get better timing resolution for this effect, but met with some problems:
- the audio engine plays garbage if a Sample is shorter than the duration of a note (which varies with tempo)
- we modulate the sequence tempo every frame in a very wide range, after a few seconds the sequence stops playing.
function self:startTicks()
local inst = snd.instrument.new()
for i = 1, kTickSamples do
local sample = snd.sample.new('audio/tick_' .. i)
local s = snd.synth.new(sample)
inst:addVoice(s, i)
end
local track = snd.track.new()
track:setInstrument(inst)
for i = 1, kTickSamples do
track:addNote(i, i, 1, 100)
end
self.tickChannel = snd.channel.new()
self.tickChannel:addSource(inst)
self.tickSequence = snd.sequence.new()
self.tickSequence:addTrack(track)
self.tickSequence:setLoops(0, 6)
self.tickSequence:setTempo(10)
self.tickSequence:play()
end
function self:setTickSpeed(speed)
self.tickSequence:setTempo(speed)
end