Skip to content

Conversation

harshithsunku
Copy link
Contributor

@harshithsunku harshithsunku commented Sep 20, 2025

Audio Chunking System for Firmware

Overview

This PR introduces a time-based audio chunking system that improves file management, power efficiency, and remote chunk handling via Bluetooth GATT. The system records audio in configurable time-based chunks rather than continuous large files.

Features Added in PR

1. Time-Based Audio Chunking

  • Audio recorded in 5-minute chunks (configurable via CHUNK_DURATION_CYCLES)
  • Simple filename format: audio/chunk_NNNNN.bin
  • Persistent counter ensures unique filenames across device reboots

2. Configurable System

  • New Kconfig option: CONFIG_OMI_ENABLE_AUDIO_CHUNKING
  • Centralized configuration in src/sdcard_config.h
  • Backward compatible with legacy file system when disabled

3. Chunk Lifecycle Management

  • Create: Automatic chunk creation and rotation during recording
  • Stream: Send chunk files over Bluetooth to connected devices
  • Delete: Remove chunks after successful upload
  • Monitor: Query chunk counters and status via GATT characteristics

4. Bluetooth GATT Integration

  • New characteristics for chunk counter retrieval
  • Chunk streaming request characteristic
  • Chunk deletion request characteristic

Configuration

Enable chunking in your project config:

CONFIG_OMI_ENABLE_AUDIO_CHUNKING=y

Adjust chunk duration in src/sdcard_config.h:

#define CHUNK_DURATION_CYCLES 600  // 5 minutes (600 × 500ms)

Testing

  • Verified chunk creation, rotation, streaming, and deletion
  • Counter persistence validated across reboots
  • GATT characteristics tested with debug APP, Video attached

- Introduced a new configuration option for enabling audio chunking in Kconfig.
- Updated project configuration to include the new audio chunking feature.
- Implemented a new SD card management system to handle audio chunking, including file naming and chunk rotation logic.
- Added functions for generating unique audio filenames and managing chunk counters.
- Updated main loop to check for chunk rotation timing.
- Enhanced error handling and logging for file operations related to chunking.
- Created a new header file for SD card configuration constants to centralize paths and settings.
@harshithsunku harshithsunku marked this pull request as ready for review September 20, 2025 10:13
@beastoin
Copy link
Collaborator

Please list all features you have supported with this PR, including your tests, to make sure the firmware fulfills the ticket requirements.

e.g., features: list audio files, transfer the audio bytes (of one file), delete audio file.

@harshithsunku

@harshithsunku harshithsunku marked this pull request as draft September 21, 2025 09:18
…ounter management

- Reduced maximum filename length for audio chunks and updated filename format to exclude timestamp.
- Introduced separate counters for chunk start and current values to enhance uniqueness across reboots.
- Updated functions for saving and retrieving chunk counters to handle the new structure.
- Introduced `get_chunk_counter_snapshot` function to retrieve current chunk counters without affecting persistent storage.
- Added a new characteristic for chunk counters in the storage service to facilitate retrieval via GATT.
- Enhanced debugging output during chunk file creation to include detailed chunking state information.
@harshithsunku
Copy link
Contributor Author

harshithsunku commented Sep 28, 2025

Please list all features you have supported with this PR, including your tests, to make sure the firmware fulfills the ticket requirements.

e.g., features: list audio files, transfer the audio bytes (of one file), delete audio file.

@harshithsunku

Hi @beastoin ,

I’ve implemented audio file chunking into 5-minute segments and added a few new GATT BLE characteristics:

  • List chunk file range
  • Delete chunk file
  • Download chunk file

For validation and testing, I used my custom built debug tool instead of the mobile app (since I haven’t made app-side changes yet).
Here’s a screenshot of the tool in action:

OMI Debug Tool

This shows the chunking flow — receiving 440-byte packets, assembling them into files (e.g., ~43 kB for a 10 second chunk), and supporting operations like streaming, downloading, and deletion.

I’ll be tied up with other work for the next two days, but I’ll resume this shortly. Only unit testing is pending — I’ll update with the final PR in a couple of days.

- Implemented `stream_chunk_file` and `delete_chunk_file` functions to manage audio chunk files on the SD card.
- Enhanced chunk counter management during deletion to ensure proper tracking of chunk states.
- Added new GATT characteristics for chunk sending and deletion requests, improving interaction with the storage service.
- Improved error handling and logging for chunk operations to facilitate debugging and monitoring.
@harshithsunku
Copy link
Contributor Author

Hi @beastoin ,

I’ve done UT and validated the audio chunking and GATT characteristics firmware changes using my debug tool. A short video demonstration is shown below.

2025-10-01.19-00-57.mp4

- Updated `stream_chunk_file` and `delete_chunk_file` functions to include validation for chunk ID ranges, improving error handling.
- Refined logging to replace printf statements with structured logging for better debugging and monitoring.
- Added detailed documentation for chunk file operations in the header file to clarify usage and error codes.
- Improved chunk management by ensuring proper state checks before streaming or deleting chunks.
@harshithsunku harshithsunku marked this pull request as ready for review October 2, 2025 15:01
@harshithsunku
Copy link
Contributor Author

Hi @beastoin ,

Could you please review this PR, Firmware changes are done and tested.

Thanks.

@beastoin
Copy link
Collaborator

beastoin commented Oct 9, 2025

yeah, looks solid. btw, will let you know soon.

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