microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
721 stars 593 forks source link

recording extension sim: microphone light doesn't always turns off #5126

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago

The microphone LED might is only meant to be ON while the device is recording.

✅ In the simulator this works correctly with a programme like this. When the audio recording is finished the microphone light turns off:

image

❌ However, when using the [plot bar graph] block the microphone LED stays turned on after the recording is done. This screenshot was taken after the recording finished, as the [clear screen] block has taken place and display is clear:

image

Maybe this is because the simulator widget to change the light level stays loaded on the simulator, but this is a deviation from the real behaviour on the device, as on the micro:bit the microphone LED goes off as expected.



> makecode.microbit.org version:  [5.1.26](https://github.com/Microsoft/pxt-microbit/releases/tag/v5.1.26)
> Microsoft MakeCode version:  [8.6.33](https://github.com/Microsoft/pxt/releases/tag/v8.6.33)
> microbit runtime version:  [v2.2.0-rc6](https://github.com/lancaster-university/microbit/releases/tag/v2.2.0-rc6)
> codal-microbit-v2 runtime version:  [v0.2.50](https://github.com/lancaster-university/codal-microbit-v2/releases/tag/v0.2.50)
srietkerk commented 1 year ago

Thank you for finding this! I will work on getting the simulator to reflect the correct hardware behavior.

I want to follow-up with a possible hardware bug that I found. As I was experimenting to better understand this issue, I ran into some weirdness on the micro:bit. If you have a program like the following, the bar graph for the sound level without the recording doesn't behave correctly if you fire the A button pressed program first.

image

Steps

  1. Download the above program onto the micro:bit
  2. Press A to trigger the recording extension and sound level tracker
  3. Press B to trigger the sound level tracker without recording audio
  4. You'll see the sound level only output one level for the duration of the while loop

For control

  1. Reset the micro:bit
  2. Press B to trigger the sound level tracker without recording audio
  3. You'll see the sound level tracker behave as you would expect
  4. Press A to trigger the recording extension and sound level tracker
  5. You'll see the sound level tracker behave as you would expect
  6. Press B to trigger the sound level tracker without recording audio
  7. You'll see the sound level only output one level for the duration of the while loop

It looks like the recording extension continues to have control over the microphone. I figured this might be a problem with how the extension explicitly asks to enable and disable the mic currently: https://github.com/microsoft/pxt-microbit/blob/db3677a9319fbff9bfc81d6141cc36acf6b99015/libs/audio-recording/recording.cpp#L75. However, I deleted the enableMic and disableMic code in my testing and rebuilt the target, and nothing changed. I otherwise don't see an obvious spot within the recording extension itself that could be causing this problem. I suspect this problem is arising because the sound level blocks aren't using the ubit object that was pointed out here https://github.com/microsoft/pxt-microbit/issues/5002. Are there any other places I should look to help solve this problem?

microbit-carlos commented 1 year ago

Is this problem replicable in C++ code using the uBit object? If it's not and it's caused by MakeCode instantiating its own level detector, then this might be a good opportunity to update that code to use the uBit object, as that is the recommended way to use that feature. Even if we find an easy workaround now for having a separate levelSPL, other future changes to the sound pipeline could still conflict with having that external instance.

@JohnVidler do you have any other pointers?

abchatra commented 1 year ago

Simulator still shows microphone recording if the you press B after couple of seconds in the following program image