|
69 | 69 | #define SOUND_EFFECT_FX_VIBRATO (1)
|
70 | 70 | #define SOUND_EFFECT_FX_WARBLE (3)
|
71 | 71 |
|
| 72 | +// These default fx values are the same as used by MakeCode. |
| 73 | +#define SOUND_EFFECT_FX_VIBRATO_DEFAULT_PARAM (2) |
| 74 | +#define SOUND_EFFECT_FX_TREMOLO_DEFAULT_PARAM (3) |
| 75 | +#define SOUND_EFFECT_FX_WARBLE_DEFAULT_PARAM (2) |
| 76 | +#define SOUND_EFFECT_FX_VIBRATO_DEFAULT_STEPS (512) |
| 77 | +#define SOUND_EFFECT_FX_TREMOLO_DEFAULT_STEPS (900) |
| 78 | +#define SOUND_EFFECT_FX_WARBLE_DEFAULT_STEPS (700) |
| 79 | + |
72 | 80 | #define SOUND_EFFECT_DEFAULT_FREQ_START (500)
|
73 | 81 | #define SOUND_EFFECT_DEFAULT_FREQ_END (2500)
|
74 | 82 | #define SOUND_EFFECT_DEFAULT_DURATION (500)
|
@@ -116,6 +124,18 @@ STATIC const soundeffect_attr_t soundeffect_attr_table[] = {
|
116 | 124 | { MP_QSTR_shape, SOUND_EXPR_SHAPE_OFFSET, SOUND_EXPR_SHAPE_LENGTH },
|
117 | 125 | };
|
118 | 126 |
|
| 127 | +static const uint8_t fx_default_param[] = { |
| 128 | + [SOUND_EFFECT_FX_VIBRATO] = SOUND_EFFECT_FX_VIBRATO_DEFAULT_PARAM, |
| 129 | + [SOUND_EFFECT_FX_TREMOLO] = SOUND_EFFECT_FX_TREMOLO_DEFAULT_PARAM, |
| 130 | + [SOUND_EFFECT_FX_WARBLE] = SOUND_EFFECT_FX_WARBLE_DEFAULT_PARAM, |
| 131 | +}; |
| 132 | + |
| 133 | +static const uint16_t fx_default_steps[] = { |
| 134 | + [SOUND_EFFECT_FX_VIBRATO] = SOUND_EFFECT_FX_VIBRATO_DEFAULT_STEPS, |
| 135 | + [SOUND_EFFECT_FX_TREMOLO] = SOUND_EFFECT_FX_TREMOLO_DEFAULT_STEPS, |
| 136 | + [SOUND_EFFECT_FX_WARBLE] = SOUND_EFFECT_FX_WARBLE_DEFAULT_STEPS, |
| 137 | +}; |
| 138 | + |
119 | 139 | const char *microbit_soundeffect_get_sound_expr_data(mp_obj_t self_in) {
|
120 | 140 | const microbit_soundeffect_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
121 | 141 | return &self->sound_expr[0];
|
@@ -273,6 +293,11 @@ STATIC void microbit_soundeffect_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des
|
273 | 293 | if (self->is_mutable) {
|
274 | 294 | unsigned int value = mp_obj_get_int(dest[1]);
|
275 | 295 | sound_expr_encode(self, soundeffect_attr->offset, soundeffect_attr->length, value);
|
| 296 | + if (soundeffect_attr->offset == SOUND_EXPR_FX_CHOICE_OFFSET) { |
| 297 | + // Changing the fx choice, so also update the fx parameters for that choice. |
| 298 | + sound_expr_encode(self, SOUND_EXPR_FX_PARAM_OFFSET, SOUND_EXPR_FX_PARAM_LENGTH, fx_default_param[value]); |
| 299 | + sound_expr_encode(self, SOUND_EXPR_FX_STEPS_OFFSET, SOUND_EXPR_FX_STEPS_LENGTH, fx_default_steps[value]); |
| 300 | + } |
276 | 301 | dest[0] = MP_OBJ_NULL; // Indicate store succeeded.
|
277 | 302 | }
|
278 | 303 | }
|
|
0 commit comments