Skip to content

Commit a0967d6

Browse files
committed
vfx_core: fix compute_freq error
1 parent 04c99cf commit a0967d6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

main/src/user/vfx.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void vfx_task(void *pvParameter)
154154
xEventGroupSetBits(user_event_group, VFX_FFT_IDLE_BIT);
155155
}
156156

157-
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor * 4, vfx_disp_height, 1);
157+
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor, vfx_disp_height, 1);
158158

159159
if (vfx.mode == VFX_MODE_IDX_SPECTRUM_R_N) {
160160
color_h = 0;
@@ -253,7 +253,7 @@ static void vfx_task(void *pvParameter)
253253
xEventGroupSetBits(user_event_group, VFX_FFT_IDLE_BIT);
254254
}
255255

256-
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor * 2, vfx_disp_height, 0);
256+
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor, vfx_disp_height / 2, 0);
257257

258258
if (vfx.mode == VFX_MODE_IDX_SPECTRUM_R_L) {
259259
color_h = 0;
@@ -379,9 +379,9 @@ static void vfx_task(void *pvParameter)
379379
}
380380

381381
if (vfx.mode == VFX_MODE_IDX_SPECTRUM_M_N) {
382-
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor * 4, vu_val_max, 0);
382+
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor, vu_val_max, 0);
383383
} else {
384-
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor * 4, vu_val_max, 0);
384+
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor, vu_val_max, 0);
385385
}
386386

387387
for (uint8_t i = vu_idx_min; i <= vu_idx_max; i++) {
@@ -896,9 +896,9 @@ static void vfx_task(void *pvParameter)
896896
}
897897

898898
if (vfx.mode == VFX_MODE_IDX_FOUNTAIN_S_N || vfx.mode == VFX_MODE_IDX_FOUNTAIN_G_N) {
899-
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor * 4, canvas_height, 1);
899+
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor, canvas_height, 1);
900900
} else {
901-
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor * 4, canvas_height, 1);
901+
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor, canvas_height, 1);
902902
}
903903

904904
if (vfx.mode == VFX_MODE_IDX_FOUNTAIN_S_N || vfx.mode == VFX_MODE_IDX_FOUNTAIN_S_L) {
@@ -1013,9 +1013,9 @@ static void vfx_task(void *pvParameter)
10131013
}
10141014

10151015
if (vfx.mode == VFX_MODE_IDX_FOUNTAIN_H_N) {
1016-
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor * 4, canvas_height, 1);
1016+
vfx_compute_freq_lin(vfx_fft_output, fft_out, vfx.scale_factor, canvas_height, 1);
10171017
} else {
1018-
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor * 4, canvas_height, 1);
1018+
vfx_compute_freq_log(vfx_fft_output, fft_out, vfx.scale_factor, canvas_height, 1);
10191019
}
10201020

10211021
for (uint16_t i = 0; i < canvas_width; i++) {

main/src/user/vfx_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void vfx_draw_layer_number(uint8_t num, uint8_t layer, float color_h, float colo
232232

233233
void vfx_compute_freq_lin(const float *data_in, uint16_t *data_out, uint16_t scale_factor, uint16_t max_val, uint16_t min_val)
234234
{
235-
data_out[0] += sqrt(pow(data_in[0], 2) + pow(data_in[1], 2)) / FFT_N * (max_val * scale_factor / 65535.0);
235+
data_out[0] += sqrt(pow(data_in[0], 2) + pow(data_in[1], 2)) / FFT_N * (max_val * scale_factor / 32768.0);
236236
data_out[0] /= 2;
237237
if (data_out[0] > max_val) {
238238
data_out[0] = max_val;
@@ -241,7 +241,7 @@ void vfx_compute_freq_lin(const float *data_in, uint16_t *data_out, uint16_t sca
241241
}
242242

243243
for (uint16_t k = 1; k < FFT_N / 2; k++) {
244-
data_out[k] += sqrt(pow(vfx_fft_output[2 * k], 2) + pow(vfx_fft_output[2 * k + 1], 2)) / FFT_N * (max_val * scale_factor / 65535.0);
244+
data_out[k] += sqrt(pow(vfx_fft_output[2 * k], 2) + pow(vfx_fft_output[2 * k + 1], 2)) / FFT_N * 2 * (max_val * scale_factor / 32768.0);
245245
data_out[k] /= 2;
246246
if (data_out[k] > max_val) {
247247
data_out[k] = max_val;
@@ -253,7 +253,7 @@ void vfx_compute_freq_lin(const float *data_in, uint16_t *data_out, uint16_t sca
253253

254254
void vfx_compute_freq_log(const float *data_in, uint16_t *data_out, uint16_t scale_factor, uint16_t max_val, uint16_t min_val)
255255
{
256-
data_out[0] += 20 * log10(1 + sqrt(pow(data_in[0], 2) + pow(data_in[1], 2)) / FFT_N) * (max_val * scale_factor / 65535.0);
256+
data_out[0] += 20 * log10(1 + sqrt(pow(data_in[0], 2) + pow(data_in[1], 2)) / FFT_N) * (max_val * scale_factor / 32768.0);
257257
data_out[0] /= 2;
258258
if (data_out[0] > max_val) {
259259
data_out[0] = max_val;
@@ -262,7 +262,7 @@ void vfx_compute_freq_log(const float *data_in, uint16_t *data_out, uint16_t sca
262262
}
263263

264264
for (uint16_t k = 1; k < FFT_N / 2; k++) {
265-
data_out[k] += 20 * log10(1 + sqrt(pow(data_in[2 * k], 2) + pow(data_in[2 * k + 1], 2)) / FFT_N * 2) * (max_val * scale_factor / 65535.0);
265+
data_out[k] += 20 * log10(1 + sqrt(pow(data_in[2 * k], 2) + pow(data_in[2 * k + 1], 2)) / FFT_N * 2) * (max_val * scale_factor / 32768.0);
266266
data_out[k] /= 2;
267267
if (data_out[k] > max_val) {
268268
data_out[k] = max_val;

0 commit comments

Comments
 (0)