transience entfernt
This commit is contained in:
parent
10f616582c
commit
183b10ef0f
@ -65,7 +65,7 @@ int rounds = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.begin(250000);
|
||||
|
||||
FastLED.addLeds<WS2812, LED_PIN, RGB>(leds, NUM_LEDS);
|
||||
FastLED.setMaxPowerInVoltsAndMilliamps(5, 300);
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "zauberstab.h"
|
||||
#include <algorithm>
|
||||
|
||||
#undef NUM_LEDS
|
||||
#define NUM_LEDS 45
|
||||
|
||||
#define SAMPLING_FREQUENCY_BP 40 // number of energy chunks per second
|
||||
#define SAMPLING_FREQUENCY_CONTROL 1 // check number of times per second if the current band pass is the best one
|
||||
#define Q 20. // quality factor of band pass filters
|
||||
@ -34,8 +37,6 @@ static float u1[n_BP];
|
||||
static float u2[n_BP];
|
||||
static float y[n_BP];
|
||||
static float y_fil[n_BP];
|
||||
static float y_fil_avg;
|
||||
static float transience = 0;
|
||||
|
||||
static float angle;
|
||||
static float angle2;
|
||||
@ -45,14 +46,16 @@ static float angle2;
|
||||
static float pos_target = NUM_LEDS / 2;
|
||||
static float pos_target_filtered = NUM_LEDS / 2;
|
||||
|
||||
static float microphone_offset = 675;
|
||||
static float microphone_offset = 1900;
|
||||
static long initial_time;
|
||||
|
||||
static int active = 15;
|
||||
static int candidate = 15;
|
||||
static int rounds = 0;
|
||||
|
||||
static float get_value(int pos, float pos0)
|
||||
static int n_samples = 0;
|
||||
|
||||
static int get_value(int pos, float pos0)
|
||||
{
|
||||
if (abs(pos0 - pos) > 5)
|
||||
{
|
||||
@ -83,23 +86,27 @@ static void set_filter()
|
||||
void setup()
|
||||
{
|
||||
zauberstab_init();
|
||||
Serial.begin(115200);
|
||||
Serial.begin(250000);
|
||||
set_filter();
|
||||
initial_time = micros();
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
|
||||
int sample = int(analogRead(MIC_PIN) - microphone_offset);
|
||||
energy += abs(sample) * abs(sample);
|
||||
n_samples++;
|
||||
|
||||
if (micros() - last_us_bp > sampling_period_bp)
|
||||
{
|
||||
Serial.println(sample);
|
||||
Serial.println(n_samples);
|
||||
n_samples = 0;
|
||||
|
||||
microphone_offset += (analogRead(MIC_PIN) - microphone_offset) * 0.001;
|
||||
last_us_bp += sampling_period_bp;
|
||||
//energy_fil += (energy - energy_fil) * 0.01;
|
||||
y_fil_avg = 0;
|
||||
|
||||
for (int i = 0; i < n_BP; i++)
|
||||
{
|
||||
y[i] = (b0[i] / a0[i]) * energy + 0. + (b2[i] / a0[i]) * u2[i] - (a1[i] / a0[i]) * yy1[i] - (a2[i] / a0[i]) * yy2[i];
|
||||
@ -112,9 +119,8 @@ void loop()
|
||||
yy2[i] = yy1[i];
|
||||
yy1[i] = y[i];
|
||||
y_fil[i] += (abs(y[i]) - y_fil[i]) * 0.005; //linie der scheitelpunkte
|
||||
y_fil_avg += y_fil[i];
|
||||
|
||||
}
|
||||
y_fil_avg /= n_BP;
|
||||
|
||||
float delays = constrain(SAMPLING_FREQUENCY_BP * 0.25 / (1.75 + active * (2.4 - 1.75) / n_BP), 4., 6.);
|
||||
|
||||
@ -152,15 +158,12 @@ void loop()
|
||||
|
||||
energy = 0;
|
||||
|
||||
transience += ((y_fil[active]/y_fil_avg-1.6) - transience)*0.02;
|
||||
transience = max(transience, 0.0f);
|
||||
transience = min(transience, 1.0f);
|
||||
|
||||
for (int i = 0; i < NUM_LEDS; i++)
|
||||
{
|
||||
leds[i].g = int(get_value(i, pos_target_filtered)*transience);
|
||||
leds[i].r = int(get_value(i, pos_target_filtered+2)*transience);
|
||||
leds[i].b = int(get_value(i, pos_target_filtered-2)*transience);
|
||||
leds[i].g = get_value(i, pos_target_filtered);
|
||||
leds[i].r = get_value(i, pos_target_filtered+2);
|
||||
leds[i].b = get_value(i, pos_target_filtered-2);
|
||||
|
||||
|
||||
//leds[i].setRGB(brightness_red, brightness_green, brightness_blue);
|
||||
//leds[i].setHSV(160, (rounds == 6) ? 0xFF : 0, brightness);
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user