Skip to content

Commit

Permalink
Merge pull request #16 from THATDONFC/Chris
Browse files Browse the repository at this point in the history
Merge THATDONFC/WLED-Chris into THATDONFC/WLED-master
  • Loading branch information
THATDONFC authored May 12, 2020
2 parents ac92e13 + b668e79 commit 5041a38
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 292 deletions.
2 changes: 1 addition & 1 deletion wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3930,7 +3930,7 @@ uint16_t WS2812FX::mode_asound13(void) {
// Serial.print(sampleAvg); Serial.print(" "); Serial.println(fftBin[6]);

// fftBin version with simple math.
if (fftBin[6] > sampleAvg*100 & millis() > (oldPeak + 300)) {
if ((fftBin[6] > sampleAvg*100) & (millis() > (oldPeak + 300))) {
setPixelColor(10, 255,0,0);
} else {
setPixelColor(10, 0,0,0);
Expand Down
65 changes: 28 additions & 37 deletions wled00/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
*/

#ifndef ESP8266
TaskHandle_t FFT_Task;
TaskHandle_t FFT_Task;
#endif

//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t)

#ifdef ESP8266
#define MIC_PIN A0
#define MIC_PIN A0
#else
#define MIC_PIN 36 // Changed to directly naming pin since ESP32 has multiple ADCs 8266: A0 ESP32: 36(ADC1_0) Analog port for microphone
#define MIC_PIN 36 // Changed to directly naming pin since ESP32 has multiple ADCs 8266: A0 ESP32: 36(ADC1_0) Analog port for microphone
#ifndef LED_BUILTIN
// Set LED_BUILTIN if it is not defined by Arduino framework
#define LED_BUILTIN 3
#endif
#endif

// As defined in wled00.ino
// byte soundSquelch = 10; //default squelch value for volume reactive routines.

// uint8_t squelch = 10; // Anything below this is background noise, so we'll make it '0'. Can be adjusted
// As defined in wled00.h
// byte soundSquelch = 10; // default squelch value for volume reactive routines
// uint16_t noiseFloor = 100; // default squelch value for FFT reactive routines

int micIn; // Current sample starts with negative values and large values, which is why it's 16 bit signed
int sample; // Current sample
Expand All @@ -47,47 +46,43 @@ uint8_t myVals[32]; // Used to store a


#ifndef ESP8266
#include "arduinoFFT.h"
//#include "movingAvg.h"

// Create FFT object
arduinoFFT FFT = arduinoFFT();
#include "arduinoFFT.h"
//#include "movingAvg.h"

const uint16_t samples = 512; //This value MUST ALWAYS be a power of 2
const double samplingFrequency = 10240;
arduinoFFT FFT = arduinoFFT(); // Create FFT object

unsigned int sampling_period_us;
unsigned long microseconds;
const uint16_t samples = 512; // This value MUST ALWAYS be a power of 2
const double samplingFrequency = 10240; // Sampling frequency

/*
These are the input and output vectors
Input vectors receive computed results from FFT
*/
double fftBin[samples];
double vReal[samples];
double vImag[samples];
unsigned int sampling_period_us;
unsigned long microseconds;

/*
These are the input and output vectors
Input vectors receive computed results from FFT
*/
double fftBin[samples];
double vReal[samples];
double vImag[samples];
#endif

uint16_t lastSample; // last audio noise sample
uint16_t lastSample; // last audio noise sample

void getSample() {

static long peakTime;

#ifdef WLED_DISABLE_SOUND
micIn = inoise8(millis(), millis()); // Simulated analog read
micIn = inoise8(millis(), millis()); // Simulated analog read
#else
#ifdef ESP32
micIn = micData;
micIn = micIn >> 2; // ESP32 has 2 more bits of A/D, so we need to normalize
micIn = micData;
micIn = micIn >> 2; // ESP32 has 2 more bits of A/D, so we need to normalize
#endif
#ifdef ESP8266
micIn = analogRead(MIC_PIN); // Poor man's analog read
micIn = analogRead(MIC_PIN); // Poor man's analog read
#endif
#endif


micLev = ((micLev * 31) + micIn) / 32; // Smooth it out over the last 32 samples for automatic centering
micIn -= micLev; // Let's center it to 0 now
micIn = abs(micIn); // And get the absolute value of each sample
Expand Down Expand Up @@ -160,7 +155,6 @@ void FFTcode( void * parameter) {
double envelope = 0;
uint16_t rawMicData = 0;


for(;;) {
delay(1); // DO NOT DELETE THIS LINE! It is needed to give the IDLE(0) task enough time and to keep the watchdog happy.
microseconds = micros();
Expand All @@ -175,20 +169,17 @@ void FFTcode( void * parameter) {

// rawMicData = rawMicData - mAvg; // center
// beatSample = bassFilter(rawMicData);
// if (beatSample < 0) beatSample =-beatSample; // abs
// if (beatSample < 0) beatSample =-beatSample; // abs
// envelope = envelopeFilter(beatSample);


while(micros() - microseconds < sampling_period_us){
//empty loop
}
microseconds += sampling_period_us;
}

// beat = beatFilter(envelope);
//if (beat > 50000) digitalWrite(LED_BUILTIN, HIGH); else digitalWrite(LED_BUILTIN, LOW);


// beat = beatFilter(envelope);
// if (beat > 50000) digitalWrite(LED_BUILTIN, HIGH); else digitalWrite(LED_BUILTIN, LOW);

FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD); // Weigh data
FFT.Compute(vReal, vImag, samples, FFT_FORWARD); // Compute FFT
Expand Down
23 changes: 12 additions & 11 deletions wled00/data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@
transition: 0.7s;
pointer-events: none;
}

/* Keep sliders on top when scrolling
Effect Speed */
.staytop {
display: block;
position: -webkit-sticky;
Expand All @@ -276,25 +277,25 @@
z-index: 1;
margin-top: 1px;
}

/* Effect Intensity */
#staytop1 {
top: 29px;
top: 30px;
}

/* FFT Low */
#staytop2 {
top: 58px;
top: 60px;
}

/* FFT High */
#staytop3 {
top: 87px;
top: 90px;
}

/* FFT Custom */
#staytop4 {
top: 116px;
top: 120px;
}

/* Solid Effect Mode */
#staytop5 {
top: 145px;
top: 150px;
}

#toast {
Expand Down
9 changes: 7 additions & 2 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ void alexaInit();
void handleAlexa();
void onAlexaChange(EspalexaDevice* dev);

//audio_reactive.cpp // Which functions do we declare here???
//void agcAvg();
//void FFTcode(void * parameter);
//void getSample();

//blynk.cpp
void initBlynk(const char* auth);
void handleBlynk();
Expand Down Expand Up @@ -106,7 +111,7 @@ void publishMqtt();
//ntp.cpp
void handleNetworkTime();
void sendNTPPacket();
bool checkNTPResponse();
bool checkNTPResponse();
void updateLocalTime();
void getTimeString(char* out);
bool checkCountdown();
Expand All @@ -123,7 +128,7 @@ void _overlayAnalogClock();

byte getSameCodeLength(char code, int index, char const cronixieDisplay[]);
void setCronixie();
void _overlayCronixie();
void _overlayCronixie();
void _drawOverlayCronixie();

//set.cpp
Expand Down
Loading

0 comments on commit 5041a38

Please sign in to comment.