Skip to content

Commit fa66ffb

Browse files
committed
AudioDriverCS42448Class
1 parent c03e4d5 commit fa66ffb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Driver.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ class CodecConfig : public codec_config_t {
4646
i2s.mode = MODE_SLAVE;
4747
}
4848

49+
/// Compare all attributes but ignore sample rate
50+
bool equalsExRate(CodecConfig alt){
51+
return (input_device == alt.input_device &&
52+
output_device == alt.output_device &&
53+
i2s.bits == alt.i2s.bits &&
54+
i2s.channels == alt.i2s.channels &&
55+
i2s.fmt == alt.i2s.fmt &&
56+
i2s.mode == alt.i2s.mode);
57+
}
58+
4959
/// Returns bits per sample as number
5060
int getBitsNumeric() {
5161
switch (i2s.bits) {
@@ -486,20 +496,18 @@ class AudioDriverCS42448Class : public AudioDriver {
486496
// setup pins
487497
pins.begin();
488498
// setup ad1938
489-
cs42448.begin(codecCfg, getI2C(), getI2CAddress());
499+
cs42448.begin(cfg, getI2C(), getI2CAddress());
490500
cs42448.setMute(false);
491501
return true;
492502
}
493503
virtual bool setConfig(CodecConfig codecCfg) {
494504
bool result = true;
495-
if (codecCfg.input_device == cfg.input_device &&
496-
codecCfg.output_device == cfg.output_device &&
497-
codecCfg.i2s.bits == cfg.i2s.bits &&
498-
codecCfg.i2s.channels == cfg.i2s.channels &&
499-
codecCfg.i2s.fmt == cfg.i2s.fmt && codecCfg.i2s.mode == cfg.i2s.mode) {
505+
if (codecCfg.equalsExRate(cfg)) {
500506
// just update the rate
501507
if (cfg.i2s.rate != cfg.i2s.rate) {
508+
cs42448.setMute(true);
502509
cs42448.setSampleRate(codecCfg.getRateNumeric());
510+
cs42448.setMute(false);
503511
}
504512
} else {
505513
result = begin(codecCfg, *p_pins);

0 commit comments

Comments
 (0)