diff options
author | Bad Diode <bd@badd10de.dev> | 2023-07-21 18:15:39 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-07-21 18:15:39 +0200 |
commit | 293ac066f324964739efa7d34a0e01ef8af43e89 (patch) | |
tree | ed1ee93ec57136e9f0777865ec61e25933c55479 | |
parent | 53729509f4f39690f025902df07bc38fc898ec65 (diff) | |
download | stepper-293ac066f324964739efa7d34a0e01ef8af43e89.tar.gz stepper-293ac066f324964739efa7d34a0e01ef8af43e89.zip |
Change behaviour of ch3 on empty trigs: stop sound
-rw-r--r-- | src/globals.c | 4 | ||||
-rw-r--r-- | src/sequencer.c | 55 |
2 files changed, 45 insertions, 14 deletions
diff --git a/src/globals.c b/src/globals.c index 724ff10..758f3b5 100644 --- a/src/globals.c +++ b/src/globals.c | |||
@@ -59,6 +59,10 @@ bool clear_screen = true; | |||
59 | #define PARAMS_H 52 | 59 | #define PARAMS_H 52 |
60 | #define PARAMS_START_X 32 | 60 | #define PARAMS_START_X 32 |
61 | #define PARAMS_START_Y 22 | 61 | #define PARAMS_START_Y 22 |
62 | #define PARAMS_BOX_W 30 | ||
63 | #define PARAMS_BOX_H 24 | ||
64 | #define PARAMS_BOX_OFFSET_X (PARAMS_BOX_W + 4) | ||
65 | #define PARAMS_BOX_OFFSET_Y (PARAMS_BOX_H + 4) | ||
62 | 66 | ||
63 | #define R_SIDEBAR_X ((TRIG_START_X) + (TRIG_OFFSET_X) * 8 + 4) | 67 | #define R_SIDEBAR_X ((TRIG_START_X) + (TRIG_OFFSET_X) * 8 + 4) |
64 | #define L_SIDEBAR_X ((CHAN_START_X) - 26) | 68 | #define L_SIDEBAR_X ((CHAN_START_X) - 26) |
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) { | |||
95 | TriggerNote *trig = &pat->ch1.notes[step_counter]; | 95 | TriggerNote *trig = &pat->ch1.notes[step_counter]; |
96 | ChannelSquareParams *params = &pat->ch1.params[step_counter]; | 96 | ChannelSquareParams *params = &pat->ch1.params[step_counter]; |
97 | if (trig->active) { | 97 | if (trig->active) { |
98 | SOUND_SQUARE1_SWEEP = SOUND_SWEEP_NUMBER(params->sweep_number) | 98 | if (params->sweep_time == 0) { |
99 | | SOUND_SWEEP_DIR(params->sweep_direction) | 99 | SOUND_SQUARE1_SWEEP = SOUND_SWEEP_DIR(1); |
100 | | SOUND_SWEEP_TIME(params->sweep_time); | 100 | } else { |
101 | SOUND_SQUARE1_SWEEP = SOUND_SWEEP_NUMBER(params->sweep_number) | ||
102 | | SOUND_SWEEP_DIR(params->sweep_direction) | ||
103 | | SOUND_SWEEP_TIME(params->sweep_time); | ||
104 | } | ||
101 | SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) | 105 | SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) |
102 | | SOUND_SQUARE_ENV_TIME(params->env_time) | 106 | | SOUND_SQUARE_ENV_TIME(params->env_time) |
103 | | SOUND_SQUARE_ENV_DIR(params->env_direction) | 107 | | SOUND_SQUARE_ENV_DIR(params->env_direction) |
104 | | SOUND_SQUARE_DUTY(params->duty_cycle); | 108 | | SOUND_SQUARE_DUTY(params->duty_cycle); |
105 | SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET | 109 | SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET |
106 | | sound_rates[trig->note]; | 110 | | sound_rates[trig->note]; |
111 | // Re-initialize the sound after 8 cycles if using sweeps. | ||
112 | if (params->sweep_time != 0) { | ||
113 | asm("nop"); asm("nop"); | ||
114 | asm("nop"); asm("nop"); | ||
115 | asm("nop"); asm("nop"); | ||
116 | asm("nop"); asm("nop"); | ||
117 | SOUND_SQUARE1_SWEEP = SOUND_SWEEP_NUMBER(params->sweep_number) | ||
118 | | SOUND_SWEEP_DIR(params->sweep_direction) | ||
119 | | SOUND_SWEEP_TIME(params->sweep_time); | ||
120 | SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET | ||
121 | | sound_rates[trig->note]; | ||
122 | SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) | ||
123 | | SOUND_SQUARE_ENV_TIME(params->env_time) | ||
124 | | SOUND_SQUARE_ENV_DIR(params->env_direction) | ||
125 | | SOUND_SQUARE_DUTY(params->duty_cycle); | ||
126 | } | ||
107 | } | 127 | } |
108 | } else { | 128 | } else { |
109 | SOUND_SQUARE1_SWEEP = 0; | 129 | SOUND_SQUARE1_SWEEP = 0; |
110 | SOUND_SQUARE1_CTRL = 0; | ||
111 | SOUND_SQUARE1_FREQ = 0; | 130 | SOUND_SQUARE1_FREQ = 0; |
131 | SOUND_SQUARE1_CTRL = 0; | ||
112 | } | 132 | } |
113 | if (pat->ch2.active) { | 133 | if (pat->ch2.active) { |
114 | TriggerNote *trig = &pat->ch2.notes[step_counter]; | 134 | TriggerNote *trig = &pat->ch2.notes[step_counter]; |
115 | ChannelSquareParams *params = &pat->ch2.params[step_counter]; | 135 | ChannelSquareParams *params = &pat->ch2.params[step_counter]; |
116 | if (trig->active) { | 136 | if (trig->active) { |
137 | SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET | ||
138 | | sound_rates[trig->note]; | ||
117 | SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) | 139 | SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(params->env_volume) |
118 | | SOUND_SQUARE_ENV_TIME(params->env_time) | 140 | | SOUND_SQUARE_ENV_TIME(params->env_time) |
119 | | SOUND_SQUARE_ENV_DIR(params->env_direction) | 141 | | SOUND_SQUARE_ENV_DIR(params->env_direction) |
120 | | SOUND_SQUARE_DUTY(params->duty_cycle); | 142 | | SOUND_SQUARE_DUTY(params->duty_cycle); |
121 | SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET | ||
122 | | sound_rates[trig->note]; | ||
123 | } | 143 | } |
124 | } else { | 144 | } else { |
125 | SOUND_SQUARE2_CTRL = 0; | ||
126 | SOUND_SQUARE2_FREQ = 0; | 145 | SOUND_SQUARE2_FREQ = 0; |
146 | SOUND_SQUARE2_CTRL = 0; | ||
127 | } | 147 | } |
128 | if (pat->ch3.active) { | 148 | if (pat->ch3.active) { |
129 | TriggerNote *trig = &pat->ch3.notes[step_counter]; | 149 | TriggerNote *trig = &pat->ch3.notes[step_counter]; |
130 | ChannelWaveParams *params = &pat->ch3.params[step_counter]; | 150 | ChannelWaveParams *params = &pat->ch3.params[step_counter]; |
131 | if (trig->active) { | 151 | if (trig->active) { |
152 | // TODO: If we find an empty trigger stop the sound. | ||
132 | switch (params->wave_mode) { | 153 | switch (params->wave_mode) { |
133 | case 0: { | 154 | case 0: { |
134 | SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1); | 155 | SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1); |
@@ -153,6 +174,8 @@ play_step(void) { | |||
153 | } | 174 | } |
154 | SOUND_WAVE_MODE |= SOUND_WAVE_ENABLE; | 175 | SOUND_WAVE_MODE |= SOUND_WAVE_ENABLE; |
155 | 176 | ||
177 | SOUND_WAVE_FREQ = SOUND_FREQ_RESET | ||
178 | | sound_rates[trig->note]; | ||
156 | switch (params->wave_volume) { | 179 | switch (params->wave_volume) { |
157 | case 0: { SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; } break; | 180 | case 0: { SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; } break; |
158 | case 1: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_25; } break; | 181 | case 1: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_25; } break; |
@@ -160,12 +183,16 @@ play_step(void) { | |||
160 | case 3: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_75; } break; | 183 | case 3: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_75; } break; |
161 | case 4: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_100; } break; | 184 | case 4: { SOUND_WAVE_CTRL = SOUND_WAVE_VOL_100; } break; |
162 | } | 185 | } |
163 | SOUND_WAVE_FREQ = SOUND_FREQ_RESET | 186 | } else { |
164 | | sound_rates[trig->note]; | 187 | // NOTE: Maybe in the future we want an AD, but for now this is |
188 | // probably better than holding the notes. Or perhaps add a hold | ||
189 | // mode? | ||
190 | SOUND_WAVE_FREQ = 0; | ||
191 | SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; | ||
165 | } | 192 | } |
166 | } else { | 193 | } else { |
167 | SOUND_WAVE_CTRL = 0; | ||
168 | SOUND_WAVE_FREQ = 0; | 194 | SOUND_WAVE_FREQ = 0; |
195 | SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; | ||
169 | } | 196 | } |
170 | if (pat->ch4.active) { | 197 | if (pat->ch4.active) { |
171 | TriggerNote *trig = &pat->ch4.notes[step_counter]; | 198 | TriggerNote *trig = &pat->ch4.notes[step_counter]; |
@@ -187,18 +214,18 @@ play_step(void) { | |||
187 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, | 214 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, |
188 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 215 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
189 | }; | 216 | }; |
190 | SOUND_NOISE_CTRL = SOUND_NOISE_ENV_VOL(params->env_volume) | ||
191 | | SOUND_NOISE_ENV_TIME(params->env_time) | ||
192 | | SOUND_NOISE_ENV_DIR(params->env_direction); | ||
193 | SOUND_NOISE_FREQ = SOUND_FREQ_RESET | 217 | SOUND_NOISE_FREQ = SOUND_FREQ_RESET |
194 | | SOUND_NOISE_PRESTEP_FREQ(pre_freq[trig->note]) | 218 | | SOUND_NOISE_PRESTEP_FREQ(pre_freq[trig->note]) |
195 | | SOUND_NOISE_DIV_FREQ(div_freq[trig->note]) | 219 | | SOUND_NOISE_DIV_FREQ(div_freq[trig->note]) |
196 | | SOUND_NOISE_COUNTER_STAGE(params->bit_mode) | 220 | | SOUND_NOISE_COUNTER_STAGE(params->bit_mode) |
197 | | SOUND_NOISE_TIMED_MODE(0); | 221 | | SOUND_NOISE_TIMED_MODE(0); |
222 | SOUND_NOISE_CTRL = SOUND_NOISE_ENV_VOL(params->env_volume) | ||
223 | | SOUND_NOISE_ENV_TIME(params->env_time) | ||
224 | | SOUND_NOISE_ENV_DIR(params->env_direction); | ||
198 | } | 225 | } |
199 | } else { | 226 | } else { |
200 | SOUND_NOISE_CTRL = 0; | ||
201 | SOUND_NOISE_FREQ = 0; | 227 | SOUND_NOISE_FREQ = 0; |
228 | SOUND_NOISE_CTRL = 0; | ||
202 | } | 229 | } |
203 | 230 | ||
204 | switch (settings.sync) { | 231 | switch (settings.sync) { |