Compare commits

..

No commits in common. 'log' and 'master' have entirely different histories.
log ... master

  1. 2
      Src/tim.c
  2. 72
      User/user_main.c

@ -50,7 +50,7 @@ void MX_TIM3_Init(void)
htim3.Instance = TIM3; htim3.Instance = TIM3;
htim3.Init.Prescaler = 0; htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 1800; // MX: changed from 1800 htim3.Init.Period = 3600; // MX: changed from 1800
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_OC_Init(&htim3) != HAL_OK) if (HAL_TIM_OC_Init(&htim3) != HAL_OK)
{ {

@ -23,7 +23,6 @@
#define SCREEN_W 32 #define SCREEN_W 32
#define SCREEN_H 16 #define SCREEN_H 16
#define DEFAULT_BRIGHTNESS 2
// Pins // Pins
#define BTN_CENTER 0 #define BTN_CENTER 0
@ -33,16 +32,9 @@
#define BTN_DOWN 4 #define BTN_DOWN 4
// Y axis scaling factors // Y axis scaling factors
#define WAVEFORM_SCALE 0.02 #define WAVEFORM_SCALE 0.007f
#define FFT_PRELOG_SCALE 1.0 #define FFT_SCALE 0.25f * 0.3f
#define FFT_FINAL_SCALE 3.0 #define FFT_SPINDLE_SCALE_MULT 0.5f
#define FFT_PREFFT_SCALE 0.4
#define VOL_STEP_TIME 50
#define VOL_STEP 0.05
#define VOL_STEP_LARGE 0.75
#define VOL_STEP_THRESH 0.01
#define VOL_STEP_SPEEDUP_TIME 750
uint32_t audio_samples[SAMPLE_COUNT * 2]; // 2x size needed for complex FFT uint32_t audio_samples[SAMPLE_COUNT * 2]; // 2x size needed for complex FFT
float *audio_samples_f = (float *) audio_samples; float *audio_samples_f = (float *) audio_samples;
@ -50,7 +42,6 @@ float *audio_samples_f = (float *) audio_samples;
// counter for auto repeat // counter for auto repeat
ms_time_t updn_press_timer = 0; ms_time_t updn_press_timer = 0;
ms_time_t ltrt_press_timer = 0; ms_time_t ltrt_press_timer = 0;
ms_time_t updn_hold_ts;
/** Dot matrix display instance */ /** Dot matrix display instance */
DotMatrix_Cfg *disp; DotMatrix_Cfg *disp;
@ -59,8 +50,8 @@ DotMatrix_Cfg *disp;
volatile bool capture_pending = false; volatile bool capture_pending = false;
/** scale & brightness config fields. Initial values. */ /** scale & brightness config fields. Initial values. */
float y_scale = 1; float y_scale = 5;
uint8_t brightness = DEFAULT_BRIGHTNESS; uint8_t brightness = 3;
/** active rendering mode (visualisation preset) */ /** active rendering mode (visualisation preset) */
enum { enum {
@ -180,17 +171,12 @@ void display_wave()
dmtx_show(disp); dmtx_show(disp);
} }
/** Calculate FFT */ /** Calculate and display FFT */
static void calculate_fft() static void calculate_fft()
{ {
float *bins = audio_samples_f; float *bins = audio_samples_f;
samples_to_float(); samples_to_float();
for (int i = 0; i < SAMPLE_COUNT; i++) {
bins[i] *= y_scale * FFT_PREFFT_SCALE; //win_hamming_512[i];
}
spread_samples_for_fft(); spread_samples_for_fft();
const arm_cfft_instance_f32 *S; const arm_cfft_instance_f32 *S;
@ -201,18 +187,17 @@ static void calculate_fft()
// Normalize & display // Normalize & display
start_render();
float factor = (1.0f / BIN_COUNT) * FFT_SCALE * y_scale;
for (int i = 0; i < BIN_COUNT; i++) { // +1 because bin 0 is always 0 for (int i = 0; i < BIN_COUNT; i++) { // +1 because bin 0 is always 0
float bin = bins[i] * (1.0f / BIN_COUNT) * FFT_PRELOG_SCALE; bins[i] *= factor;
bin = log2f(bin);
bins[i] = bin * FFT_FINAL_SCALE;
} }
} }
/** Render classic FFT */ /** Render classic FFT */
static void display_fft() static void display_fft()
{ {
start_render();
float *bins = audio_samples_f; float *bins = audio_samples_f;
for (int x = 0; x < SCREEN_W; x++) { for (int x = 0; x < SCREEN_W; x++) {
@ -227,12 +212,10 @@ static void display_fft()
/** Render FFT "spindle" */ /** Render FFT "spindle" */
static void display_fft_spindle() static void display_fft_spindle()
{ {
start_render();
float *bins = audio_samples_f; float *bins = audio_samples_f;
for (int x = 0; x < SCREEN_W; x++) { for (int x = 0; x < SCREEN_W; x++) {
for (int j = 0; j < 1 + floorf(bins[x] * 0.5f); j++) { for (int j = 0; j < 1 + floorf(bins[x] * FFT_SPINDLE_SCALE_MULT); j++) {
dmtx_set(disp, x, 7 + j, 1); dmtx_set(disp, x, 7 + j, 1);
dmtx_set(disp, x, 7 - j, 1); dmtx_set(disp, x, 7 - j, 1);
} }
@ -265,20 +248,16 @@ static void gamepad_button_cb(uint32_t btn, bool press)
case BTN_UP: case BTN_UP:
up_pressed = press; up_pressed = press;
if (press) { if (press) {
updn_hold_ts = ms_now();
updn_press_timer = 0; updn_press_timer = 0;
y_scale += VOL_STEP; y_scale += 0.5f;
} }
break; break;
case BTN_DOWN: case BTN_DOWN:
down_pressed = press; down_pressed = press;
if (press) { if (press) {
updn_hold_ts = ms_now();
updn_press_timer = 0; updn_press_timer = 0;
if (y_scale > VOL_STEP + VOL_STEP_THRESH) { if (y_scale > 0.55) y_scale -= 0.5f;
y_scale -= VOL_STEP;
}
} }
break; break;
@ -386,7 +365,6 @@ void user_main()
user_init(); user_init();
ms_time_t counter1 = 0; ms_time_t counter1 = 0;
ms_time_t counter2 = 0;
while (1) { while (1) {
if (ms_loop_elapsed(&counter1, 500)) { if (ms_loop_elapsed(&counter1, 500)) {
// Blink // Blink
@ -395,31 +373,19 @@ void user_main()
// hold-to-repeat // hold-to-repeat
// This is not the correct way to do it, but good enough // This is not the correct way to do it, but good enough
if (ms_loop_elapsed(&updn_press_timer, VOL_STEP_TIME)) { if (ms_loop_elapsed(&updn_press_timer, 100)) {
if (up_pressed) { if (up_pressed) {
if (ms_now() - updn_hold_ts > VOL_STEP_SPEEDUP_TIME) { y_scale += 0.5;
y_scale += VOL_STEP_LARGE;
} else {
y_scale += VOL_STEP;
}
} }
if (down_pressed) { if (down_pressed) {
if (ms_now() - updn_hold_ts > VOL_STEP_SPEEDUP_TIME) { if (y_scale > 0.55) {
if (y_scale > VOL_STEP_LARGE + VOL_STEP_THRESH) { y_scale -= 0.5;
y_scale -= VOL_STEP_LARGE;
} else if (y_scale > VOL_STEP + VOL_STEP_THRESH) {
y_scale -= VOL_STEP;
}
} else {
if (y_scale > VOL_STEP + VOL_STEP_THRESH) {
y_scale -= VOL_STEP;
}
} }
} }
if (up_pressed || down_pressed) { if (up_pressed || down_pressed) {
dbg("scale = %.2f", y_scale); dbg("scale = %.1f", y_scale);
} }
} }
@ -442,11 +408,9 @@ void user_main()
} }
// capture a sample to update display // capture a sample to update display
//if (ms_loop_elapsed(&counter2, 10)) {
if (!capture_pending) { if (!capture_pending) {
capture_start(); capture_start();
} }
//}
} }
} }

Loading…
Cancel
Save