Skip to content

Commit

Permalink
adf-mic: also increase volume if using 16bit (gain_log2)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnumpi committed Jun 17, 2024
1 parent 08640fe commit 81146a3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions esphome/components/adf_pipeline/microphone/esp_adf_microphone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ size_t ADFMicrophone::read(int16_t *buf, size_t len) {
}
size_t bytes_read = 0;
bytes_read = this->pcm_stream_.stream_read_bytes((char *) buf, len);
if ( bytes_read && this->gain_log2_ > 0){
size_t samples_read = bytes_read / sizeof(int16_t);
std::vector<int16_t> samples;
samples.resize(samples_read);
for (size_t i = 0; i < samples_read; i++) {
int32_t temp = (buf)[i] << this->gain_log2_ ;
samples[i] = (int16_t) clamp<int32_t>(temp, INT16_MIN, INT16_MAX );
}
memcpy(buf, samples.data(), samples_read * sizeof(int16_t));
}

return bytes_read;
}

Expand Down

0 comments on commit 81146a3

Please sign in to comment.