Merge remote-tracking branch 'origin/audioreactive-prototype' into audio-reactive

This commit is contained in:
Frank
2022-10-04 14:00:53 +02:00
2 changed files with 35 additions and 18 deletions

View File

@@ -213,6 +213,7 @@ void FFTcode(void * parameter)
#if defined(WLED_DEBUG) || defined(SR_DEBUG) #if defined(WLED_DEBUG) || defined(SR_DEBUG)
uint64_t start = esp_timer_get_time(); uint64_t start = esp_timer_get_time();
bool haveDoneFFT = false; // indicates if second measurement (FFT time) is valid
#endif #endif
// get a fresh batch of samples from I2S // get a fresh batch of samples from I2S
@@ -223,6 +224,7 @@ void FFTcode(void * parameter)
uint64_t sampleTimeInMillis = (esp_timer_get_time() - start +5ULL) / 10ULL; // "+5" to ensure proper rounding uint64_t sampleTimeInMillis = (esp_timer_get_time() - start +5ULL) / 10ULL; // "+5" to ensure proper rounding
sampleTime = (sampleTimeInMillis*3 + sampleTime*7)/10; // smooth sampleTime = (sampleTimeInMillis*3 + sampleTime*7)/10; // smooth
} }
start = esp_timer_get_time(); // start measuring FFT time
#endif #endif
xLastWakeTime = xTaskGetTickCount(); // update "last unblocked time" for vTaskDelay xLastWakeTime = xTaskGetTickCount(); // update "last unblocked time" for vTaskDelay
@@ -277,6 +279,10 @@ void FFTcode(void * parameter)
#endif #endif
FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects FFT_MajorPeak = constrain(FFT_MajorPeak, 1.0f, 11025.0f); // restrict value to range expected by effects
#if defined(WLED_DEBUG) || defined(SR_DEBUG)
haveDoneFFT = true;
#endif
} else { // noise gate closed - only clear results as FFT was skipped. MIC samples are still valid when we do this. } else { // noise gate closed - only clear results as FFT was skipped. MIC samples are still valid when we do this.
memset(vReal, 0, sizeof(vReal)); memset(vReal, 0, sizeof(vReal));
FFT_MajorPeak = 1; FFT_MajorPeak = 1;
@@ -425,7 +431,7 @@ void FFTcode(void * parameter)
} }
#if defined(WLED_DEBUG) || defined(SR_DEBUG) #if defined(WLED_DEBUG) || defined(SR_DEBUG)
if (start < esp_timer_get_time()) { // filter out overflows if (haveDoneFFT && (start < esp_timer_get_time())) { // filter out overflows
uint64_t fftTimeInMillis = ((esp_timer_get_time() - start) +5ULL) / 10ULL; // "+5" to ensure proper rounding uint64_t fftTimeInMillis = ((esp_timer_get_time() - start) +5ULL) / 10ULL; // "+5" to ensure proper rounding
fftTime = (fftTimeInMillis*3 + fftTime*7)/10; // smooth fftTime = (fftTimeInMillis*3 + fftTime*7)/10; // smooth
} }
@@ -591,21 +597,21 @@ class AudioReactive : public Usermod {
//////////////////// ////////////////////
void logAudio() void logAudio()
{ {
if (disableSoundProcessing && (!udpSyncConnected || ((audioSyncEnabled & 0x02) == 0))) return; // no audio availeable
#ifdef MIC_LOGGER #ifdef MIC_LOGGER
// Debugging functions for audio input and sound processing. Comment out the values you want to see // Debugging functions for audio input and sound processing. Comment out the values you want to see
Serial.print("micReal:"); Serial.print(micDataReal); Serial.print("\t"); Serial.print("micReal:"); Serial.print(micDataReal); Serial.print("\t");
//Serial.print("micIn:"); Serial.print(micIn); Serial.print("\t"); Serial.print("volumeSmth:"); Serial.print(volumeSmth); Serial.print("\t");
//Serial.print("micLev:"); Serial.print(micLev); Serial.print("\t"); //Serial.print("volumeRaw:"); Serial.print(volumeRaw); Serial.print("\t");
//Serial.print("sampleReal:"); Serial.print(sampleReal); Serial.print("\t"); //Serial.print("DC_Level:"); Serial.print(micLev); Serial.print("\t");
//Serial.print("sample:"); Serial.print(sample); Serial.print("\t"); //Serial.print("sampleAgc:"); Serial.print(sampleAgc); Serial.print("\t");
//Serial.print("sampleAvg:"); Serial.print(sampleAvg); Serial.print("\t"); //Serial.print("sampleAvg:"); Serial.print(sampleAvg); Serial.print("\t");
//Serial.print("sampleReal:"); Serial.print(sampleReal); Serial.print("\t");
//Serial.print("micIn:"); Serial.print(micIn); Serial.print("\t");
//Serial.print("sample:"); Serial.print(sample); Serial.print("\t");
//Serial.print("sampleMax:"); Serial.print(sampleMax); Serial.print("\t"); //Serial.print("sampleMax:"); Serial.print(sampleMax); Serial.print("\t");
//Serial.print("samplePeak:"); Serial.print((samplePeak!=0) ? 128:0); Serial.print("\t"); //Serial.print("samplePeak:"); Serial.print((samplePeak!=0) ? 128:0); Serial.print("\t");
//Serial.print("multAgc:"); Serial.print(multAgc, 4); Serial.print("\t"); //Serial.print("multAgc:"); Serial.print(multAgc, 4); Serial.print("\t");
Serial.print("sampleAgc:"); Serial.print(sampleAgc); Serial.print("\t");
//Serial.print("volumeRaw:"); Serial.print(volumeRaw); Serial.print("\t");
//Serial.print("volumeSmth:"); Serial.print(volumeSmth); Serial.print("\t");
Serial.println(); Serial.println();
#endif #endif
@@ -1198,9 +1204,11 @@ class AudioReactive : public Usermod {
} }
#if defined(MIC_LOGGER) || defined(MIC_SAMPLING_LOG) || defined(FFT_SAMPLING_LOG) #if defined(MIC_LOGGER) || defined(MIC_SAMPLING_LOG) || defined(FFT_SAMPLING_LOG)
EVERY_N_MILLIS(20) { static unsigned long lastMicLoggerTime = 0;
logAudio(); if (millis()-lastMicLoggerTime > 20) {
} lastMicLoggerTime = millis();
logAudio();
}
#endif #endif
// Info Page: keep max sample from last 5 seconds // Info Page: keep max sample from last 5 seconds
@@ -1427,11 +1435,18 @@ class AudioReactive : public Usermod {
infoArr = user.createNestedArray(F("Sampling time")); infoArr = user.createNestedArray(F("Sampling time"));
infoArr.add(float(sampleTime)/100.0f); infoArr.add(float(sampleTime)/100.0f);
infoArr.add(" ms"); infoArr.add(" ms");
infoArr = user.createNestedArray(F("FFT time")); infoArr = user.createNestedArray(F("FFT time"));
infoArr.add(float(fftTime-sampleTime)/100.0f); infoArr.add(float(fftTime)/100.0f);
infoArr.add(" ms"); if ((fftTime/100) >= FFT_MIN_CYCLE) // FFT time over budget -> I2S buffer will overflow
infoArr.add("<b style=\"color:red;\">! ms</b>");
else if ((fftTime/80 + sampleTime/80) >= FFT_MIN_CYCLE) // FFT time >75% of budget -> risk of instability
infoArr.add("<b style=\"color:orange;\"> ms!</b>");
else
infoArr.add(" ms");
DEBUGSR_PRINTF("AR Sampling time: %5.2f ms\n", float(sampleTime)/100.0f); DEBUGSR_PRINTF("AR Sampling time: %5.2f ms\n", float(sampleTime)/100.0f);
DEBUGSR_PRINTF("AR FFT time : %5.2f ms\n", float(fftTime-sampleTime)/100.0f); DEBUGSR_PRINTF("AR FFT time : %5.2f ms\n", float(fftTime)/100.0f);
#endif #endif
} }
} }

View File

@@ -204,9 +204,11 @@ void WLED::loop()
DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime); DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime);
DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime); DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime);
DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP()); DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP());
DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 30); if (loops > 0) { // avoid division by zero
DEBUG_PRINT(F("UM time[ms]: ")); DEBUG_PRINT(avgUsermodMillis/loops); DEBUG_PRINT("/");DEBUG_PRINTLN(maxUsermodMillis); DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 30);
DEBUG_PRINT(F("Strip time[ms]: ")); DEBUG_PRINT(avgStripMillis/loops); DEBUG_PRINT("/"); DEBUG_PRINTLN(maxStripMillis); DEBUG_PRINT(F("UM time[ms]: ")); DEBUG_PRINT(avgUsermodMillis/loops); DEBUG_PRINT("/");DEBUG_PRINTLN(maxUsermodMillis);
DEBUG_PRINT(F("Strip time[ms]: ")); DEBUG_PRINT(avgStripMillis/loops); DEBUG_PRINT("/"); DEBUG_PRINTLN(maxStripMillis);
}
strip.printSize(); strip.printSize();
loops = 0; loops = 0;
maxUsermodMillis = 0; maxUsermodMillis = 0;