lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
41 stars 50 forks source link

Microphone takes longer to turn on the second time is used #376

Closed microbit-carlos closed 3 months ago

microbit-carlos commented 9 months ago

With simple MakeCode parrot programme from https://github.com/microsoft/pxt-microbit/issues/5312, when button A is pressed the first time the microphone goes online very quickly. Any subsquent button presses and the microphone takes about a second to turn on from the moment the button is pressed.:

input.onButtonPressed(Button.A, function () {
    record.setSampleRate(11000)
    basic.showString("?")
    record.startRecording(record.BlockingState.Blocking)
    basic.showLeds(`
        . # . . .
        . # # . .
        . # # # .
        . # # . .
        . # . . .
        `)
    record.setSampleRate(18000)
    record.playAudio(record.BlockingState.Blocking)
    basic.clearScreen()
})

Tested with MakeCode using CODAL versions v0.2.55 to v0.2.57, but it's possible it is present in previous versions as well, as I haven't tested earlier ones.

microbit-carlos commented 9 months ago

Okay, tested in MakeCode v6.0.1 with CODAL v0.2.47 and the present is still present there.

microbit-carlos commented 9 months ago

changing the [ show string [ "?" ] ] block with "show image" with 0 ms delay shows that in that case the mic LED comes up almost immediately after the image.

image
input.onButtonPressed(Button.A, function () {
    record.setSampleRate(11000)
    images.createImage(`
        . # # # .
        # . . . #
        # . . . #
        # . . . #
        . # # # .
        `).showImage(0, 0)
    record.startRecording(record.BlockingState.Blocking)
    basic.showLeds(`
        . # . . .
        . # # . .
        . # # # .
        . # # . .
        . # . . .
        `)
    record.setSampleRate(18000)
    record.playAudio(record.BlockingState.Blocking)
    basic.clearScreen()
})

Or if the interval second parameter is used in basic.showString("?", 0) to set the delay to 0ms, then it also works as expected.

So @JohnVidler suspicion that the first run doesn't respect the default 400 ms delay from basic.showString("?") is right. But the delay on the second run is much longer, using a stopwatch it's about 2 seconds.

JohnVidler commented 8 months ago

Do we have a CODAL repro for this? Is this a Makecode issue or a timing issue in CODAL?

microbit-carlos commented 8 months ago

We haven't tried it in CODAL code directly, so that might be the first step.

microbit-carlos commented 3 months ago

I can confirm that this issue does not reproduce anymore on the current Live MakeCode, so the delay issue is likely to have been on the MakeCode side and fixed at some point in the last few months.