2525 */
2626#include "shared-bindings/audioio/Mixer.h"
2727#include "shared-module/audioio/MixerVoice.h"
28+ #include "shared-bindings/audioio/MixerVoice.h"
2829
2930#include <stdint.h>
3031
@@ -113,6 +114,7 @@ STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args,
113114
114115 for (int v = 0 ; v < voice_count ; v ++ ){
115116 self -> voice [v ] = audioio_mixervoice_type .make_new (& audioio_mixervoice_type , 0 , 0 , NULL );
117+ common_hal_audioio_mixervoice_set_parent (self -> voice [v ], self );
116118 }
117119 self -> voice_tuple = mp_obj_new_tuple (self -> voice_count , self -> voice );
118120
@@ -148,54 +150,6 @@ STATIC mp_obj_t audioio_mixer_obj___exit__(size_t n_args, const mp_obj_t *args)
148150}
149151STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audioio_mixer___exit___obj , 4 , 4 , audioio_mixer_obj___exit__ );
150152
151-
152- //| .. method:: play(sample, *, voice=0, loop=False)
153- //|
154- //| Plays the sample once when loop=False and continuously when loop=True.
155- //| Does not block. Use `playing` to block.
156- //|
157- //| Sample must be an `audioio.WaveFile`, `audioio.Mixer` or `audioio.RawSample`.
158- //|
159- //| The sample must match the Mixer's encoding settings given in the constructor.
160- //|
161- STATIC mp_obj_t audioio_mixer_obj_play (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
162- enum { ARG_sample , ARG_voice , ARG_loop };
163- static const mp_arg_t allowed_args [] = {
164- { MP_QSTR_sample , MP_ARG_OBJ | MP_ARG_REQUIRED },
165- { MP_QSTR_voice , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
166- { MP_QSTR_loop , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
167- };
168- audioio_mixer_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
169- raise_error_if_deinited (common_hal_audioio_mixer_deinited (self ));
170- mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
171- mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
172-
173- mp_obj_t sample = args [ARG_sample ].u_obj ;
174- common_hal_audioio_mixer_play (self , sample , args [ARG_voice ].u_int , args [ARG_loop ].u_bool );
175-
176- return mp_const_none ;
177- }
178- MP_DEFINE_CONST_FUN_OBJ_KW (audioio_mixer_play_obj , 1 , audioio_mixer_obj_play );
179-
180- //| .. method:: stop_voice(voice=0)
181- //|
182- //| Stops playback of the sample on the given voice.
183- //|
184- STATIC mp_obj_t audioio_mixer_obj_stop_voice (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
185- enum { ARG_voice };
186- static const mp_arg_t allowed_args [] = {
187- { MP_QSTR_voice , MP_ARG_INT , {.u_int = 0 } },
188- };
189- audioio_mixer_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
190- raise_error_if_deinited (common_hal_audioio_mixer_deinited (self ));
191- mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
192- mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
193-
194- common_hal_audioio_mixer_stop_voice (self , args [ARG_voice ].u_int );
195- return mp_const_none ;
196- }
197- MP_DEFINE_CONST_FUN_OBJ_KW (audioio_mixer_stop_voice_obj , 1 , audioio_mixer_obj_stop_voice );
198-
199153//| .. attribute:: playing
200154//|
201155//| True when any voice is being output. (read-only)
@@ -245,7 +199,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_voice_obj, audioio_mixer_obj_get_voi
245199
246200const mp_obj_property_t audioio_mixer_voice_obj = {
247201 .base .type = & mp_type_property ,
248- .proxy = {(mp_obj_t )& audioio_mixer_obj_get_voice ,
202+ .proxy = {(mp_obj_t )& audioio_mixer_get_voice_obj ,
249203 (mp_obj_t )& mp_const_none_obj ,
250204 (mp_obj_t )& mp_const_none_obj },
251205};
@@ -256,8 +210,6 @@ STATIC const mp_rom_map_elem_t audioio_mixer_locals_dict_table[] = {
256210 { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& audioio_mixer_deinit_obj ) },
257211 { MP_ROM_QSTR (MP_QSTR___enter__ ), MP_ROM_PTR (& default___enter___obj ) },
258212 { MP_ROM_QSTR (MP_QSTR___exit__ ), MP_ROM_PTR (& audioio_mixer___exit___obj ) },
259- { MP_ROM_QSTR (MP_QSTR_play ), MP_ROM_PTR (& audioio_mixer_play_obj ) },
260- { MP_ROM_QSTR (MP_QSTR_stop_voice ), MP_ROM_PTR (& audioio_mixer_stop_voice_obj ) },
261213
262214 // Properties
263215 { MP_ROM_QSTR (MP_QSTR_playing ), MP_ROM_PTR (& audioio_mixer_playing_obj ) },
0 commit comments