Skip to content

Commit 7cfc6d3

Browse files
committed
Support for 18 and 20 bits
1 parent 4dfe601 commit 7cfc6d3

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

src/Driver.h

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "DriverPins.h"
1717

1818
namespace audio_driver {
19-
19+
2020
const int rate_num[8] = {8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000};
2121
const samplerate_t rate_code[8] = {RATE_08K, RATE_11K, RATE_16K, RATE_22K,
2222
RATE_24K, RATE_32K, RATE_44K, RATE_48K};
@@ -61,6 +61,12 @@ class CodecConfig : public codec_config_t {
6161
case 16:
6262
i2s.bits = BIT_LENGTH_16BITS;
6363
return bits;
64+
case 18:
65+
i2s.bits = BIT_LENGTH_18BITS;
66+
return bits;
67+
case 20:
68+
i2s.bits = BIT_LENGTH_20BITS;
69+
return bits;
6470
case 24:
6571
i2s.bits = BIT_LENGTH_24BITS;
6672
return bits;
@@ -118,21 +124,21 @@ class CodecConfig : public codec_config_t {
118124
is_output = true;
119125

120126
if (is_input && is_output) {
121-
AD_LOGD("CODEC_MODE_BOTH");
127+
AD_LOGD("mode->CODEC_MODE_BOTH");
122128
return CODEC_MODE_BOTH;
123129
}
124130

125131
if (is_output) {
126-
AD_LOGD("CODEC_MODE_DECODE");
132+
AD_LOGD("mode->CODEC_MODE_DECODE");
127133
return CODEC_MODE_DECODE;
128134
}
129135

130136
if (is_input) {
131-
AD_LOGD("CODEC_MODE_ENCODE");
137+
AD_LOGD("mode->CODEC_MODE_ENCODE");
132138
return CODEC_MODE_ENCODE;
133139
}
134140

135-
AD_LOGD("CODEC_MODE_NONE");
141+
AD_LOGD("mode->CODEC_MODE_NONE");
136142
return CODEC_MODE_NONE;
137143
}
138144
};
@@ -652,7 +658,7 @@ class AudioDriverWM8994Class : public AudioDriver {
652658
delay(10);
653659
p_pins = &pins;
654660
int vol = map(volume, 0, 100, DEFAULT_VOLMIN, DEFAULT_VOLMAX);
655-
uint32_t freq = getFrequency(codec_cfg.i2s.rate);
661+
uint32_t freq = codecCfg.getRateNumeric();
656662
uint16_t outputDevice = getOutput(codec_cfg.dac_output);
657663

658664
auto i2c = pins.getI2CPins(CODEC);
@@ -688,27 +694,6 @@ class AudioDriverWM8994Class : public AudioDriver {
688694
return cnt == 0;
689695
}
690696

691-
uint32_t getFrequency(samplerate_t rateNum) {
692-
switch (rateNum) {
693-
case RATE_08K:
694-
return 8000; /*!< set to 8k samples per second */
695-
case RATE_11K:
696-
return 11024; /*!< set to 11.025k samples per second */
697-
case RATE_16K:
698-
return 16000; /*!< set to 16k samples in per second */
699-
case RATE_22K:
700-
return 22050; /*!< set to 22.050k samples per second */
701-
case RATE_24K:
702-
return 24000; /*!< set to 24k samples in per second */
703-
case RATE_32K:
704-
return 32000; /*!< set to 32k samples in per second */
705-
case RATE_44K:
706-
return 44100; /*!< set to 44.1k samples per second */
707-
case RATE_48K:
708-
return 48000; /*!< set to 48k samples per second */
709-
}
710-
return 44100;
711-
}
712697

713698
uint16_t getOutput(dac_output_t dac_output) {
714699
switch (dac_output) {

0 commit comments

Comments
 (0)