Skip to content

Commit

Permalink
AnalogConfigESP32V1 sample rate stereo
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 13, 2023
1 parent e1da6ab commit 1e8c59a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/AudioAnalog/AnalogAudioESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class AnalogDriverESP32V1 : public AnalogDriverBase {

/// Configure the ADC
adc_continuous_config_t dig_cfg = {
.sample_freq_hz = (uint32_t)cfg.sample_rate,
.sample_freq_hz = (uint32_t)cfg.sample_rate * cfg.channels,
.conv_mode = cfg.adc_conversion_mode,
.format = cfg.adc_output_type,
};
Expand Down Expand Up @@ -375,14 +375,15 @@ class AnalogDriverESP32V1 : public AnalogDriverBase {
}

bool checkADCSampleRate() {
int sample_rate = cfg.sample_rate * cfg.channels;
// Boundary checks
if ((cfg.sample_rate < SOC_ADC_SAMPLE_FREQ_THRES_LOW) ||
(cfg.sample_rate > SOC_ADC_SAMPLE_FREQ_THRES_HIGH)) {
if ((sample_rate < SOC_ADC_SAMPLE_FREQ_THRES_LOW) ||
(sample_rate > SOC_ADC_SAMPLE_FREQ_THRES_HIGH)) {
LOGE("sample rate: %u can not be set, range: %u to %u",
SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH);
return false;
} else {
LOGI("sample rate: %u, range: %u to %u", cfg.sample_rate,
LOGI("sample rate: %u, range: %u to %u", sample_rate,
SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH);
}
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/AudioAnalog/AnalogConfigESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class AnalogConfigESP32V1 : public AudioInfo {
bits_per_sample = 16;
rx_tx_mode = rxtxMode;
if (rx_tx_mode == RX_MODE) {
// make sure that the proposed sample rate is valid
if (sample_rate*channels>SOC_ADC_SAMPLE_FREQ_THRES_HIGH){
sample_rate = SOC_ADC_SAMPLE_FREQ_THRES_HIGH / channels;
}
LOGI("I2S_MODE_ADC_BUILT_IN");
} else {
LOGI("I2S_MODE_DAC_BUILT_IN");
Expand Down

0 comments on commit 1e8c59a

Please sign in to comment.