Skip to content

Commit 1d136aa

Browse files
committed
make automatic scaling optional in AnalogAudio
1 parent 01a75f6 commit 1d136aa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/AudioTools/AnalogAudio.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const char* ADC_TAG = "ADC";
1616
static int16_t convert8DAC(int value, int value_bits_per_sample){
1717
// -> convert to positive
1818
int16_t result = (value * maxValue(8) / maxValue(value_bits_per_sample)) + maxValue(8) / 2;
19-
return result;
19+
return result;
2020
}
2121

2222

@@ -43,17 +43,20 @@ class AnalogConfig {
4343
int mode_internal;
4444
int bits_per_sample = 16;
4545
int channels = 2;
46+
bool auto_scale = true;
4647

47-
AnalogConfig() {
48+
AnalogConfig(bool auto_scale = true) {
4849
this->mode = RX_MODE;
50+
this->auto_scale = auto_scale;
4951
setPin(DEFAUT_ADC_PIN);
5052
mode_internal = (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
5153
}
5254

5355

5456
/// Default constructor
55-
AnalogConfig(RxTxMode mode) {
57+
AnalogConfig(RxTxMode mode,bool auto_scale = true) {
5658
this->mode = mode;
59+
this->auto_scale = auto_scale;
5760
if (mode == RX_MODE) {
5861
setPin(DEFAUT_ADC_PIN);
5962
mode_internal = (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
@@ -216,7 +219,13 @@ class AnalogAudio {
216219
/// writes the data to the I2S interface
217220
size_t writeBytes(const void *src, size_t size_bytes){
218221
size_t result = 0;
219-
result = AnalogAudio::writeExpandChannel(i2s_num, adc_config.channels, adc_config.bits_per_sample, src, size_bytes);
222+
if (!adc_config.auto_scale){
223+
if (i2s_write(i2s_num, src, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
224+
LOGE("%s", __func__);
225+
}
226+
} else {
227+
result = AnalogAudio::writeExpandChannel(i2s_num, adc_config.channels, adc_config.bits_per_sample, src, size_bytes);
228+
}
220229
return result;
221230
}
222231

0 commit comments

Comments
 (0)