2828#include "modmicrobit.h"
2929#include "modaudio.h"
3030
31- #define SOUND_EXPR_WAVE_OFFSET (0)
32- #define SOUND_EXPR_WAVE_LENGTH (1)
31+ #define SOUND_EXPR_WAVEFORM_OFFSET (0)
32+ #define SOUND_EXPR_WAVEFORM_LENGTH (1)
3333#define SOUND_EXPR_VOLUME_START_OFFSET (1)
3434#define SOUND_EXPR_VOLUME_START_LENGTH (4)
3535#define SOUND_EXPR_FREQUENCY_START_OFFSET (5)
5454#define SOUND_EXPR_ENCODE_VOLUME (v ) (((v) * 1023 + 127) / 255)
5555#define SOUND_EXPR_DECODE_VOLUME (v ) (((v) * 255 + 511) / 1023)
5656
57- #define SOUND_EFFECT_WAVE_SINE (0)
58- #define SOUND_EFFECT_WAVE_SAWTOOTH (1)
59- #define SOUND_EFFECT_WAVE_TRIANGLE (2)
60- #define SOUND_EFFECT_WAVE_SQUARE (3)
61- #define SOUND_EFFECT_WAVE_NOISE (4)
57+ #define SOUND_EFFECT_WAVEFORM_SINE (0)
58+ #define SOUND_EFFECT_WAVEFORM_SAWTOOTH (1)
59+ #define SOUND_EFFECT_WAVEFORM_TRIANGLE (2)
60+ #define SOUND_EFFECT_WAVEFORM_SQUARE (3)
61+ #define SOUND_EFFECT_WAVEFORM_NOISE (4)
6262
6363#define SOUND_EFFECT_SHAPE_LINEAR (1)
6464#define SOUND_EFFECT_SHAPE_CURVE (2)
7474#define SOUND_EFFECT_DEFAULT_DURATION (500)
7575#define SOUND_EFFECT_DEFAULT_VOL_START (255)
7676#define SOUND_EFFECT_DEFAULT_VOL_END (0)
77- #define SOUND_EFFECT_DEFAULT_WAVE (SOUND_EFFECT_WAVE_SQUARE )
77+ #define SOUND_EFFECT_DEFAULT_WAVEFORM (SOUND_EFFECT_WAVEFORM_SQUARE )
7878#define SOUND_EFFECT_DEFAULT_FX (SOUND_EFFECT_FX_NONE)
7979#define SOUND_EFFECT_DEFAULT_SHAPE (SOUND_EFFECT_SHAPE_LOG)
8080
@@ -90,12 +90,12 @@ typedef struct _soundeffect_attr_t {
9090 uint8_t length ;
9191} soundeffect_attr_t ;
9292
93- STATIC const uint16_t wave_to_qstr_table [5 ] = {
94- [SOUND_EFFECT_WAVE_SINE ] = MP_QSTR_WAVE_SINE ,
95- [SOUND_EFFECT_WAVE_SAWTOOTH ] = MP_QSTR_WAVE_SAWTOOTH ,
96- [SOUND_EFFECT_WAVE_TRIANGLE ] = MP_QSTR_WAVE_TRIANGLE ,
97- [SOUND_EFFECT_WAVE_SQUARE ] = MP_QSTR_WAVE_SQUARE ,
98- [SOUND_EFFECT_WAVE_NOISE ] = MP_QSTR_WAVE_NOISE ,
93+ STATIC const uint16_t waveform_to_qstr_table [5 ] = {
94+ [SOUND_EFFECT_WAVEFORM_SINE ] = MP_QSTR_WAVEFORM_SINE ,
95+ [SOUND_EFFECT_WAVEFORM_SAWTOOTH ] = MP_QSTR_WAVEFORM_SAWTOOTH ,
96+ [SOUND_EFFECT_WAVEFORM_TRIANGLE ] = MP_QSTR_WAVEFORM_TRIANGLE ,
97+ [SOUND_EFFECT_WAVEFORM_SQUARE ] = MP_QSTR_WAVEFORM_SQUARE ,
98+ [SOUND_EFFECT_WAVEFORM_NOISE ] = MP_QSTR_WAVEFORM_NOISE ,
9999};
100100
101101STATIC const uint16_t fx_to_qstr_table [4 ] = {
@@ -111,7 +111,7 @@ STATIC const soundeffect_attr_t soundeffect_attr_table[] = {
111111 { MP_QSTR_duration , SOUND_EXPR_DURATION_OFFSET , SOUND_EXPR_DURATION_LENGTH },
112112 { MP_QSTR_vol_start , SOUND_EXPR_VOLUME_START_OFFSET , SOUND_EXPR_VOLUME_START_LENGTH },
113113 { MP_QSTR_vol_end , SOUND_EXPR_VOLUME_END_OFFSET , SOUND_EXPR_VOLUME_END_LENGTH },
114- { MP_QSTR_wave , SOUND_EXPR_WAVE_OFFSET , SOUND_EXPR_WAVE_LENGTH },
114+ { MP_QSTR_waveform , SOUND_EXPR_WAVEFORM_OFFSET , SOUND_EXPR_WAVEFORM_LENGTH },
115115 { MP_QSTR_fx , SOUND_EXPR_FX_CHOICE_OFFSET , SOUND_EXPR_FX_CHOICE_LENGTH },
116116 { MP_QSTR_shape , SOUND_EXPR_SHAPE_OFFSET , SOUND_EXPR_SHAPE_LENGTH },
117117};
@@ -150,7 +150,7 @@ STATIC void microbit_soundeffect_print(const mp_print_t *print, mp_obj_t self_in
150150 unsigned int duration = sound_expr_decode (self , SOUND_EXPR_DURATION_OFFSET , SOUND_EXPR_DURATION_LENGTH );
151151 unsigned int vol_start = sound_expr_decode (self , SOUND_EXPR_VOLUME_START_OFFSET , SOUND_EXPR_VOLUME_START_LENGTH );
152152 unsigned int vol_end = sound_expr_decode (self , SOUND_EXPR_VOLUME_END_OFFSET , SOUND_EXPR_VOLUME_END_LENGTH );
153- unsigned int wave = sound_expr_decode (self , SOUND_EXPR_WAVE_OFFSET , SOUND_EXPR_WAVE_LENGTH );
153+ unsigned int waveform = sound_expr_decode (self , SOUND_EXPR_WAVEFORM_OFFSET , SOUND_EXPR_WAVEFORM_LENGTH );
154154 unsigned int fx = sound_expr_decode (self , SOUND_EXPR_FX_CHOICE_OFFSET , SOUND_EXPR_FX_CHOICE_LENGTH );
155155 unsigned int shape = sound_expr_decode (self , SOUND_EXPR_SHAPE_OFFSET , SOUND_EXPR_SHAPE_LENGTH );
156156
@@ -161,14 +161,14 @@ STATIC void microbit_soundeffect_print(const mp_print_t *print, mp_obj_t self_in
161161 "duration=%d, "
162162 "vol_start=%d, "
163163 "vol_end=%d, "
164- "wave =%q, "
164+ "waveform =%q, "
165165 "fx=%q, " ,
166166 freq_start ,
167167 freq_end ,
168168 duration ,
169169 vol_start ,
170170 vol_end ,
171- wave_to_qstr_table [ wave ],
171+ waveform_to_qstr_table [ waveform ],
172172 fx_to_qstr_table [fx ]
173173 );
174174
@@ -190,21 +190,21 @@ STATIC void microbit_soundeffect_print(const mp_print_t *print, mp_obj_t self_in
190190 } else {
191191 // PRINT_REPR
192192 mp_printf (print , "SoundEffect(%d, %d, %d, %d, %d, %d, %d, %d)" ,
193- freq_start , freq_end , duration , vol_start , vol_end , wave , fx , shape );
193+ freq_start , freq_end , duration , vol_start , vol_end , waveform , fx , shape );
194194 }
195195}
196196
197197// Constructor:
198- // SoundEffect(freq_start, freq_end, duration, vol_start, vol_end, wave , fx, shape)
198+ // SoundEffect(freq_start, freq_end, duration, vol_start, vol_end, waveform , fx, shape)
199199STATIC mp_obj_t microbit_soundeffect_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args_in ) {
200- enum { ARG_freq_start , ARG_freq_end , ARG_duration , ARG_vol_start , ARG_vol_end , ARG_wave , ARG_fx , ARG_shape };
200+ enum { ARG_freq_start , ARG_freq_end , ARG_duration , ARG_vol_start , ARG_vol_end , ARG_waveform , ARG_fx , ARG_shape };
201201 static const mp_arg_t allowed_args [] = {
202202 { MP_QSTR_freq_start , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_FREQ_START } },
203203 { MP_QSTR_freq_end , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_FREQ_END } },
204204 { MP_QSTR_duration , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_DURATION } },
205205 { MP_QSTR_vol_start , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_VOL_START } },
206206 { MP_QSTR_vol_end , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_VOL_END } },
207- { MP_QSTR_wave , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_WAVE } },
207+ { MP_QSTR_waveform , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_WAVEFORM } },
208208 { MP_QSTR_fx , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_FX } },
209209 { MP_QSTR_shape , MP_ARG_INT , {.u_int = SOUND_EFFECT_DEFAULT_SHAPE } },
210210 };
@@ -230,7 +230,7 @@ STATIC mp_obj_t microbit_soundeffect_make_new(const mp_obj_type_t *type, size_t
230230 sound_expr_encode (self , SOUND_EXPR_DURATION_OFFSET , SOUND_EXPR_DURATION_LENGTH , args [ARG_duration ].u_int );
231231 sound_expr_encode (self , SOUND_EXPR_VOLUME_START_OFFSET , SOUND_EXPR_VOLUME_START_LENGTH , args [ARG_vol_start ].u_int );
232232 sound_expr_encode (self , SOUND_EXPR_VOLUME_END_OFFSET , SOUND_EXPR_VOLUME_END_LENGTH , args [ARG_vol_end ].u_int );
233- sound_expr_encode (self , SOUND_EXPR_WAVE_OFFSET , SOUND_EXPR_WAVE_LENGTH , args [ARG_wave ].u_int );
233+ sound_expr_encode (self , SOUND_EXPR_WAVEFORM_OFFSET , SOUND_EXPR_WAVEFORM_LENGTH , args [ARG_waveform ].u_int );
234234 sound_expr_encode (self , SOUND_EXPR_FX_CHOICE_OFFSET , SOUND_EXPR_FX_CHOICE_LENGTH , args [ARG_fx ].u_int );
235235 sound_expr_encode (self , SOUND_EXPR_SHAPE_OFFSET , SOUND_EXPR_SHAPE_LENGTH , args [ARG_shape ].u_int );
236236
@@ -313,11 +313,11 @@ STATIC const mp_rom_map_elem_t microbit_soundeffect_locals_dict_table[] = {
313313 // Class constants.
314314 #define C (NAME ) { MP_ROM_QSTR (MP_QSTR_ ## NAME ), MP_ROM_INT (SOUND_EFFECT_ ## NAME ) }
315315
316- C (WAVE_SINE ),
317- C (WAVE_SAWTOOTH ),
318- C (WAVE_TRIANGLE ),
319- C (WAVE_SQUARE ),
320- C (WAVE_NOISE ),
316+ C (WAVEFORM_SINE ),
317+ C (WAVEFORM_SAWTOOTH ),
318+ C (WAVEFORM_TRIANGLE ),
319+ C (WAVEFORM_SQUARE ),
320+ C (WAVEFORM_NOISE ),
321321
322322 C (SHAPE_LINEAR ),
323323 C (SHAPE_CURVE ),
0 commit comments