summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-02 18:10:20 +0200
committerBad Diode <bd@badd10de.dev>2021-05-02 18:10:20 +0200
commitfc16837ded8df8ffe7ba77dc0e2387d7af3ddde2 (patch)
tree3fb37845197987f21d68a425528b08a1d107e4a5
parent53c1e688f2b2f559a2bde556c9762519efa66f03 (diff)
downloadgba-experiments-fc16837ded8df8ffe7ba77dc0e2387d7af3ddde2.tar.gz
gba-experiments-fc16837ded8df8ffe7ba77dc0e2387d7af3ddde2.zip
Add UI elements for envelope filter per trig
-rw-r--r--src/common.h2
-rw-r--r--src/sequencer.c174
2 files changed, 148 insertions, 28 deletions
diff --git a/src/common.h b/src/common.h
index ece94cd..b688711 100644
--- a/src/common.h
+++ b/src/common.h
@@ -594,7 +594,7 @@ sound_volume(SoundChannel channels, u8 volume) {
594#define SOUND_SQUARE_LEN(N) (N) 594#define SOUND_SQUARE_LEN(N) (N)
595#define SOUND_SQUARE_DUTY(N) ((N) << 0x6) 595#define SOUND_SQUARE_DUTY(N) ((N) << 0x6)
596#define SOUND_SQUARE_ENV_TIME(N) ((N) << 0x8) 596#define SOUND_SQUARE_ENV_TIME(N) ((N) << 0x8)
597#define SOUND_SQUARE_ENV_INC (1 << 0xB) 597#define SOUND_SQUARE_ENV_INC(N) ((N) << 0xB)
598#define SOUND_SQUARE_ENV_VOL(N) ((N) << 0xC) 598#define SOUND_SQUARE_ENV_VOL(N) ((N) << 0xC)
599 599
600// DMG square frequency bits. 600// DMG square frequency bits.
diff --git a/src/sequencer.c b/src/sequencer.c
index 39f083f..f76b0f8 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -99,12 +99,26 @@ u32 sprite_trigger_selection[] = {
99 0x04040407, 0x00000000, 0x00000000, 0x00000000, 99 0x04040407, 0x00000000, 0x00000000, 0x00000000,
100}; 100};
101 101
102u32 sprite_env_labels[] = { 102u32 sprite_env_label_volume[] = {
103 // Volume.
104 0xa0a0a0a0, 0xc0000000, 0x262a2a2a, 0xee000000, 103 0xa0a0a0a0, 0xc0000000, 0x262a2a2a, 0xee000000,
105 0xaaeaaaaa, 0xae000000, 0x0e020602, 0x0e000000, 104 0xaaeaaaaa, 0xae000000, 0x0e020602, 0x0e000000,
106}; 105};
107 106
107u32 sprite_env_label_time[] = {
108 0x00000000, 0x00000000, 0xee444444, 0xe4000000,
109 0xea2e6a2a, 0xea000000, 0x00000000, 0x00000000,
110};
111
112u32 sprite_env_label_direction[] = {
113 0x00000000, 0x00000000, 0xcc949494, 0xcc000000,
114 0x1d140cd4, 0xd5000000, 0x00000000, 0x00000000,
115};
116
117u32 sprite_env_label_env[] = {
118 0x6ea2a6a2, 0xae000000, 0xea2a6a2a, 0xec000000,
119 0x62a2a2a2, 0xee000000, 0xee2a6e22, 0xe2000000,
120};
121
108u32 sprite_env_volume[] = { 122u32 sprite_env_volume[] = {
109 0x80808080, 0x80808000, 0x0f0c0c0c, 0x0c6c6f00, 123 0x80808080, 0x80808000, 0x0f0c0c0c, 0x0c6c6f00,
110 0x1f999919, 0x19999f00, 0x00090d06, 0x030d0c00, 124 0x1f999919, 0x19999f00, 0x00090d06, 0x030d0c00,
@@ -140,33 +154,61 @@ u32 sprite_env_volume[] = {
140 0xf0909090, 0x9096f600, 0x0199d961, 0x31d9c900, 154 0xf0909090, 0x9096f600, 0x0199d961, 0x31d9c900,
141}; 155};
142 156
157u32 sprite_env_time[] = {
158 0x80808080, 0x80808000, 0x0f0c0c0c, 0x0c6c6f00,
159 0x1f999919, 0x19999f00, 0x00090d06, 0x030d0c00,
160 0x60606060, 0x60606000, 0x181c1a19, 0x1fd8d800,
161 0x3e30303c, 0x30303e00, 0x00131b0c, 0x061b1900,
162 0xf8c0c0f8, 0x1818f800, 0x3e32323e, 0x32b2be00,
163 0x7c0c0c7c, 0x4c4d7d00, 0x00263618, 0x0c363200,
164 0xc0e0d0c8, 0xf8c0c000, 0x3e30303e, 0x0686be00,
165 0x7c64647c, 0x60617d00, 0x00263618, 0x0c363200,
166 0xe06060e0, 0x0000e000, 0xfbc0c063, 0x331b1b00,
167 0x30303030, 0x30363600, 0x00131b0c, 0x061b1900,
168 0xe0000080, 0xc0606000, 0x1b1b1b19, 0x18d8d800,
169 0x30383432, 0x3e303000, 0x00131b0c, 0x061b1900,
170 0xf8c8c8f8, 0xc8c8f800, 0x3e06063e, 0x30b0be00,
171 0x7c606030, 0x180d0d00, 0x00263618, 0x0c363200,
172 0xec2c2c2c, 0x2c2cec00, 0xfbcbcbcb, 0xcbcbfb00,
173 0xf0909090, 0x9096f600, 0x0199d961, 0x31d9c900,
174};
175
176u32 sprite_env_sweep_direction[] = {
177 0x00000000, 0x00000000, 0xc8c8c8c8, 0xc8c8f800,
178 0x3e32323e, 0x02020200, 0x00000000, 0x00000000,
179 0xe0202020, 0x2020e000, 0x71cbcbcb, 0xcbcb7100,
180 0xb2b2b2b2, 0xb2ba9400, 0x0d0f0e0c, 0x0c0c0c00,
181};
182
143typedef struct SeqTrigger { 183typedef struct SeqTrigger {
144 bool trigger; 184 bool trigger;
145 Note note; 185 Note note;
146 u8 env_volume; 186 u8 env_volume;
187 u8 env_time;
188 u8 env_direction;
147 // TODO: ... 189 // TODO: ...
148} SeqTrigger; 190} SeqTrigger;
149 191
150static SeqTrigger sequence_synth[] = { 192static SeqTrigger sequence_synth[] = {
151 {true, NOTE_D_4, 0}, 193 {true , NOTE_D_4 , 0, 0, 0},
152 {true, NOTE_F_4, 1}, 194 {true , NOTE_F_4 , 1, 1, 0},
153 {true, NOTE_A_4, 2}, 195 {true , NOTE_A_4 , 2, 2, 0},
154 {true, NOTE_C_5, 3}, 196 {true , NOTE_C_5 , 3, 3, 0},
155 197
156 {true, NOTE_D_4, 4}, 198 {true , NOTE_D_4 , 4, 4, 1},
157 {false, NOTE_C_SHARP_4, 5}, 199 {false , NOTE_C_SHARP_4 , 5, 5, 1},
158 {false, NOTE_D_4, 6}, 200 {false , NOTE_D_4 , 6, 6, 1},
159 {false, NOTE_D_4, 7}, 201 {false , NOTE_D_4 , 7, 7, 1},
160 202
161 {true, NOTE_D_4, 8}, 203 {true , NOTE_D_4 , 8, 0, 0},
162 {true, NOTE_F_4, 9}, 204 {true , NOTE_F_4 , 9, 1, 0},
163 {true, NOTE_A_4, 10}, 205 {true , NOTE_A_4 , 10, 2, 0},
164 {true, NOTE_C_5, 11}, 206 {true , NOTE_C_5 , 11, 3, 0},
165 207
166 {true, NOTE_D_4, 12}, 208 {true , NOTE_D_4 , 12, 4, 1},
167 {false, NOTE_D_4, 13}, 209 {false , NOTE_D_4 , 13, 5, 1},
168 {true, NOTE_A_4, 14}, 210 {true , NOTE_A_4 , 14, 6, 1},
169 {false, NOTE_A_5, 15}, 211 {false , NOTE_A_5 , 15, 7, 1},
170}; 212};
171 213
172static int bpm = 120; 214static int bpm = 120;
@@ -179,7 +221,8 @@ irq_timer_0(void) {
179 active_note = trig->note; 221 active_note = trig->note;
180 if (trig->trigger) { 222 if (trig->trigger) {
181 SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(trig->env_volume) 223 SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(trig->env_volume)
182 | SOUND_SQUARE_ENV_TIME(4) 224 | SOUND_SQUARE_ENV_TIME(trig->env_time)
225 | SOUND_SQUARE_ENV_INC(trig->env_direction)
183 | SOUND_SQUARE_DUTY(2); 226 | SOUND_SQUARE_DUTY(2);
184 SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note]; 227 SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note];
185 } 228 }
@@ -222,6 +265,8 @@ set_time(int bpm) {
222// - 033-033 trigger selection indicator. 265// - 033-033 trigger selection indicator.
223// - 034-034 envelope: volume label. 266// - 034-034 envelope: volume label.
224// - 035-0xx envelope: volume indicator. 267// - 035-0xx envelope: volume indicator.
268// - 0xx-0xx envelope: time label.
269// - 0xx-0xx envelope: time indicator.
225// 270//
226 271
227 272
@@ -231,6 +276,7 @@ set_time(int bpm) {
231#define SEQ_TRIG_DIST 20 276#define SEQ_TRIG_DIST 20
232#define SEQ_ENV_POS_X 10 277#define SEQ_ENV_POS_X 10
233#define SEQ_ENV_POS_Y 10 278#define SEQ_ENV_POS_Y 10
279#define SEQ_ENV_DIST 34
234 280
235size_t obj_counter = 0; 281size_t obj_counter = 0;
236 282
@@ -246,7 +292,7 @@ typedef struct SeqSprite {
246 292
247int trig_selection_loc = 1; 293int trig_selection_loc = 1;
248 294
249SeqSprite seq_sprites[36] = {0}; 295SeqSprite seq_sprites[41] = {0};
250 296
251void 297void
252init_sequencer_sprites(void) { 298init_sequencer_sprites(void) {
@@ -265,9 +311,7 @@ init_sequencer_sprites(void) {
265 311
266 seq_sprites[i].id = obj_counter++; 312 seq_sprites[i].id = obj_counter++;
267 seq_sprites[i].base_tile = base_tile; 313 seq_sprites[i].base_tile = base_tile;
268 seq_sprites[i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y); 314 seq_sprites[i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_HIDDEN | OBJ_Y_COORD(y);
269 // TODO: They should start hidden until the update function changes that.
270 // seq_sprites[i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_HIDDEN;
271 seq_sprites[i].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x); 315 seq_sprites[i].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
272 seq_sprites[i].obj_attr_2 = base_tile; 316 seq_sprites[i].obj_attr_2 = base_tile;
273 } 317 }
@@ -317,7 +361,7 @@ init_sequencer_sprites(void) {
317 seq_sprites[33].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); 361 seq_sprites[33].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
318 } 362 }
319 363
320 sprite_id = load_packed_sprite_data(&sprite_env_labels, 4, 1); 364 sprite_id = load_packed_sprite_data(&sprite_env_label_volume, 4, 1);
321 { 365 {
322 int x = SEQ_ENV_POS_X; 366 int x = SEQ_ENV_POS_X;
323 int y = SEQ_ENV_POS_Y; 367 int y = SEQ_ENV_POS_Y;
@@ -340,6 +384,66 @@ init_sequencer_sprites(void) {
340 seq_sprites[35].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x); 384 seq_sprites[35].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
341 seq_sprites[35].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); 385 seq_sprites[35].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
342 } 386 }
387
388 sprite_id = load_packed_sprite_data(&sprite_env_label_time, 4, 1);
389 {
390 int x = SEQ_ENV_POS_X + SEQ_ENV_DIST;
391 int y = SEQ_ENV_POS_Y;
392 int base_tile = sprites[sprite_id].tile_start;
393 seq_sprites[36].id = obj_counter++;
394 seq_sprites[36].base_tile = base_tile;
395 seq_sprites[36].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
396 seq_sprites[36].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
397 seq_sprites[36].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
398 }
399
400 sprite_id = load_packed_sprite_data(&sprite_env_time, 4, 8);
401 {
402 int x = SEQ_ENV_POS_X + SEQ_ENV_DIST;
403 int y = SEQ_ENV_POS_Y + 8;
404 int base_tile = sprites[sprite_id].tile_start;
405 seq_sprites[37].id = obj_counter++;
406 seq_sprites[37].base_tile = base_tile;
407 seq_sprites[37].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
408 seq_sprites[37].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
409 seq_sprites[37].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
410 }
411
412 sprite_id = load_packed_sprite_data(&sprite_env_label_direction, 4, 1);
413 {
414 int x = SEQ_ENV_POS_X + SEQ_ENV_DIST * 2;
415 int y = SEQ_ENV_POS_Y;
416 int base_tile = sprites[sprite_id].tile_start;
417 seq_sprites[38].id = obj_counter++;
418 seq_sprites[38].base_tile = base_tile;
419 seq_sprites[38].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
420 seq_sprites[38].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
421 seq_sprites[38].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
422 }
423
424 sprite_id = load_packed_sprite_data(&sprite_env_sweep_direction, 4, 2);
425 {
426 int x = SEQ_ENV_POS_X + SEQ_ENV_DIST * 2;
427 int y = SEQ_ENV_POS_Y + 8;
428 int base_tile = sprites[sprite_id].tile_start;
429 seq_sprites[39].id = obj_counter++;
430 seq_sprites[39].base_tile = base_tile;
431 seq_sprites[39].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
432 seq_sprites[39].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
433 seq_sprites[39].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
434 }
435
436 sprite_id = load_packed_sprite_data(&sprite_env_label_env, 4, 1);
437 {
438 int x = SEQ_ENV_POS_X + SEQ_ENV_DIST;
439 int y = SEQ_ENV_POS_Y - 8;
440 int base_tile = sprites[sprite_id].tile_start;
441 seq_sprites[40].id = obj_counter++;
442 seq_sprites[40].base_tile = base_tile;
443 seq_sprites[40].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
444 seq_sprites[40].obj_attr_1 = OBJ_SIZE_MID | OBJ_X_COORD(x);
445 seq_sprites[40].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
446 }
343} 447}
344 448
345void 449void
@@ -393,6 +497,22 @@ update_sequencer_sprites(void) {
393 size_t tile = base_tile + tile_diff; 497 size_t tile = base_tile + tile_diff;
394 seq_sprites[35].obj_attr_2 = tile | OBJ_PAL_BANK(2); 498 seq_sprites[35].obj_attr_2 = tile | OBJ_PAL_BANK(2);
395 } 499 }
500
501 // 38: Envelope initial volume
502 {
503 size_t tile_diff = sequence_synth[trig_selection_loc].env_time * 4;
504 size_t base_tile = seq_sprites[37].base_tile;
505 size_t tile = base_tile + tile_diff;
506 seq_sprites[37].obj_attr_2 = tile | OBJ_PAL_BANK(2);
507 }
508
509 // 40: Envelope initial volume
510 {
511 size_t tile_diff = sequence_synth[trig_selection_loc].env_direction * 4;
512 size_t base_tile = seq_sprites[39].base_tile;
513 size_t tile = base_tile + tile_diff;
514 seq_sprites[39].obj_attr_2 = tile | OBJ_PAL_BANK(2);
515 }
396} 516}
397 517
398void 518void