From d49b10a8022f945f950cb7371cf26569d0671f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 3 Jun 2016 14:39:36 +0200 Subject: [PATCH] adjustments --- project/mode_audio.c | 43 ++++++++++--------------------------------- project/mode_life.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/project/mode_audio.c b/project/mode_audio.c index 85c4d98..dff3bd4 100644 --- a/project/mode_audio.c +++ b/project/mode_audio.c @@ -15,7 +15,7 @@ static volatile bool capture_pending = false; union samp_buf_union { uint32_t uints[SAMP_BUF_LEN]; float floats[SAMP_BUF_LEN]; - uint8_t as_bytes[SAMP_BUF_LEN*sizeof(uint32_t)]; + uint8_t as_bytes[SAMP_BUF_LEN * sizeof(uint32_t)]; }; // sample buffers (static - invalidated when sampling starts anew). @@ -34,7 +34,7 @@ static void boot_animation(void) dmtx_clear(dmtx); // Boot animation (for FFT) - for(int i = 0; i < 16; i++) { + for (int i = 0; i < 16; i++) { dmtx_set(dmtx, i, 0, 1); dmtx_show(dmtx); delay_ms(20); @@ -116,8 +116,8 @@ static void audio_capture_done(void* unused) return; } - const int samp_count = SAMP_BUF_LEN/2; - const int bin_count = SAMP_BUF_LEN/4; + const int samp_count = SAMP_BUF_LEN / 2; + const int bin_count = SAMP_BUF_LEN / 4; float *bins = samp_buf.floats; @@ -134,14 +134,6 @@ static void audio_capture_done(void* unused) samp_buf.floats[i] -= mean; } -// if (print_next_fft) { -// printf("--- Raw (adjusted) ---\n"); -// for(int i = 0; i < samp_count; i++) { -// printf("%.2f, ", samp_buf.floats[i]); -// } -// printf("\n"); -// } - for (int i = samp_count - 1; i >= 0; i--) { bins[i * 2 + 1] = 0; // imaginary bins[i * 2] = samp_buf.floats[i]; // real @@ -153,35 +145,20 @@ static void audio_capture_done(void* unused) arm_cfft_f32(S, bins, 0, true); // bit reversed FFT arm_cmplx_mag_f32(bins, bins, bin_count); // get magnitude (extract real values) -// if (print_next_fft) { -// printf("--- Bins ---\n"); -// for(int i = 0; i < bin_count; i++) { -// printf("%.2f, ", bins[i]); -// } -// printf("\n"); -// } - // normalize dmtx_clear(dmtx); - float factor = (1.0f/bin_count)*0.3f; - for(int i = 0; i < bin_count-1; i+=2) { - bins[i] *= factor; - bins[i+1] *= factor; - //float avg = i==0 ? bins[1] : (bins[i] + bins[i+1])/2; - float avg = (bins[i] + bins[i+1])/2; + float factor = (1.0f / bin_count) * 0.25f; + for (int i = 0; i < bin_count; i++) { + bins[i] *= factor; - for(int j = 0; j < 1+floorf(avg); j++) { - //dmtx_toggle(dmtx, i/2, j); - dmtx_toggle(dmtx, i/2, j); - //dmtx_toggle(dmtx, j, 15-i/2); - //dmtx_toggle(dmtx, 15- i/2, 15-j); + for (int j = 0; j < 1 + floorf(bins[i]); j++) { + dmtx_set(dmtx, i - 1, j, 1); // hide zero 0th bin } } dmtx_show(dmtx); -// print_next_fft = false; capture_pending = false; } @@ -194,5 +171,5 @@ void capture_audio(void *unused) capture_pending = true; - start_adc_dma(samp_buf.uints, SAMP_BUF_LEN/2); + start_adc_dma(samp_buf.uints, SAMP_BUF_LEN / 2); } diff --git a/project/mode_life.c b/project/mode_life.c index 4d278de..b641bcc 100644 --- a/project/mode_life.c +++ b/project/mode_life.c @@ -36,8 +36,8 @@ static ms_time_t step_time = 200; // game step time #define BLINKLEN_ONE 300 // blink on time for '1' #define BLINKLEN_ZERO 10 // blink on time for '0' -#define MOVE_TIME 100 // mouse move -#define MOVE_START_TIME 700 +#define MOVE_TIME 80 // mouse move +#define MOVE_START_TIME 600 #define WRAPPING 0 @@ -322,7 +322,7 @@ void mode_life_btn(char key) case 'K': // Reset btn - if (modA_down) { + if (modB_down) { // total reset dbg("Reset to blank"); memset(board_orig, 0, SIZEOF_BOARD); @@ -344,14 +344,14 @@ void mode_life_btn(char key) if (running) { switch (key) { - case 'X': // slower + case 'Y': // slower if (step_time < 1000) { step_time += 50; set_periodic_task_interval(task_gametick, step_time); } break; - case 'Y': // faster + case 'X': // faster if (step_time > 50) { step_time -= 50; set_periodic_task_interval(task_gametick, step_time); @@ -425,10 +425,10 @@ void mode_life_btn(char key) // --- Paint BTN --- - case 'Y': painting_1 = true; break; - case 'y': painting_1 = false; break; - case 'X': painting_0 = true; break; - case 'x': painting_0 = false; break; + case 'X': painting_1 = true; break; + case 'x': painting_1 = false; break; + case 'Y': painting_0 = true; break; + case 'y': painting_0 = false; break; // --- Control ---