feat: inline timestamp markers for offline audio segments#4851
Open
feat: inline timestamp markers for offline audio segments#4851
Conversation
Add recording_start_time tracking to the SD card storage layer. The info.txt file is extended from 4 bytes (offset only) to 8 bytes (offset + recording start time) with backward-compatible reading.
Extend the storage read characteristic from 2 to 3 uint32 values to include the recording start time alongside file size and offset.
Add write_timestamp_to_storage() to write a 5-byte marker (0xFF + 4-byte LE epoch) before the first audio frame of each offline recording segment. Add storage_flush_buffer() to flush pending data on shutdown. Reset the marker flag on each BLE connect so subsequent offline sessions get fresh timestamps.
Call storage_flush_buffer() in turnoff_all() to ensure any pending audio data in the write buffer is persisted before powering off the SD card.
Parse inline timestamp markers in both BLE and WiFi sync paths to split audio into properly-timed WAL segments. Also fix chunk size calculation to use actual codec FPS instead of hardcoded values, and derive WAL duration from actual frame count rather than a fixed 60-second assumption.
Member
Author
Contributor
There was a problem hiding this comment.
Code Review
This pull request successfully implements a valuable feature by embedding inline timestamp markers in offline audio recordings, allowing for accurate segmentation. The firmware and app changes are well-executed, with robust logic for handling the new data format and maintaining backward compatibility. However, the review identified two high-severity issues that should be addressed: unrelated logging configuration changes in omi.conf that appear to be development artifacts, and the removal of a necessary header file in sd_card.c which could compromise build stability. Once these points are resolved, the pull request will be in excellent shape.
Instead of flushing immediately when a 0xFF timestamp marker is encountered during BLE streaming, record markers and their frame indices. Split segments at marker boundaries only during the normal chunking phase, preventing tiny 5-second WAL fragments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
0xFFtimestamp markers in the offline audio data stream so each recording segment (between BLE disconnects or power cycles) has an exact UTC start timeinfo.txton SD card from 4 to 8 bytes to persist a recording start time alongside the read offsetFirmware changes
write_timestamp_to_storage()injects a 5-byte marker (0xFF+ 4-byte LE epoch) before the first offline audio frame of each segment.storage_flush_buffer()flushes pending data on shutdown.needs_timestamp_markerflag resets on each BLE connect.recording_start_timepersisted ininfo.txt(backward-compatible 8-byte format)[file_size, offset, recording_start_time]storage_flush_buffer()beforeapp_sd_off()inturnoff_all()App changes
0xFFmarkers in both BLE and WiFi sync paths, splits audio into correctly-timed WAL segments. Fixes chunk size fromsdcardChunkSizeSecs * 100tosdcardChunkSizeSecs * codec.getFramesPerSecond().Backward compatibility
Test plan