From 1e8c59aa61dc3c33a6d054102a8b702cd58bdb2c Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Mon, 13 Nov 2023 11:00:54 +0100 Subject: [PATCH] AnalogConfigESP32V1 sample rate stereo --- src/AudioAnalog/AnalogAudioESP32V1.h | 9 +++++---- src/AudioAnalog/AnalogConfigESP32V1.h | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/AudioAnalog/AnalogAudioESP32V1.h b/src/AudioAnalog/AnalogAudioESP32V1.h index 2e5a3554c0..bbfa0e0a37 100644 --- a/src/AudioAnalog/AnalogAudioESP32V1.h +++ b/src/AudioAnalog/AnalogAudioESP32V1.h @@ -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, }; @@ -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; diff --git a/src/AudioAnalog/AnalogConfigESP32V1.h b/src/AudioAnalog/AnalogConfigESP32V1.h index f133dd5e77..3220e1f847 100644 --- a/src/AudioAnalog/AnalogConfigESP32V1.h +++ b/src/AudioAnalog/AnalogConfigESP32V1.h @@ -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");