Skip to content

Conversation

@78
Copy link
Owner

@78 78 commented Oct 2, 2025

This pull request introduces a unified and configurable input gain system for all audio codec classes, replacing hardcoded microphone gain values. It adds an input_gain_ member to the base AudioCodec class, provides a setter method, and ensures that each codec uses this member for setting input gain. Additionally, it improves the NoAudioCodec and NoAudioCodecSimplexPdm classes by implementing input gain amplification in software. These changes make audio input gain more flexible and easier to manage across different hardware implementations.

Input Gain Refactor and Configuration

  • Added input_gain_ member variable and corresponding getter/setter (SetInputGain, input_gain) to the base AudioCodec class, allowing input gain to be set and queried in a unified way. (main/audio/audio_codec.h, main/audio/audio_codec.cc) [1] [2] [3] [4]
  • Updated all derived codec constructors to initialize input_gain_ with appropriate default values for each hardware type. (main/audio/codecs/box_audio_codec.cc, main/audio/codecs/es8311_audio_codec.cc, main/audio/codecs/es8374_audio_codec.cc, main/audio/codecs/es8388_audio_codec.cc, main/audio/codecs/es8389_audio_codec.cc, main/boards/m5stack-core-s3/cores3_audio_codec.cc, main/boards/m5stack-tab5/tab5_audio_codec.cc) [1] [2] [3] [4] [5] [6] [7]
  • Modified all codec input enable methods to use the configurable input_gain_ value instead of hardcoded or macro-defined gain values. (main/audio/codecs/box_audio_codec.cc, main/audio/codecs/es8311_audio_codec.cc, main/audio/codecs/es8374_audio_codec.cc, main/audio/codecs/es8388_audio_codec.cc, main/audio/codecs/es8389_audio_codec.cc, main/boards/m5stack-core-s3/cores3_audio_codec.cc, main/boards/m5stack-tab5/tab5_audio_codec.cc) [1] [2] [3] [4] [5] [6] [7]

NoAudioCodec Improvements

  • Implemented software-based input gain amplification in NoAudioCodecSimplexPdm::Read, scaling the input samples by input_gain_ before returning them. (main/audio/codecs/no_audio_codec.cc)
  • Refactored and moved the Write and Read implementations for NoAudioCodec to improve code organization and ensure correct volume and gain handling. (main/audio/codecs/no_audio_codec.cc) [1] [2]

These changes make the audio input gain handling more flexible, maintainable, and consistent across all supported codecs.

@78 78 merged commit 2fd0ff0 into main Oct 2, 2025
1 of 92 checks passed
Cmdmac pushed a commit to Cmdmac/xiaozhi-esp32 that referenced this pull request Oct 14, 2025
Wvirgil123 added a commit to Wvirgil123/xiaozhi-esp32 that referenced this pull request Oct 20, 2025
* main:
  Add 16 more languages to locales (78#1297)
  Fix LilyGo-T-CameraPlus-S3 Camera (78#1295)
  Fix lichuang-dev camera (78#1290)
  将太极派新款和旧款分离 (78#1287)
  Refactor: Use esp_video component (78#1245)
  add support for Wireless-Tag WTP4C5MP07S ESP32P4 board + 7 inch MIPI DSI LCD display combo (78#1281)
  Optimize AdcBatteryMonitor to work without charge detection pin. (78#1276)
  enable rrti for m5stack-tab5 (78#1268)
  Add LILYGO T-Display-P4 board adaptation (78#1269)
  Added Waveshare ESP32-P4-WIFI6-Touch-LCD-7B third party board (78#1243)
  Add esp32c5 configuration (78#1258)
  Change the button array to ADC buttons as in the board for esp32s3-korv2 (78#1256)
  Add SetInputGain(float gain) to AudioCodec (78#1252)
  Update README (78#1251)
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