Skip to content

feat - add VAD feature for Omi device and improve power consumption - #6950

Merged
mdmohsin7 merged 33 commits into
BasedHardware:mainfrom
TuEmb:TuEmb/aad_trigger
Apr 23, 2026
Merged

mdmohsin7 merged 33 commits into
BasedHardware:mainfrom
TuEmb:TuEmb/aad_trigger

Conversation

@TuEmb

@TuEmb TuEmb commented Apr 22, 2026 •

Copy link
Copy Markdown
Collaborator

This PR introduces a voice-activity based recording pipeline to reduce power usage and improve offline reliability.
The main direction is to gate audio forwarding by VAD state, add pre-roll handling, and coordinate mic/SD behavior during sleep and wake transitions.

What changed

1. VAD/AAD pipeline

  • Added VAD gate configs and runtime state flow (sleep vs recording)
  • Added debounce, hold, and threshold-based voice detection
  • Added pre-roll buffering and flush when transitioning from sleep to recording
  • Introduced software-managed AAD flow integration path and related state logic

2. Microphone runtime mode switching

  • Added stereo and mono-left mic modes
  • Added APIs for mic pause/resume and dynamic mode switching
  • Updated processing path to handle both stereo interleaved and mono input correctly

3. SD card and offline storage behavior

  • Added SD suspend/resume requests tied to VAD sleep state in offline mode
  • Added boot-time cleanup for stale temporary/truncated audio files
  • Reduced file rotation interval to improve file lifecycle behavior

4. Transport and settings stability

  • Adjusted BLE settings load order to run after bt_enable path
  • Made advertising-start failure non-fatal so offline recording can continue
  • Updated settings initialization to load application subtree in the correct phase

5. Boot/runtime robustness

  • Added configurable watchdog timeout via Kconfig
  • Added boot-stage logging improvements for better startup diagnostics
  • Kept system progressing even when specific optional subsystems fail

TuEmb added 30 commits April 17, 2026 14:01
…ad_trigger

# Conflicts:
#	omi/firmware/omi/src/settings.c
@greptile-apps

greptile-apps Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a software VAD gate and T5838 hardware AAD (Acoustic Activity Detection) to reduce power consumption on the Omi device, along with SPI/SD PM gating between flushes, DCDC converter enablement, a configurable watchdog timeout, and boot-time stale-file cleanup.

  • P0 — CONFIG_BT=y dropped in omi.conf: the line was replaced by a duplicate CONFIG_BT_SETTINGS=y, disabling the entire Bluetooth stack; no BLE connectivity will be available in this build.
  • P1 — sd_write_pause() never called from AAD: the function is implemented and declared with the explicit note "used by AAD to stop writing during VAD silence", but aad.c never includes sd_card.h or calls it, leaving SD writes active during VAD sleep.
  • P1 — LOG_LEVEL_DBG hardcoded in sd_card.c: forces verbose logging unconditionally, flooding output in production builds.

Confidence Score: 2/5

Not safe to merge — loss of CONFIG_BT=y disables Bluetooth entirely, and two additional P1 issues leave stated power-saving goals incomplete.

A P0 bug (missing CONFIG_BT=y) would render the device unreachable over BLE. Two P1 issues (sd_write_pause never wired, hardcoded debug log level) further reduce confidence. The VAD/AAD logic itself is reasonably structured but integration gaps must be addressed before shipping.

omi/firmware/omi/omi.conf (CONFIG_BT=y missing), omi/firmware/omi/src/aad.c (sd_write_pause not called), omi/firmware/omi/src/sd_card.c (hardcoded LOG_LEVEL_DBG), omi/firmware/omi/src/lib/core/transport.c (silent adv failure)

Important Files Changed

Filename Overview
omi/firmware/omi/omi.conf Critical: CONFIG_BT=y dropped and replaced with a duplicate CONFIG_BT_SETTINGS=y, disabling the entire Bluetooth stack; also enables DCDC, VAD, and logging.
omi/firmware/omi/src/aad.c New VAD/AAD driver with pre-roll buffering, debounce state machine, and WAKE-pin ISR; SD write pause on VAD sleep is implemented in sd_card.c but never wired up from here.
omi/firmware/omi/src/sd_card.c Adds SPI/SD PM gating, sd_write_pause(), boot-time stale-file cleanup, and halves WRITE_BATCH_COUNT; log level hardcoded to DBG instead of CONFIG_LOG_DEFAULT_LEVEL.
omi/firmware/omi/src/lib/core/transport.c Adds settings_load() after bt_enable(), duplicate settings.h include, and silently continues when bt_le_adv_start fails instead of propagating the error.
omi/firmware/boards/omi/Kconfig New board Kconfig enabling DCDC converters for both app and network MCUs to reduce idle power consumption.
omi/firmware/omi/Kconfig Adds Kconfig symbols for VAD gate, amplitude threshold, debounce frames, hold time, T5838 AAD enable, and configurable watchdog timeout.
omi/firmware/omi/src/aad.h Header for AAD/VAD module; contains a UTF-8 BOM that should be stripped.
omi/firmware/omi/src/main.c Integrates aad_start() and aad_process_audio() under CONFIG_OMI_ENABLE_T5838_AAD guard cleanly.
omi/firmware/omi/src/wdog_facade.c Watchdog timeout now driven by CONFIG_OMI_WATCHDOG_TIMEOUT_MS Kconfig symbol instead of a hard-coded constant.
omi/firmware/omi/src/settings.c Comment updated to clarify BT settings_load() ordering; no functional changes.
omi/firmware/omi/src/lib/core/sd_card.h Adds sd_write_pause() declaration for VAD-driven SD I/O gating.
omi/firmware/omi/src/lib/core/button.c Minor: imu.h include moved after wdog_facade.h, trailing whitespace added on one line.
omi/firmware/omi/CMakeLists.txt Conditionally appends aad.c to the build when CONFIG_OMI_ENABLE_T5838_AAD is set.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    MIC[Mic Callback\nmic_handler] --> AAD{CONFIG_OMI_ENABLE_T5838_AAD?}
    AAD -- yes --> PROC[aad_process_audio]
    AAD -- no --> CODEC
    PROC --> AVG[Compute avg_abs_amplitude]
    AVG --> VOICE{avg >= VAD_THRESHOLD?}
    VOICE -- yes --> STREAK[Increment voice_streak]
    STREAK --> DEB{streak >= DEBOUNCE_FRAMES?}
    DEB -- yes --> REC[State: RECORDING\nFlush pre-roll queue]
    DEB -- no --> PREROLL_STORE
    VOICE -- no --> RESET_STREAK[Reset voice_streak]
    RESET_STREAK --> HOLD{Recording and silent >= HOLD_MS?}
    HOLD -- yes --> SLEEP[State: SLEEP\nvad_sleeping=true]
    HOLD -- no --> CHECK_REC
    SLEEP --> PREROLL_STORE[Store in pre-roll ring]
    PREROLL_STORE --> DISCARD[Return false - discard frame]
    CHECK_REC{is_recording?}
    CHECK_REC -- no --> PREROLL_STORE
    REC --> CHECK_REC
    CHECK_REC -- yes --> PREROLL_FLUSH{pre-roll flush pending?}
    PREROLL_FLUSH -- yes --> BACKLOG[Push live frame to backlog\nFlush one pre-roll frame]
    BACKLOG --> DISCARD
    PREROLL_FLUSH -- no --> BACKLOG_CHK{live backlog count > 0?}
    BACKLOG_CHK -- yes --> FLUSH_BACKLOG[Flush one backlog frame\nQueue current frame]
    FLUSH_BACKLOG --> DISCARD
    BACKLOG_CHK -- no --> CODEC[codec_receive_pcm\nReturn true]
    WAKE_ISR[T5838 WAKE Pin ISR] --> ATOMIC[atomic_set wake_pending]
    ATOMIC --> SEM[k_sem_give aad_sem]
    SEM --> THREAD[AAD Thread\naad_thread_fn]
    THREAD --> CONSUMED[atomic_set wake_consumed]
    CONSUMED --> PROC
Loading

Comments Outside Diff (4)

  1. omi/firmware/omi/omi.conf, line 122-123 (link)

    P0 CONFIG_BT=y removed, breaking the Bluetooth stack

    CONFIG_BT=y (the master Bluetooth stack enable) was replaced by a duplicate CONFIG_BT_SETTINGS=y. Without CONFIG_BT=y, all dependent symbols (CONFIG_BT_SMP, CONFIG_BT_PERIPHERAL, CONFIG_BT_GATT_*, etc.) are outside their dependency scope and the BT stack will not be compiled in. Firmware will boot but without any BLE connectivity.

  2. omi/firmware/omi/src/aad.c, line 405-412 (link)

    P1 SD write pause never called — VAD-sleep power saving is incomplete

    sd_write_pause() is declared in sd_card.h and implemented in sd_card.c with the explicit comment "Used by AAD to stop writing during VAD silence", but aad.c never includes sd_card.h and never calls sd_write_pause(). aad_is_sleeping() is also not polled anywhere in the codebase. As a result, the SD card keeps writing even when VAD enters SLEEP, negating one of the stated power savings goals.

  3. omi/firmware/omi/src/lib/core/transport.c, line 1638-1641 (link)

    P1 Silent BLE advertising failure may hide serious configuration problems

    Changing bt_le_adv_start failure from a fatal error to a warning with "continuing without BLE" means that a misconfigured identity address will silently produce a device that records to SD but is unreachable over BLE. Callers of transport_start() get no indication that BLE is non-functional. Consider returning an error or setting a status flag so higher layers can react (e.g., light an LED error indicator).

  4. omi/firmware/omi/src/lib/core/transport.c, line 617 (link)

    P2 Duplicate #include <zephyr/settings/settings.h>

    <zephyr/settings/settings.h> was already included two lines above this addition. The duplicate is harmless due to include guards but should be removed.

Reviews (1): Last reviewed commit: "turn off logging for debug" | Re-trigger Greptile

break;
}

char path[64];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Hardcoded LOG_LEVEL_DBG will flood production logs

LOG_MODULE_REGISTER(sd_card, LOG_LEVEL_DBG) forces debug-level logging for the SD card module unconditionally, regardless of CONFIG_LOG_DEFAULT_LEVEL. The SD worker path now logs every flush with LOG_DBG, which will generate significant log traffic in production builds and slow down the SD thread.

Suggested change
char path[64];
LOG_MODULE_REGISTER(sd_card, CONFIG_LOG_DEFAULT_LEVEL);

@@ -0,0 +1,45 @@
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 UTF-8 BOM at the top of the file

The file begins with a UTF-8 BOM (\xEF\xBB\xBF). While GCC typically handles this, some embedded toolchains used in nRF Connect SDK may emit a spurious warning or treat the BOM as an invalid character before the first /*. Remove it so the file starts cleanly with /.

@TuEmb

TuEmb commented Apr 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Offline Sleep Mode (no voice):

image

Offline Recording Mode
image

@TuEmb

TuEmb commented Apr 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

deepsleep:

image

Audio sync:

image

Online Sleep Mode:

image

Online Streaming Mode:

image

@TuEmb
TuEmb requested a review from mdmohsin7 April 23, 2026 07:59
@mdmohsin7
mdmohsin7 merged commit c5274ca into BasedHardware:main Apr 23, 2026
1 check failed
@TuEmb
TuEmb deleted the TuEmb/aad_trigger branch April 23, 2026 13:57
Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…asedHardware#6950)

This PR introduces a voice-activity based recording pipeline to reduce
power usage and improve offline reliability.
The main direction is to gate audio forwarding by VAD state, add
pre-roll handling, and coordinate mic/SD behavior during sleep and wake
transitions.

What changed

**1. VAD/AAD pipeline**
- Added VAD gate configs and runtime state flow (sleep vs recording)
- Added debounce, hold, and threshold-based voice detection
- Added pre-roll buffering and flush when transitioning from sleep to
recording
- Introduced software-managed AAD flow integration path and related
state logic

**2. Microphone runtime mode switching**
- Added stereo and mono-left mic modes
- Added APIs for mic pause/resume and dynamic mode switching
- Updated processing path to handle both stereo interleaved and mono
input correctly

**3. SD card and offline storage behavior**
- Added SD suspend/resume requests tied to VAD sleep state in offline
mode
- Added boot-time cleanup for stale temporary/truncated audio files
- Reduced file rotation interval to improve file lifecycle behavior

**4. Transport and settings stability**
- Adjusted BLE settings load order to run after bt_enable path
- Made advertising-start failure non-fatal so offline recording can
continue
- Updated settings initialization to load application subtree in the
correct phase

**5. Boot/runtime robustness**
- Added configurable watchdog timeout via Kconfig
- Added boot-stage logging improvements for better startup diagnostics
- Kept system progressing even when specific optional subsystems fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants