summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-02 19:25:19 +0200
committerBad Diode <bd@badd10de.dev>2021-05-02 19:25:19 +0200
commit60953849bb18c1719f6c90de5e48084efae71592 (patch)
treec2615d6b0e896f018f68e400bc07f50f259425f3
parent8216086180ad5875d8bdade518503b7de2396a82 (diff)
downloadgba-experiments-60953849bb18c1719f6c90de5e48084efae71592.tar.gz
gba-experiments-60953849bb18c1719f6c90de5e48084efae71592.zip
Add duty-cycle sprites and trigger parameters
-rw-r--r--src/sequencer.c99
1 files 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 @@
1#define SPRITE_NOTE_NAMES_W 16
2#define SPRITE_NOTE_NAMES_H 8
3
4u32 sprite_note_names[] = { 1u32 sprite_note_names[] = {
5 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e, 2 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e,
6 0x00000098, 0xa8a8a898, 0x00000038, 0x203b0a39, 3 0x00000098, 0xa8a8a898, 0x00000038, 0x203b0a39,
@@ -119,6 +116,24 @@ u32 sprite_env_label_env[] = {
119 0x62a2a2a2, 0xee000000, 0xee2a6e22, 0xe2000000, 116 0x62a2a2a2, 0xee000000, 0xee2a6e22, 0xe2000000,
120}; 117};
121 118
119u32 sprite_duty_cycle_label[] = {
120 0x00000000, 0x00000080, 0xa6aaaaaa, 0xe60000ab,
121 0xaea4e444, 0x4400008b, 0x00000000, 0x00000003,
122 0x80808080, 0x00000000, 0xa8b89093, 0x00000000,
123 0x888888bb, 0x00000000, 0x00010003, 0x00000000,
124};
125
126u32 sprite_duty_cycle[] = {
127 0xb03030b0, 0xb0b0b000, 0x0f0c0c0f, 0x01616f00,
128 0x1f83831f, 0x18989f00, 0x00090d06, 0x030d0c00,
129 0x00000000, 0x00000000, 0xdfd8d8df, 0x0303df00,
130 0x07606087, 0xc6662700, 0x00020301, 0x00030300,
131 0x00000000, 0x00000000, 0xdf43435f, 0x5858df00,
132 0x07666686, 0xc6662700, 0x00020301, 0x00030300,
133 0x00000000, 0x00000000, 0xdfd8d8cc, 0x0603c300,
134 0x07606087, 0xc6662700, 0x00020301, 0x00030300,
135};
136
122u32 sprite_env_volume[] = { 137u32 sprite_env_volume[] = {
123 0x80808080, 0x80808000, 0x0f0c0c0c, 0x0c6c6f00, 138 0x80808080, 0x80808000, 0x0f0c0c0c, 0x0c6c6f00,
124 0x1f999919, 0x19999f00, 0x00090d06, 0x030d0c00, 139 0x1f999919, 0x19999f00, 0x00090d06, 0x030d0c00,
@@ -186,29 +201,30 @@ typedef struct SeqTrigger {
186 u8 env_volume; 201 u8 env_volume;
187 u8 env_time; 202 u8 env_time;
188 u8 env_direction; 203 u8 env_direction;
204 u8 duty_cycle;
189 // TODO: ... 205 // TODO: ...
190} SeqTrigger; 206} SeqTrigger;
191 207
192static SeqTrigger sequence_synth[] = { 208static SeqTrigger sequence_synth[] = {
193 {true , NOTE_D_4 , 0, 0, 0}, 209 {true , NOTE_D_4 , 0, 0, 0, 0},
194 {true , NOTE_F_4 , 1, 1, 0}, 210 {true , NOTE_F_4 , 1, 1, 0, 0},
195 {true , NOTE_A_4 , 2, 2, 0}, 211 {true , NOTE_A_4 , 2, 2, 0, 1},
196 {true , NOTE_C_5 , 3, 3, 0}, 212 {true , NOTE_C_5 , 3, 3, 0, 1},
197 213
198 {true , NOTE_D_4 , 4, 4, 1}, 214 {true , NOTE_D_4 , 4, 4, 1, 2},
199 {false , NOTE_C_SHARP_4 , 5, 5, 1}, 215 {false , NOTE_C_SHARP_4 , 5, 5, 1, 2},
200 {false , NOTE_D_4 , 6, 6, 1}, 216 {false , NOTE_D_4 , 6, 6, 1, 3},
201 {false , NOTE_D_4 , 7, 7, 1}, 217 {false , NOTE_D_4 , 7, 7, 1, 3},
202 218
203 {true , NOTE_D_4 , 8, 0, 0}, 219 {true , NOTE_D_4 , 8, 0, 0, 0},
204 {true , NOTE_F_4 , 9, 1, 0}, 220 {true , NOTE_F_4 , 9, 1, 0, 0},
205 {true , NOTE_A_4 , 10, 2, 0}, 221 {true , NOTE_A_4 , 10, 2, 0, 1},
206 {true , NOTE_C_5 , 11, 3, 0}, 222 {true , NOTE_C_5 , 11, 3, 0, 1},
207 223
208 {true , NOTE_D_4 , 12, 4, 1}, 224 {true , NOTE_D_4 , 12, 4, 1, 2},
209 {false , NOTE_D_4 , 13, 5, 1}, 225 {false , NOTE_D_4 , 13, 5, 1, 2},
210 {true , NOTE_A_4 , 14, 6, 1}, 226 {true , NOTE_A_4 , 14, 6, 1, 3},
211 {false , NOTE_A_5 , 15, 7, 1}, 227 {false , NOTE_A_5 , 15, 7, 1, 3},
212}; 228};
213 229
214static int bpm = 120; 230static int bpm = 120;
@@ -223,7 +239,7 @@ irq_timer_0(void) {
223 SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(trig->env_volume) 239 SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(trig->env_volume)
224 | SOUND_SQUARE_ENV_TIME(trig->env_time) 240 | SOUND_SQUARE_ENV_TIME(trig->env_time)
225 | SOUND_SQUARE_ENV_INC(trig->env_direction) 241 | SOUND_SQUARE_ENV_INC(trig->env_direction)
226 | SOUND_SQUARE_DUTY(2); 242 | SOUND_SQUARE_DUTY(trig->duty_cycle);
227 SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note]; 243 SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note];
228 } 244 }
229 step_counter = (step_counter + 1) % 16; 245 step_counter = (step_counter + 1) % 16;
@@ -273,6 +289,8 @@ set_time(int bpm) {
273// - 038-038 envelope: direction label. 289// - 038-038 envelope: direction label.
274// - 039-039 envelope: direction indicator. 290// - 039-039 envelope: direction indicator.
275// - 040-040 envelope: envelope label. 291// - 040-040 envelope: envelope label.
292// - 041-041 duty-cycle label.
293// - 042-042 duty-cycle indicator.
276// 294//
277 295
278 296
@@ -283,6 +301,8 @@ set_time(int bpm) {
283#define SEQ_ENV_POS_X 10 301#define SEQ_ENV_POS_X 10
284#define SEQ_ENV_POS_Y 10 302#define SEQ_ENV_POS_Y 10
285#define SEQ_ENV_DIST 34 303#define SEQ_ENV_DIST 34
304#define SEQ_DUTYCYCLE_POS_X SEQ_ENV_POS_X + SEQ_ENV_DIST * 3
305#define SEQ_DUTYCYCLE_POS_Y 10 - 8
286 306
287size_t obj_counter = 0; 307size_t obj_counter = 0;
288 308
@@ -298,7 +318,7 @@ typedef struct SeqSprite {
298 318
299int trig_selection_loc = 1; 319int trig_selection_loc = 1;
300 320
301SeqSprite seq_sprites[41] = {0}; 321SeqSprite seq_sprites[43] = {0};
302 322
303void 323void
304init_sequencer_sprites(void) { 324init_sequencer_sprites(void) {
@@ -450,6 +470,29 @@ init_sequencer_sprites(void) {
450 seq_sprites[40].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x); 470 seq_sprites[40].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
451 seq_sprites[40].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); 471 seq_sprites[40].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
452 } 472 }
473
474 sprite_id = load_packed_sprite_data(&sprite_duty_cycle_label, 8, 1);
475 {
476 int x = SEQ_DUTYCYCLE_POS_X;
477 int y = SEQ_DUTYCYCLE_POS_Y;
478 int base_tile = sprites[sprite_id].tile_start;
479 seq_sprites[41].id = obj_counter++;
480 seq_sprites[41].base_tile = base_tile;
481 seq_sprites[41].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
482 seq_sprites[41].obj_attr_1 = OBJ_SIZE_BIG | OBJ_X_COORD(x);
483 seq_sprites[41].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
484 }
485 sprite_id = load_packed_sprite_data(&sprite_duty_cycle, 4, 4);
486 {
487 int x = SEQ_DUTYCYCLE_POS_X;
488 int y = SEQ_DUTYCYCLE_POS_Y + 16;
489 int base_tile = sprites[sprite_id].tile_start;
490 seq_sprites[42].id = obj_counter++;
491 seq_sprites[42].base_tile = base_tile;
492 seq_sprites[42].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
493 seq_sprites[42].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
494 seq_sprites[42].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
495 }
453} 496}
454 497
455void 498void
@@ -519,6 +562,14 @@ update_sequencer_sprites(void) {
519 size_t tile = base_tile + tile_diff; 562 size_t tile = base_tile + tile_diff;
520 seq_sprites[39].obj_attr_2 = tile | OBJ_PAL_BANK(2); 563 seq_sprites[39].obj_attr_2 = tile | OBJ_PAL_BANK(2);
521 } 564 }
565
566 // 43: Envelope initial volume
567 {
568 size_t tile_diff = sequence_synth[trig_selection_loc].duty_cycle * 4;
569 size_t base_tile = seq_sprites[42].base_tile;
570 size_t tile = base_tile + tile_diff;
571 seq_sprites[42].obj_attr_2 = tile | OBJ_PAL_BANK(2);
572 }
522} 573}
523 574
524void 575void