Skip to content

Commit 488c16b

Browse files
committed
AudioDriverES8388Class setInputVolume
1 parent aea1464 commit 488c16b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Driver.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,20 +361,22 @@ class AudioDriverAD1938Class : public AudioDriver {
361361
bool end(void) override { return ad1938.end(); }
362362
bool setMute(bool mute) override { return ad1938.setMute(mute); }
363363
// mutes an individual DAC: valid range (0:3)
364-
bool setMute(bool mute, int line) {
365-
if (line > 3) return false;
366-
return ad1938.setVolumeDAC(line, mute ? 0.0 : (static_cast<float>(volumes[line]) / 100.0f));
364+
bool setMute(bool mute, int line) {
365+
if (line > 3) return false;
366+
return ad1938.setVolumeDAC(
367+
line, mute ? 0.0 : (static_cast<float>(volumes[line]) / 100.0f));
367368
}
368369

369370
/// Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
370371
bool setVolume(int volume) override {
371372
this->volume = volume;
372-
for (int j=0;j<8;j++){
373+
for (int j = 0; j < 8; j++) {
373374
volumes[j] = volume;
374375
}
375376
return ad1938.setVolume(static_cast<float>(volume) / 100.0f);
376377
}
377-
/// Defines the Volume per DAC (in %) if volume is 0, mute is enabled,range is 0-100.
378+
/// Defines the Volume per DAC (in %) if volume is 0, mute is enabled,range is
379+
/// 0-100.
378380
bool setVolume(int volume, int line) {
379381
if (line > 7) return false;
380382
volumes[line] = volume;
@@ -783,7 +785,7 @@ class AudioDriverES8388Class : public AudioDriver {
783785
bool setMute(bool mute) {
784786
line_active[0] = !mute;
785787
line_active[1] = !mute;
786-
return es8388_set_voice_mute(mute) == RESULT_OK;
788+
return es8388_set_voice_mute(mute) == RESULT_OK;
787789
}
788790
// mute individual line: lines start at 0 (valid range 0:1)
789791
bool setMute(bool mute, int line) {
@@ -815,8 +817,13 @@ class AudioDriverES8388Class : public AudioDriver {
815817
}
816818

817819
bool setInputVolume(int volume) {
818-
// map values from 0 - 100 to 0 to 10
819-
es_mic_gain_t gain = (es_mic_gain_t)(limitValue(volume) / 10);
820+
// map values from 0 - 100 to 0 to 9 MIC_GAIN_MIN = -1,
821+
es_mic_gain_t gains[] = {MIC_GAIN_0DB, MIC_GAIN_3DB, MIC_GAIN_6DB,
822+
MIC_GAIN_9DB, MIC_GAIN_12DB, MIC_GAIN_15DB,
823+
MIC_GAIN_18DB, MIC_GAIN_21DB, MIC_GAIN_24DB,
824+
MIC_GAIN_MAX};
825+
int idx = limitValue(volume / 10, 9);
826+
es_mic_gain_t gain = gains[idx];
820827
AD_LOGD("input volume: %d -> gain %d", volume, gain);
821828
return setMicrophoneGain(gain);
822829
}

0 commit comments

Comments
 (0)