Skip to content

Commit

Permalink
Updating i2s_read thanks to tavdog and s-marley.
Browse files Browse the repository at this point in the history
  • Loading branch information
atuline committed Oct 27, 2021
1 parent 2edbbcf commit 4560e92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 6 additions & 6 deletions wled00/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ void FFTcode( void * parameter) {

for(int i=0; i<samples; i++) {
if ((digitalMic && dmEnabled) == false) {
micData = analogRead(audioPin); // Analog Read
micData = analogRead(audioPin) >> 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
Expand Down
9 changes: 7 additions & 2 deletions wled00/usermod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
}
}

Expand Down

0 comments on commit 4560e92

Please sign in to comment.