Skip to content

Commit

Permalink
BROKEN VERSION: Improved Tempo detection using FFT instead of GDFT data
Browse files Browse the repository at this point in the history
  • Loading branch information
connornishijima committed Jun 8, 2024
1 parent 51d5216 commit 7d19262
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void load_config(){
strcpy(configuration.softness.ui_type_string, "s");
configuration.softness.type = f32;
configuration.softness.ui_type = ui_type_slider;
configuration.softness.value.f32 = 0.25;
configuration.softness.value.f32 = 0.0;
//configuration.softness.value.f32 = preferences.getFloat(configuration.softness.name, 0.25);

// Color
Expand Down Expand Up @@ -103,8 +103,7 @@ void load_config(){
strcpy(configuration.background.ui_type_string, "s");
configuration.background.type = f32;
configuration.background.ui_type = ui_type_slider;
configuration.background.value.f32 = 0.2
;
configuration.background.value.f32 = 0.0;
//configuration.background.value.f32 = preferences.getFloat(configuration.background.name, 0.25);

// Current Mode
Expand Down
2 changes: 1 addition & 1 deletion src/global_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define NUM_TEMPI (96)

// BPM range
#define TEMPO_LOW (32)
#define TEMPO_LOW (48)
#define TEMPO_HIGH (TEMPO_LOW + NUM_TEMPI)

// How far forward or back in time the beat phase is shifted
Expand Down
6 changes: 3 additions & 3 deletions src/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ void draw_line(CRGBF* layer, float x1, float x2, CRGBF color, float opacity) {
layer[i].b += color.b * mix;
} else {
// Blend mode: Mix color
layer[i].r = layer[i].r * (1.0 - mix) + color.r * mix;
layer[i].g = layer[i].g * (1.0 - mix) + color.g * mix;
layer[i].b = layer[i].b * (1.0 - mix) + color.b * mix;
//layer[i].r = layer[i].r * (1.0 - mix) + color.r * mix;
//layer[i].g = layer[i].g * (1.0 - mix) + color.g * mix;
//layer[i].b = layer[i].b * (1.0 - mix) + color.b * mix;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/light_modes/active/metronome.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void draw_metronome() {
metronome_width = 1.0;
}

float dot_pos = clip_float( sine * (0.5*(sqrt((contribution))) * metronome_width) + 0.5 );
float dot_pos = clip_float( sine * (0.5*(sqrt(sqrt((contribution)))) * metronome_width) + 0.5 );

float opacity = clip_float(contribution*2.0);

Expand Down
7 changes: 5 additions & 2 deletions src/microphone.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ __attribute__((aligned(16)))
float fft_output[FFT_SIZE];

__attribute__((aligned(16)))
float fft_max[FFT_SIZE];+*
float fft_max[FFT_SIZE];

void perform_fft(){
memset(fft_input_complex, 0, sizeof(float) * (FFT_SIZE << 1));

const uint8_t step_size = 4;
const uint8_t step_size = 3;
for(uint16_t i = 0; i < FFT_SIZE; i++){
fft_input[i] = sample_history[((SAMPLE_HISTORY_LENGTH-1) - (FFT_SIZE*step_size)) + i*step_size ];
}
Expand All @@ -73,9 +73,12 @@ void perform_fft(){

// Calculate the magnitude of the complex numbers and convert to 0.0 to 1.0 range
for (uint16_t i = 0 ; i < FFT_SIZE; i++) {
float progress = (float)i / FFT_SIZE;
float real = fft_input_complex[i << 1];
float imag = fft_input_complex[(i << 1) + 1];
fft_output[i] = sqrtf(real * real + imag * imag) / (FFT_SIZE >> 1);
fft_output[i] = fft_output[i]*(0.5+0.5*progress);

fft_max[i] = fmaxf(fft_max[i], fft_output[i]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tempo.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ void calculate_tempi_magnitudes(int16_t single_bin = -1) {
}
}

if (max_val < 0.02) {
max_val = 0.02;
if (max_val < 0.01) {
max_val = 0.01;
}

float autoranger_scale = 1.0 / (max_val);
Expand Down

0 comments on commit 7d19262

Please sign in to comment.