From 4560e92424617f124ada301975f7591b848a3e2d Mon Sep 17 00:00:00 2001 From: Andrew Tuline Date: Wed, 27 Oct 2021 08:24:21 -0700 Subject: [PATCH] Updating i2s_read thanks to tavdog and s-marley. --- wled00/audio_reactive.h | 12 ++++++------ wled00/usermod.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/wled00/audio_reactive.h b/wled00/audio_reactive.h index b965c29333..2b10894dd2 100644 --- a/wled00/audio_reactive.h +++ b/wled00/audio_reactive.h @@ -282,14 +282,14 @@ void FFTcode( void * parameter) { for(int i=0; i> 2; // Analog Read } else { int32_t digitalSample = 0; - // TODO: I2S_POP_SAMLE DEPRECATED, FIND ALTERNATE SOLUTION - int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&digitalSample, portMAX_DELAY); // no timeout - if (bytes_read > 0) { - micData = abs(digitalSample >> 16); - } + size_t bytes_read = 0; + esp_err_t result = i2s_read(I2S_PORT, &digitalSample, sizeof(digitalSample), &bytes_read, /*portMAX_DELAY*/ 10); + //int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&digitalSample, portMAX_DELAY); // no timeout + if (bytes_read > 0) micData = abs(digitalSample >> 16); + } micDataSm = ((micData * 3) + micData)/4; // We'll be passing smoothed micData to the volume routines as the A/D is a bit twitchy. vReal[i] = micData; // Store Mic Data in an array diff --git a/wled00/usermod.cpp b/wled00/usermod.cpp index aa24255430..4568ca389d 100644 --- a/wled00/usermod.cpp +++ b/wled00/usermod.cpp @@ -56,10 +56,15 @@ void userSetup() { float mean = 0.0; int32_t samples[BLOCK_SIZE]; // TODO: I2S_READ_BYTES DEPRECATED, FIND ALTERNATE SOLUTION -int num_bytes_read = i2s_read_bytes(I2S_PORT, + size_t num_bytes_read = 0; + + esp_err_t result = i2s_read(I2S_PORT, &samples, BLOCK_SIZE, &num_bytes_read, portMAX_DELAY); + +/*int num_bytes_read = i2s_read_bytes(I2S_PORT, (char *)samples, BLOCK_SIZE, // the doc says bytes, but its elements. portMAX_DELAY); // no timeout +*/ int samples_read = num_bytes_read / 8; if (samples_read > 0) { @@ -72,7 +77,7 @@ if (samples_read > 0) { digitalMic = true; } else { Serial.println("Digital microphone is NOT present."); - analogReadResolution(10); // Default is 12, which is less linear. We're also only using 10 bits as a result of our ESP8266 history. + // analogReadResolution(10); // Default is 12, which is less linear. We're also only using 10 bits as a result of our ESP8266 history. } }