Skip to content

Commit 4a5fb07

Browse files
Fixed VU-based novelty curve
1 parent 5d78897 commit 4a5fb07

File tree

5 files changed

+31
-102
lines changed

5 files changed

+31
-102
lines changed

src/EMOTISCOPE_FIRMWARE.ino.cpp

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/goertzel.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,26 @@ void init_goertzel_constants_musical() {
102102
}
103103

104104
void init_window_lookup() {
105-
for (uint16_t i = 0; i < 2048; i++) {
106-
float ratio = i / 4095.0;
105+
float sigma = 0.4;
107106

108-
// Hamming window
109-
//float weighing_factor = 0.54 * (1.0 - cos(TWOPI * ratio));
107+
for (uint16_t i = 0; i < 2048; i++) {
108+
float ratio = i / 2047.0;
110109

111-
// Blackman-Harris window
112-
float weighing_factor = 0.3635819 - (0.4891775 * (cos(TWOPI * ratio))) + (0.1365995 * (cos(FOURPI * ratio))) - (0.0106411 * (cos(SIXPI * ratio)));
110+
float n_minus_halfN = i - 2048 / 2;
111+
float gaussian_weighing_factor = exp(-0.5 * pow((n_minus_halfN / (sigma * 2048 / 2)), 2));
113112

114-
window_lookup[i] = weighing_factor;
115-
window_lookup[4095 - i] = weighing_factor;
116-
}
113+
// Hamming window
114+
//float weighing_factor = 0.54 * (1.0 - cos(TWOPI * ratio));
115+
116+
// Blackman-Harris window
117+
//float weighing_factor = 0.3635819 - (0.4891775 * cos(TWOPI * ratio)) + (0.1365995 * cos(FOURPI * ratio)) - (0.0106411 * cos(SIXPI * ratio));
118+
119+
// Gaussian window
120+
float weighing_factor = gaussian_weighing_factor;
121+
122+
window_lookup[i] = weighing_factor;
123+
window_lookup[4095 - i] = weighing_factor; // Mirror the value for the second half
124+
}
117125
}
118126

119127
// Function to find the median in a small array of floats

src/lightshow_modes/metronome.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void draw_metronome() {
9797
else if(sine < -1.0){ sine = -1.0; }
9898

9999
float dot_pos = clip_float( sine * (0.5*(sqrt(contribution))) + 0.5 );
100-
float opacity = sqrt(contribution);
100+
float opacity = sqrt(sqrt(contribution));
101101

102102
if(opacity > 0.0025){
103103
CRGBF dot_color = hsv(configuration.hue + configuration.hue_range*progress, configuration.saturation, 1.0);

src/tempo.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#define NOVELTY_HISTORY_LENGTH (1024) // 50 FPS for 20.48 seconds
1616
#define NOVELTY_LOG_HZ (50)
1717

18-
#define TEMPO_LOW (64-32)
19-
#define TEMPO_HIGH (192-32)
18+
#define TEMPO_LOW (64-16)
19+
#define TEMPO_HIGH (192-16)
2020

2121
#define BEAT_SHIFT_PERCENT (0.08)
2222

@@ -144,19 +144,19 @@ float calculate_magnitude_of_tempo(uint16_t tempo_bin) {
144144
float q1 = 0;
145145
float q2 = 0;
146146

147-
// float window_pos = 0.0;
147+
float window_pos = 0.0;
148148

149149
for (uint16_t i = 0; i < block_size; i++) {
150150
float progress = float(i) / block_size;
151151
float sample_novelty = novelty_curve_normalized[((NOVELTY_HISTORY_LENGTH - 1) - block_size) + i];
152152
float sample_vu = vu_curve[((NOVELTY_HISTORY_LENGTH - 1) - block_size) + i];
153153
float sample = (sample_novelty + sample_vu) / 2.0;
154154

155-
float q0 = tempi[tempo_bin].coeff * q1 - q2 + sample_novelty;
155+
float q0 = tempi[tempo_bin].coeff * q1 - q2 + (sample * window_lookup[uint32_t(window_pos)]);
156156
q2 = q1;
157157
q1 = q0;
158158

159-
// window_pos += tempi[tempo_bin].window_step;
159+
window_pos += tempi[tempo_bin].window_step;
160160
}
161161

162162
float real = (q1 - q2 * tempi[tempo_bin].cosine);
@@ -180,7 +180,7 @@ float calculate_magnitude_of_tempo(uint16_t tempo_bin) {
180180
float progress = 1.0 - (tempo_bin / float(NUM_TEMPI));
181181
progress *= progress;
182182

183-
float scale = (0.75 * progress) + 0.25;
183+
float scale = (0.5 * progress) + 0.5;
184184

185185
normalized_magnitude *= scale;
186186
}, __func__ );
@@ -350,7 +350,7 @@ void update_novelty() {
350350

351351
float current_novelty = 0.0;
352352
for (uint16_t i = 0; i < NUM_FREQS; i++) {
353-
float new_mag = frequencies_musical[i].magnitude; // sqrt(sqrt(frequencies[i].magnitude));
353+
float new_mag = spectrogram_smooth[i]; // sqrt(sqrt(frequencies[i].magnitude));
354354
frequencies_musical[i].novelty = max(0.0f, new_mag - frequencies_musical[i].magnitude_last);
355355
frequencies_musical[i].magnitude_last = new_mag;
356356

@@ -361,7 +361,9 @@ void update_novelty() {
361361
check_silence(current_novelty);
362362

363363
log_novelty(current_novelty);
364-
log_vu(vu_level);
364+
365+
log_vu(vu_max);
366+
vu_max = 0.000001;
365367
}
366368
}
367369

src/vu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
volatile float vu_level_raw = 0.0;
22
volatile float vu_level = 0.0;
3+
volatile float vu_max = 0.0;
34

45
void run_vu(){
56
static float max_amplitude_cap = 0.0000001;
@@ -34,4 +35,6 @@ void run_vu(){
3435

3536
float mix_speed = 0.25;
3637
vu_level = vu_level_raw * mix_speed + vu_level*(1.0-mix_speed);
38+
39+
vu_max = max(vu_max, vu_level);
3740
}

0 commit comments

Comments
 (0)