Skip to content

Commit 5a66f74

Browse files
committed
AudioDriverAD1938Class setMute on line level
1 parent 0b90648 commit 5a66f74

File tree

3 files changed

+52
-30
lines changed

3 files changed

+52
-30
lines changed

src/Driver.h

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,26 @@ class AudioDriverAD1938Class : public AudioDriver {
353353
return result;
354354
}
355355
bool end(void) override { return ad1938.end(); }
356-
bool setMute(bool enable) override { return ad1938.setMute(enable); }
356+
bool setMute(bool mute) override { return ad1938.setMute(mute); }
357+
// mutes an individual DAC
358+
bool setMute(bool mute, int line) {
359+
if (line > 7) return false;
360+
return ad1938.setVolumeDAC(line, mute ? 0.0 : (static_cast<float>(volumes[line]) / 100.0f));
361+
}
362+
357363
/// Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
358364
bool setVolume(int volume) override {
359365
this->volume = volume;
366+
for (int j=0;j<8;j++){
367+
volumes[j] = volume;
368+
}
360369
return ad1938.setVolume(static_cast<float>(volume) / 100.0f);
361370
}
362-
bool setVolume(int dac, float volume) {
363-
return ad1938.setVolumeDAC(dac, volume);
371+
/// Defines the Volume per DAC (in %) if volume is 0, mute is enabled,range is 0-100.
372+
bool setVolume(int volume, int line) {
373+
if (line > 7) return false;
374+
volumes[line] = volume;
375+
return ad1938.setVolumeDAC(static_cast<float>(volume) / 100.0f, line);
364376
}
365377

366378
int getVolume() override { return volume; }
@@ -375,6 +387,7 @@ class AudioDriverAD1938Class : public AudioDriver {
375387
AD1938 ad1938;
376388
DriverPins *p_pins = nullptr;
377389
int volume = 100;
390+
int volumes[8] = {100};
378391
};
379392

380393
/**
@@ -478,7 +491,7 @@ class AudioDriverCS43l22Class : public AudioDriver {
478491
};
479492

480493
/**
481-
* @brief Driver API for AD1938 TDS DAC/ADC
494+
* @brief Driver API for CS42448 TDS DAC/ADC
482495
* @author Phil Schatzmann
483496
* @copyright GPLv3
484497
*/
@@ -488,7 +501,7 @@ class AudioDriverCS42448Class : public AudioDriver {
488501
cfg = codecCfg;
489502
// setup pins
490503
pins.begin();
491-
// setup ad1938
504+
// setup cs42448
492505
cs42448.begin(cfg, getI2C(), getI2CAddress());
493506
cs42448.setMute(false);
494507
return true;
@@ -509,8 +522,8 @@ class AudioDriverCS42448Class : public AudioDriver {
509522
}
510523
bool end(void) override { return cs42448.end(); }
511524
bool setMute(bool enable) override { return cs42448.setMute(enable); }
512-
bool setMute(int channel, bool enable) {
513-
return cs42448.setMuteDAC(channel, enable);
525+
bool setMute(bool enable, int line) {
526+
return cs42448.setMuteDAC(line, enable);
514527
}
515528
/// Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
516529
bool setVolume(int volume) override {
@@ -762,19 +775,27 @@ class AudioDriverES8374Class : public AudioDriver {
762775
class AudioDriverES8388Class : public AudioDriver {
763776
public:
764777
bool setMute(bool mute) { return es8388_set_voice_mute(mute) == RESULT_OK; }
765-
// bool setMute(bool mute, int line) {
766-
// switch (line) {
767-
// case 1:
768-
// return es8388_config_output_device(DAC_OUTPUT_LINE1) == RESULT_OK;
769-
// break;
770-
// case 2:
771-
// return es8388_config_output_device(DAC_OUTPUT_LINE2) == RESULT_OK;
772-
// break;
773-
// default:
774-
// AD_LOGE("Invalid dac %d", volume);
775-
// return false;
776-
// }
777-
// }
778+
// mute line: lines start at 0
779+
bool setMute(bool mute, int line) {
780+
bool line_active[2];
781+
if (line > 1) {
782+
AD_LOGD("invalid line %d", line);
783+
return false;
784+
}
785+
line_active[line] = !mute;
786+
// mute is managed on line level, so deactivate global mute
787+
setMute(false);
788+
if (line_active[0] && line_active[1]) {
789+
return es8388_config_output_device(DAC_OUTPUT_ALL) == RESULT_OK;
790+
} else if (!line_active[0] && !line_active[1]) {
791+
return es8388_config_output_device(DAC_OUTPUT_NONE) == RESULT_OK;
792+
} else if (line_active[0]) {
793+
return es8388_config_output_device(DAC_OUTPUT_LINE1) == RESULT_OK;
794+
} else if (line_active[1]) {
795+
return es8388_config_output_device(DAC_OUTPUT_LINE2) == RESULT_OK;
796+
}
797+
return false;
798+
}
778799
bool setVolume(int volume) {
779800
AD_LOGD("volume %d", volume);
780801
return es8388_set_voice_volume(limitValue(volume)) == RESULT_OK;

src/Driver/ad1938/ad1938.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ class AD1938 {
5656
for (int j = 0; j > 4; j++) setVolumeDAC(j, vol);
5757
return true;
5858
}
59-
bool setVolumeDAC(int dac, float volume) {
59+
bool setVolume(int dac, float volume) {
6060
return setVolumeDAC(dac, scaleVolume(volume));
6161
}
62+
bool setVolume(int volume) {
63+
for (int j = 0; j > 4; j++) setVolumeDAC(j, volume);
64+
return true;
65+
}
66+
bool setVolumeDAC(int dac, int volume);
67+
6268
bool setMuteADC(bool mute);
6369

6470
bool setMuteDAC(bool mute);
@@ -85,11 +91,6 @@ class AD1938 {
8591
bool spi_write_reg(unsigned char reg, unsigned char val);
8692
unsigned char spi_read_reg(unsigned char reg);
8793
bool isPllLocked();
88-
bool setVolumeDAC(int dac, int volume);
89-
bool setVolume(int volume) {
90-
for (int j = 0; j > 4; j++) setVolumeDAC(j, volume);
91-
return true;
92-
}
9394
int scaleVolume(float volume) {
9495
int vol = (1.0 - volume) * 255;
9596
if (vol < 0) vol = 0;

src/Driver/cs42448/cs42448.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ class CS42448 {
230230

231231
return true;
232232
}
233-
234-
bool setMuteDAC(uint8_t channel, bool mute) {
233+
// line starts at 0
234+
bool setMuteDAC(uint8_t line, bool mute) {
235235
uint8_t mute_reg_value;
236-
if (channel >= 8) return false;
236+
if (line >= 8) return false;
237237
if (!readReg(CS42448_DAC_Channel_Mute, &mute_reg_value)) return false;
238-
setBit(mute_reg_value, channel, mute);
238+
setBit(mute_reg_value, line, mute);
239239
if (!writeReg(CS42448_DAC_Channel_Mute, mute_reg_value)) return false;
240240
return true;
241241
}

0 commit comments

Comments
 (0)