aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-01-16 15:21:47 +0100
committerBad Diode <bd@badd10de.dev>2024-01-16 15:21:47 +0100
commitbda8ac3969d40b28c4c14683c1f722647fd17aec (patch)
tree17473683aa917a5aced51fc35e8c0866eb00595f
parent950b4268b6283f0eb322ba93b623988abc0d4e96 (diff)
downloadstepper-bda8ac3969d40b28c4c14683c1f722647fd17aec.tar.gz
stepper-bda8ac3969d40b28c4c14683c1f722647fd17aec.zip
Further performance improvements
-rw-r--r--Makefile2
-rw-r--r--src/globals.c1
-rw-r--r--src/main.c12
-rw-r--r--src/sequencer.c81
4 files changed, 52 insertions, 44 deletions
diff --git a/Makefile b/Makefile
index 60a141c..89ea9b0 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ INC_FLAGS := $(addprefix -I,$(INC_DIRS))
27INC_FLAGS += -I$(LIBGBA_SRC) 27INC_FLAGS += -I$(LIBGBA_SRC)
28 28
29# Output library names and executables. 29# Output library names and executables.
30TARGET := STEPPER-v1.8-dev-20 30TARGET := STEPPER-v1.8-dev-21
31ELF := $(BUILD_DIR)/$(TARGET).elf 31ELF := $(BUILD_DIR)/$(TARGET).elf
32BIN := $(BUILD_DIR)/$(TARGET).gba 32BIN := $(BUILD_DIR)/$(TARGET).gba
33 33
diff --git a/src/globals.c b/src/globals.c
index c040585..9d0a5bb 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -236,3 +236,4 @@ static int wave_env_ticks = 0;
236static int wave_env_attack = 8; 236static int wave_env_attack = 8;
237static int wave_env_decay = 8; 237static int wave_env_decay = 8;
238static int wave_env_prog = 0; 238static int wave_env_prog = 0;
239static Wave current_wave[8] = {0};
diff --git a/src/main.c b/src/main.c
index 2731b6a..a4d3421 100644
--- a/src/main.c
+++ b/src/main.c
@@ -71,6 +71,8 @@ WITH REGARD TO THIS SOFTWARE.
71#define PROF_ENABLE 0 71#define PROF_ENABLE 0
72#include "profiling.c" 72#include "profiling.c"
73 73
74static int frames = 0;
75
74void 76void
75render_sequencer(void) { 77render_sequencer(void) {
76 if (redraw_trigs) { 78 if (redraw_trigs) {
@@ -110,11 +112,15 @@ render_sequencer(void) {
110 112
111 if (input_handler == handle_pattern_selection || 113 if (input_handler == handle_pattern_selection ||
112 input_handler == handle_pattern_chain) { 114 input_handler == handle_pattern_chain) {
113 draw_pattern_chain(); 115 if (frames & 0x1) {
116 draw_pattern_chain();
117 }
114 } 118 }
115 119
116 draw_notif_bar(); 120 if (frames++ & 0x1) {
117 PROF(draw_piano_notes(), draw_piano_cycles); 121 draw_notif_bar();
122 PROF(draw_piano_notes(), draw_piano_cycles);
123 }
118 PROF(draw_cursors(), draw_cursor_cycles); 124 PROF(draw_cursors(), draw_cursor_cycles);
119} 125}
120 126
diff --git a/src/sequencer.c b/src/sequencer.c
index 45fc0e4..c01f905 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -376,12 +376,37 @@ wave_ad_tick(void) {
376env_start: 376env_start:
377 switch (wave_env) { 377 switch (wave_env) {
378 case WAV_ENV_START: { 378 case WAV_ENV_START: {
379 // Calculate all 8 transitions for the current target wave.
380 for (size_t k = 0; k < 8; k++) {
381 for (size_t j = 0; j < 4; j++) {
382 u32 next = 0;
383 u32 prev = (*wave_target)[j];
384 for (size_t i = 0; i < 8; i++) {
385 u8 val = (prev >> 4 * i) & 0xF;
386 u8 tmp = mult_table[val][k];
387 next |= (tmp << 4 * i);
388 }
389 current_wave[k][j] = next;
390 }
391 // DEBUG:
392 // if (k < 4) {
393 // int x = 0;
394 // int y = 18 * k;
395 // draw_filled_rect(x, y, 100 + x, 16 + y, COL_BG);
396 // draw_wave_pattern(&current_wave[k], 0 + x, 0 + y, 1);
397 // } else {
398 // int x = 100;
399 // int y = 18 * (k - 4);
400 // draw_filled_rect(x, y, 100 + x, 16 + y, COL_BG);
401 // draw_wave_pattern(&current_wave[k], 0 + x, 0 + y, 1);
402 // }
403 }
379 wave_env_ticks = 0; 404 wave_env_ticks = 0;
380 wave_env_prog = 0; 405 wave_env_prog = 0;
381 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0); 406 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
382 memcpy32(SOUND_WAVE_RAM, wave_zero, 16); 407 memcpy32(SOUND_WAVE_RAM, current_wave[0], 16);
383 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1); 408 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
384 memcpy32(SOUND_WAVE_RAM, wave_zero, 16); 409 memcpy32(SOUND_WAVE_RAM, current_wave[0], 16);
385 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(0) 410 SOUND_WAVE_MODE = SOUND_WAVE_BANK_MODE(0)
386 | SOUND_WAVE_BANK_SELECT(0); 411 | SOUND_WAVE_BANK_SELECT(0);
387 SOUND_WAVE_MODE |= SOUND_WAVE_ENABLE; 412 SOUND_WAVE_MODE |= SOUND_WAVE_ENABLE;
@@ -411,17 +436,14 @@ env_start:
411 } 436 }
412 wave_env_ticks = 0; 437 wave_env_ticks = 0;
413 438
414 // Attack. 439 // DEBUG:
415 for (size_t j = 0; j < 4; j++) { 440 // int x = 50;
416 u32 next = 0; 441 // int y = 50;
417 u32 prev = (*wave_target)[j]; 442 // draw_filled_rect(0 + x, 0 + y, 100 + x, 32 + y, COL_BG);
418 for (size_t i = 0; i < 8; i++) { 443 // draw_wave_pattern(&current_wave[wave_env_prog], 0 + x, 0 + y, 1);
419 u8 val = (prev >> 4 * i) & 0xF; 444
420 u8 tmp = mult_table[val][wave_env_prog]; 445 memcpy32(SOUND_WAVE_RAM, current_wave[wave_env_prog], 16);
421 next |= (tmp << 4 * i); 446 SOUND_WAVE_MODE ^= SOUND_WAVE_BANK_SELECT(1);
422 }
423 wave_active[j] = next;
424 }
425 if (++wave_env_prog >= 8) { 447 if (++wave_env_prog >= 8) {
426 if (wave_env_decay == 0) { 448 if (wave_env_decay == 0) {
427 wave_env = WAV_ENV_OFF; 449 wave_env = WAV_ENV_OFF;
@@ -430,15 +452,6 @@ env_start:
430 } 452 }
431 wave_env_prog = 0; 453 wave_env_prog = 0;
432 } 454 }
433
434 // DEBUG:
435 // int x = 50;
436 // int y = 50;
437 // draw_filled_rect(0 + x, 0 + y, 100 + x, 32 + y, COL_BG);
438 // draw_wave_pattern(&wave_active, 0 + x, 0 + y, 1);
439
440 memcpy32(SOUND_WAVE_RAM, wave_active, 16);
441 SOUND_WAVE_MODE ^= SOUND_WAVE_BANK_SELECT(1);
442 } break; 455 } break;
443 case WAV_ENV_DECAY: { 456 case WAV_ENV_DECAY: {
444 if (wave_env_ticks++ < wave_env_decay) { 457 if (wave_env_ticks++ < wave_env_decay) {
@@ -446,30 +459,18 @@ env_start:
446 } 459 }
447 wave_env_ticks = 0; 460 wave_env_ticks = 0;
448 461
449 // Decay.
450 for (size_t j = 0; j < 4; j++) {
451 u32 next = 0;
452 u32 prev = (*wave_target)[j];
453 for (size_t i = 0; i < 8; i++) {
454 u8 val = (prev >> 4 * i) & 0xF;
455 u8 tmp = mult_table[val][7 - wave_env_prog];
456 next |= (tmp << 4 * i);
457 }
458 wave_active[j] = next;
459 }
460 if (++wave_env_prog >= 8) {
461 wave_env = WAV_ENV_END;
462 wave_env_prog = 0;
463 }
464
465 // DEBUG: 462 // DEBUG:
466 // int x = 50; 463 // int x = 50;
467 // int y = 50; 464 // int y = 50;
468 // draw_filled_rect(0 + x, 0 + y, 100 + x, 32 + y, COL_BG); 465 // draw_filled_rect(0 + x, 0 + y, 100 + x, 32 + y, COL_BG);
469 // draw_wave_pattern(&wave_active, 0 + x, 0 + y, 1); 466 // draw_wave_pattern(&current_wave[7-wave_env_prog], 0 + x, 0 + y, 1);
470 467
471 memcpy32(SOUND_WAVE_RAM, wave_active, 16); 468 memcpy32(SOUND_WAVE_RAM, current_wave[7 - wave_env_prog], 16);
472 SOUND_WAVE_MODE ^= SOUND_WAVE_BANK_SELECT(1); 469 SOUND_WAVE_MODE ^= SOUND_WAVE_BANK_SELECT(1);
470 if (++wave_env_prog >= 8) {
471 wave_env = WAV_ENV_END;
472 wave_env_prog = 0;
473 }
473 } break; 474 } break;
474 case WAV_ENV_OFF: { 475 case WAV_ENV_OFF: {
475 if (wave_env_ticks++ == 24) { 476 if (wave_env_ticks++ == 24) {