This is with
- macOS 12.3.1
- SDK 1.9.3
- Nova 9.3
- Also a wired headphone/mic plugged into my computer
I'm experimenting with the micinput
methods, trying to build a state machine that lets you
- Record a sound
- Play that sound or re-record that sound
I've already discovered that I can't log things with print
because mixing print and micinput.stopRecording
can cause the simulator to crash. But even when I can navigate through my state machine successfully, I still can't:
- observe the callback in
playdate.sound.sampleplayer:setFinishCallback
being called - hear the sample (I think that) I've recorded during playback
Here's the relevant state machine code:
local snd <const> = playdate.sound
local state = State.awaitingRecording
local recording = snd.sample.new(5.0, snd.kFormat16bitMono)
local player = snd.sampleplayer.new(recording)
function updateState(toState)
if state == toState then
return
end
if (state == State.awaitingRecording or state == State.awaitingPlayback)
and toState == State.recording then
log("Starting to record")
state = toState
snd.micinput.recordToSample(recording, function ()
log("Recording callback called")
updateState(State.awaitingPlayback)
end)
elseif state == State.recording and toState == State.awaitingPlayback then
log("Stopping the recording")
state = toState
snd.micinput.stopRecording()
elseif state == State.awaitingPlayback and toState == State.playing then
log("Starting playback")
state = toState
player:setSample(recording)
player:setFinishCallback(function ()
log("Playback finished")
updateState(State.awaitingPlayback)
end)
player:play()
elseif state == State.playing and toState == State.awaitingPlayback then
state = toState
player:stop()
log("Ready to play/record again")
end
end
Side note: I say "even when" I can get through the state machine because intermittently things just hang in the "recording" state. Playdate callbacks like
playdate.update
andplaydate.BButtonDown
stop getting called. I'm still trying to figure out if that's something I'm doing wrong or if it's the tools hitting a bug.
Anyone else see this behavior? Is there something silly I'm missing from my code?
Thanks.
test-audio-sampler.zip (77.0 KB)