Add SetInputGain(float gain) to AudioCodec #1252
Merged
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.
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 baseAudioCodecclass, provides a setter method, and ensures that each codec uses this member for setting input gain. Additionally, it improves theNoAudioCodecandNoAudioCodecSimplexPdmclasses 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
input_gain_member variable and corresponding getter/setter (SetInputGain,input_gain) to the baseAudioCodecclass, 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]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]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
NoAudioCodecSimplexPdm::Read, scaling the input samples byinput_gain_before returning them. (main/audio/codecs/no_audio_codec.cc)WriteandReadimplementations forNoAudioCodecto 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.