Difficulty recording and playing back audio samples in the Simulator

,

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

  1. Record a sound
  2. 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 and playdate.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. :person_shrugging:

Anyone else see this behavior? Is there something silly I'm missing from my code?

Thanks.
test-audio-sampler.zip (77.0 KB)

I'm relatively sure the bug I found is hindering this. I'm going to put a pin in this until the SDK with the fix is released.

Huge thanks for the demo code--that unearthed another bug, calling stopRecording() from the finish callback was going into infinite recursion. I've added a fix for that and your demo looks like it's working correctly now. :+1:

1 Like

Great to hear that. I'm preparing Voice memos for Pocket Planner, and I noticed similar issues to those mentioned above. It's fantastic to hear that you fixed them, and I can't wait for the SDK update.