small improvements for I2S PDM and I2S Line-in
This commit is contained in:
@@ -830,13 +830,14 @@ class AudioReactive : public Usermod {
|
||||
float sampleAdj; // Gain adjusted sample value
|
||||
float tmpSample; // An interim sample variable used for calculatioins.
|
||||
const float weighting = 0.2f; // Exponential filter weighting. Will be adjustable in a future release.
|
||||
const float weighting2 = 0.073f; // Exponential filter weighting, for rising signal (a bit more robust against spikes)
|
||||
const int AGC_preset = (soundAgc > 0)? (soundAgc-1): 0; // make sure the _compiler_ knows this value will not change while we are inside the function
|
||||
|
||||
#ifdef WLED_DISABLE_SOUND
|
||||
micIn = inoise8(millis(), millis()); // Simulated analog read
|
||||
micDataReal = micIn;
|
||||
#else
|
||||
#ifdef ESP32
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
micIn = int(micDataReal); // micDataSm = ((micData * 3) + micData)/4;
|
||||
#else
|
||||
// this is the minimal code for reading analog mic input on 8266.
|
||||
@@ -860,9 +861,15 @@ class AudioReactive : public Usermod {
|
||||
micIn -= micLev; // Let's center it to 0 now
|
||||
// Using an exponential filter to smooth out the signal. We'll add controls for this in a future release.
|
||||
float micInNoDC = fabsf(micDataReal - micLev);
|
||||
expAdjF = (weighting * micInNoDC + (1.0-weighting) * expAdjF);
|
||||
|
||||
if ((micInNoDC > expAdjF) && (expAdjF > soundSquelch)) // MicIn rising, and above squelch threshold?
|
||||
expAdjF = (weighting2 * micInNoDC + (1.0f-weighting2) * expAdjF); // rise slower
|
||||
else
|
||||
expAdjF = (weighting * micInNoDC + (1.0f-weighting) * expAdjF); // fall faster
|
||||
|
||||
expAdjF = fabsf(expAdjF); // Now (!) take the absolute value
|
||||
|
||||
//expAdjF = (micInNoDC <= soundSquelch) ? 0: expAdjF; // simple noise gate - experimental
|
||||
expAdjF = (expAdjF <= soundSquelch) ? 0: expAdjF; // simple noise gate
|
||||
if ((soundSquelch == 0) && (expAdjF < 0.25f)) expAdjF = 0; // do something meaningfull when "squelch = 0"
|
||||
|
||||
@@ -1148,7 +1155,7 @@ class AudioReactive : public Usermod {
|
||||
break;
|
||||
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
case 5:
|
||||
DEBUGSR_PRINT(F("AR: I2S PDM Microphone - ")); DEBUGSR_PRINTLN(F(I2S_MIC_CHANNEL_TEXT));
|
||||
DEBUGSR_PRINT(F("AR: I2S PDM Microphone - ")); DEBUGSR_PRINTLN(F(I2S_PDM_MIC_CHANNEL_TEXT));
|
||||
audioSource = new I2SSource(SAMPLE_RATE, BLOCK_SIZE, true, 1.0f/4.0f);
|
||||
delay(100);
|
||||
if (audioSource) audioSource->initialize(i2swsPin, i2ssdPin);
|
||||
|
||||
@@ -76,11 +76,15 @@
|
||||
#ifdef I2S_USE_RIGHT_CHANNEL
|
||||
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
|
||||
#define I2S_MIC_CHANNEL_TEXT "right channel only (work-around swapped channel bug in IDF 4.4)."
|
||||
#define I2S_PDM_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_RIGHT
|
||||
#define I2S_PDM_MIC_CHANNEL_TEXT "right channel only"
|
||||
#else
|
||||
//#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ALL_LEFT
|
||||
//#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_RIGHT_LEFT
|
||||
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_RIGHT
|
||||
#define I2S_MIC_CHANNEL_TEXT "left channel only (work-around swapped channel bug in IDF 4.4)."
|
||||
#define I2S_PDM_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
|
||||
#define I2S_PDM_MIC_CHANNEL_TEXT "left channel only."
|
||||
#endif
|
||||
|
||||
#else
|
||||
@@ -92,6 +96,9 @@
|
||||
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
|
||||
#define I2S_MIC_CHANNEL_TEXT "left channel only."
|
||||
#endif
|
||||
#define I2S_PDM_MIC_CHANNEL I2S_MIC_CHANNEL
|
||||
#define I2S_PDM_MIC_CHANNEL_TEXT I2S_MIC_CHANNEL_TEXT
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -212,7 +219,7 @@ class I2SSource : public AudioSource {
|
||||
// data line, to make it simpler to debug, use the WS pin as CLK and SD
|
||||
// pin as DATA
|
||||
_config.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); // Change mode to pdm if clock pin not provided. PDM is not supported on ESP32-S2. PDM RX not supported on ESP32-C3
|
||||
_config.channel_format =I2S_CHANNEL_FMT_ONLY_LEFT; // seems that PDM mono mode always uses left channel.
|
||||
_config.channel_format =I2S_PDM_MIC_CHANNEL; // seems that PDM mono mode always uses left channel.
|
||||
//_config.use_apll = true; // experimental - use aPLL clock source to improve sampling quality
|
||||
//_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT; // not needed
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user