From 60953849bb18c1719f6c90de5e48084efae71592 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 2 May 2021 19:25:19 +0200 Subject: Add duty-cycle sprites and trigger parameters --- src/sequencer.c | 99 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/src/sequencer.c b/src/sequencer.c index d7d1c7c..5db1b5d 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -1,6 +1,3 @@ -#define SPRITE_NOTE_NAMES_W 16 -#define SPRITE_NOTE_NAMES_H 8 - u32 sprite_note_names[] = { 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e, 0x00000098, 0xa8a8a898, 0x00000038, 0x203b0a39, @@ -119,6 +116,24 @@ u32 sprite_env_label_env[] = { 0x62a2a2a2, 0xee000000, 0xee2a6e22, 0xe2000000, }; +u32 sprite_duty_cycle_label[] = { + 0x00000000, 0x00000080, 0xa6aaaaaa, 0xe60000ab, + 0xaea4e444, 0x4400008b, 0x00000000, 0x00000003, + 0x80808080, 0x00000000, 0xa8b89093, 0x00000000, + 0x888888bb, 0x00000000, 0x00010003, 0x00000000, +}; + +u32 sprite_duty_cycle[] = { + 0xb03030b0, 0xb0b0b000, 0x0f0c0c0f, 0x01616f00, + 0x1f83831f, 0x18989f00, 0x00090d06, 0x030d0c00, + 0x00000000, 0x00000000, 0xdfd8d8df, 0x0303df00, + 0x07606087, 0xc6662700, 0x00020301, 0x00030300, + 0x00000000, 0x00000000, 0xdf43435f, 0x5858df00, + 0x07666686, 0xc6662700, 0x00020301, 0x00030300, + 0x00000000, 0x00000000, 0xdfd8d8cc, 0x0603c300, + 0x07606087, 0xc6662700, 0x00020301, 0x00030300, +}; + u32 sprite_env_volume[] = { 0x80808080, 0x80808000, 0x0f0c0c0c, 0x0c6c6f00, 0x1f999919, 0x19999f00, 0x00090d06, 0x030d0c00, @@ -186,29 +201,30 @@ typedef struct SeqTrigger { u8 env_volume; u8 env_time; u8 env_direction; + u8 duty_cycle; // TODO: ... } SeqTrigger; static SeqTrigger sequence_synth[] = { - {true , NOTE_D_4 , 0, 0, 0}, - {true , NOTE_F_4 , 1, 1, 0}, - {true , NOTE_A_4 , 2, 2, 0}, - {true , NOTE_C_5 , 3, 3, 0}, - - {true , NOTE_D_4 , 4, 4, 1}, - {false , NOTE_C_SHARP_4 , 5, 5, 1}, - {false , NOTE_D_4 , 6, 6, 1}, - {false , NOTE_D_4 , 7, 7, 1}, - - {true , NOTE_D_4 , 8, 0, 0}, - {true , NOTE_F_4 , 9, 1, 0}, - {true , NOTE_A_4 , 10, 2, 0}, - {true , NOTE_C_5 , 11, 3, 0}, - - {true , NOTE_D_4 , 12, 4, 1}, - {false , NOTE_D_4 , 13, 5, 1}, - {true , NOTE_A_4 , 14, 6, 1}, - {false , NOTE_A_5 , 15, 7, 1}, + {true , NOTE_D_4 , 0, 0, 0, 0}, + {true , NOTE_F_4 , 1, 1, 0, 0}, + {true , NOTE_A_4 , 2, 2, 0, 1}, + {true , NOTE_C_5 , 3, 3, 0, 1}, + + {true , NOTE_D_4 , 4, 4, 1, 2}, + {false , NOTE_C_SHARP_4 , 5, 5, 1, 2}, + {false , NOTE_D_4 , 6, 6, 1, 3}, + {false , NOTE_D_4 , 7, 7, 1, 3}, + + {true , NOTE_D_4 , 8, 0, 0, 0}, + {true , NOTE_F_4 , 9, 1, 0, 0}, + {true , NOTE_A_4 , 10, 2, 0, 1}, + {true , NOTE_C_5 , 11, 3, 0, 1}, + + {true , NOTE_D_4 , 12, 4, 1, 2}, + {false , NOTE_D_4 , 13, 5, 1, 2}, + {true , NOTE_A_4 , 14, 6, 1, 3}, + {false , NOTE_A_5 , 15, 7, 1, 3}, }; static int bpm = 120; @@ -223,7 +239,7 @@ irq_timer_0(void) { SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(trig->env_volume) | SOUND_SQUARE_ENV_TIME(trig->env_time) | SOUND_SQUARE_ENV_INC(trig->env_direction) - | SOUND_SQUARE_DUTY(2); + | SOUND_SQUARE_DUTY(trig->duty_cycle); SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note]; } step_counter = (step_counter + 1) % 16; @@ -273,6 +289,8 @@ set_time(int bpm) { // - 038-038 envelope: direction label. // - 039-039 envelope: direction indicator. // - 040-040 envelope: envelope label. +// - 041-041 duty-cycle label. +// - 042-042 duty-cycle indicator. // @@ -283,6 +301,8 @@ set_time(int bpm) { #define SEQ_ENV_POS_X 10 #define SEQ_ENV_POS_Y 10 #define SEQ_ENV_DIST 34 +#define SEQ_DUTYCYCLE_POS_X SEQ_ENV_POS_X + SEQ_ENV_DIST * 3 +#define SEQ_DUTYCYCLE_POS_Y 10 - 8 size_t obj_counter = 0; @@ -298,7 +318,7 @@ typedef struct SeqSprite { int trig_selection_loc = 1; -SeqSprite seq_sprites[41] = {0}; +SeqSprite seq_sprites[43] = {0}; void init_sequencer_sprites(void) { @@ -450,6 +470,29 @@ init_sequencer_sprites(void) { seq_sprites[40].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x); seq_sprites[40].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); } + + sprite_id = load_packed_sprite_data(&sprite_duty_cycle_label, 8, 1); + { + int x = SEQ_DUTYCYCLE_POS_X; + int y = SEQ_DUTYCYCLE_POS_Y; + int base_tile = sprites[sprite_id].tile_start; + seq_sprites[41].id = obj_counter++; + seq_sprites[41].base_tile = base_tile; + seq_sprites[41].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y); + seq_sprites[41].obj_attr_1 = OBJ_SIZE_BIG | OBJ_X_COORD(x); + seq_sprites[41].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); + } + sprite_id = load_packed_sprite_data(&sprite_duty_cycle, 4, 4); + { + int x = SEQ_DUTYCYCLE_POS_X; + int y = SEQ_DUTYCYCLE_POS_Y + 16; + int base_tile = sprites[sprite_id].tile_start; + seq_sprites[42].id = obj_counter++; + seq_sprites[42].base_tile = base_tile; + seq_sprites[42].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y); + seq_sprites[42].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x); + seq_sprites[42].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); + } } void @@ -519,6 +562,14 @@ update_sequencer_sprites(void) { size_t tile = base_tile + tile_diff; seq_sprites[39].obj_attr_2 = tile | OBJ_PAL_BANK(2); } + + // 43: Envelope initial volume + { + size_t tile_diff = sequence_synth[trig_selection_loc].duty_cycle * 4; + size_t base_tile = seq_sprites[42].base_tile; + size_t tile = base_tile + tile_diff; + seq_sprites[42].obj_attr_2 = tile | OBJ_PAL_BANK(2); + } } void -- cgit v1.2.1