From 293ac066f324964739efa7d34a0e01ef8af43e89 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 21 Jul 2023 18:15:39 +0200 Subject: Change behaviour of ch3 on empty trigs: stop sound --- src/sequencer.c | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'src/sequencer.c') diff --git a/src/sequencer.c b/src/sequencer.c index 038b608..c544f67 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -95,40 +95,61 @@ play_step(void) { TriggerNote *trig = &pat->ch1.notes[step_counter]; ChannelSquareParams *params = &pat->ch1.params[step_counter]; if (trig->active) { - SOUND_SQUARE1_SWEEP = SOUND_SWEEP_NUMBER(params->sweep_number) - | SOUND_SWEEP_DIR(params->sweep_direction) - | SOUND_SWEEP_TIME(params->sweep_time); + if (params->sweep_time == 0) { + SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); + } else { + SOUND_SQUARE1_SWEEP = SOUND_SWEEP_NUMBER(params->sweep_number) + | SOUND_SWEEP_DIR(params->sweep_direction) + | SOUND_SWEEP_TIME(params->sweep_time); + } SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) | SOUND_SQUARE_ENV_TIME(params->env_time) | SOUND_SQUARE_ENV_DIR(params->env_direction) | SOUND_SQUARE_DUTY(params->duty_cycle); SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET | sound_rates[trig->note]; + // Re-initialize the sound after 8 cycles if using sweeps. + if (params->sweep_time != 0) { + asm("nop"); asm("nop"); + asm("nop"); asm("nop"); + asm("nop"); asm("nop"); + asm("nop"); asm("nop"); + SOUND_SQUARE1_SWEEP = SOUND_SWEEP_NUMBER(params->sweep_number) + | SOUND_SWEEP_DIR(params->sweep_direction) + | SOUND_SWEEP_TIME(params->sweep_time); + SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET + | sound_rates[trig->note]; + SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) + | SOUND_SQUARE_ENV_TIME(params->env_time) + | SOUND_SQUARE_ENV_DIR(params->env_direction) + | SOUND_SQUARE_DUTY(params->duty_cycle); + } } } else { SOUND_SQUARE1_SWEEP = 0; - SOUND_SQUARE1_CTRL = 0; SOUND_SQUARE1_FREQ = 0; + SOUND_SQUARE1_CTRL = 0; } if (pat->ch2.active) { TriggerNote *trig = &pat->ch2.notes[step_counter]; ChannelSquareParams *params = &pat->ch2.params[step_counter]; if (trig->active) { + SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET + | sound_rates[trig->note]; SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) | SOUND_SQUARE_ENV_TIME(params->env_time) | SOUND_SQUARE_ENV_DIR(params->env_direction) | SOUND_SQUARE_DUTY(params->duty_cycle); - SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET - | sound_rates[trig->note]; } } else { - SOUND_SQUARE2_CTRL = 0; SOUND_SQUARE2_FREQ = 0; + SOUND_SQUARE2_CTRL = 0; } if (pat->ch3.active) { TriggerNote *trig = &pat->ch3.notes[step_counter]; ChannelWaveParams *params = &pat->ch3.params[step_counter]; if (trig->active) { + // TODO: If we find an empty trigger stop the sound. switch (params->wave_mode) { case 0: { SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1); @@ -153,6 +174,8 @@ play_step(void) { } SOUND_WAVE_MODE |= SOUND_WAVE_ENABLE; + SOUND_WAVE_FREQ = SOUND_FREQ_RESET + | sound_rates[trig->note]; switch (params->wave_volume) { case 0: { SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; } break; case 1: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_25; } break; @@ -160,12 +183,16 @@ play_step(void) { case 3: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_75; } break; case 4: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_100; } break; } - SOUND_WAVE_FREQ = SOUND_FREQ_RESET - | sound_rates[trig->note]; + } else { + // NOTE: Maybe in the future we want an AD, but for now this is + // probably better than holding the notes. Or perhaps add a hold + // mode? + SOUND_WAVE_FREQ = 0; + SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; } } else { - SOUND_WAVE_CTRL = 0; SOUND_WAVE_FREQ = 0; + SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; } if (pat->ch4.active) { TriggerNote *trig = &pat->ch4.notes[step_counter]; @@ -187,18 +214,18 @@ play_step(void) { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - SOUND_NOISE_CTRL = SOUND_NOISE_ENV_VOL(params->env_volume) - | SOUND_NOISE_ENV_TIME(params->env_time) - | SOUND_NOISE_ENV_DIR(params->env_direction); SOUND_NOISE_FREQ = SOUND_FREQ_RESET | SOUND_NOISE_PRESTEP_FREQ(pre_freq[trig->note]) | SOUND_NOISE_DIV_FREQ(div_freq[trig->note]) | SOUND_NOISE_COUNTER_STAGE(params->bit_mode) | SOUND_NOISE_TIMED_MODE(0); + SOUND_NOISE_CTRL = SOUND_NOISE_ENV_VOL(params->env_volume) + | SOUND_NOISE_ENV_TIME(params->env_time) + | SOUND_NOISE_ENV_DIR(params->env_direction); } } else { - SOUND_NOISE_CTRL = 0; SOUND_NOISE_FREQ = 0; + SOUND_NOISE_CTRL = 0; } switch (settings.sync) { -- cgit v1.2.1