Skip to content

Commit

Permalink
Merge pull request #9861 from pdw-mb/mixervoice-loop-property
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler authored Dec 5, 2024
2 parents b481f1f + 413e577 commit 8eb1103
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shared-bindings/audiomixer/MixerVoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ MP_PROPERTY_GETSET(audiomixer_mixervoice_level_obj,
(mp_obj_t)&audiomixer_mixervoice_get_level_obj,
(mp_obj_t)&audiomixer_mixervoice_set_level_obj);

//| loop: bool
//| """Get or set the loop status of the currently playing sample."""
static mp_obj_t audiomixer_mixervoice_obj_get_loop(mp_obj_t self_in) {
return mp_obj_new_bool(common_hal_audiomixer_mixervoice_get_loop(self_in));
}
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixervoice_get_loop_obj, audiomixer_mixervoice_obj_get_loop);

static mp_obj_t audiomixer_mixervoice_obj_set_loop(mp_obj_t self_in, mp_obj_t loop_in) {
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);
bool loop = mp_obj_is_true(loop_in);
common_hal_audiomixer_mixervoice_set_loop(self, loop);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(audiomixer_mixervoice_set_loop_obj, audiomixer_mixervoice_obj_set_loop);

MP_PROPERTY_GETSET(audiomixer_mixervoice_loop_obj,
(mp_obj_t)&audiomixer_mixervoice_get_loop_obj,
(mp_obj_t)&audiomixer_mixervoice_set_loop_obj);

//| playing: bool
//| """True when this voice is being output. (read-only)"""
//|
Expand All @@ -117,6 +136,7 @@ static const mp_rom_map_elem_t audiomixer_mixervoice_locals_dict_table[] = {
// Properties
{ MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiomixer_mixervoice_playing_obj) },
{ MP_ROM_QSTR(MP_QSTR_level), MP_ROM_PTR(&audiomixer_mixervoice_level_obj) },
{ MP_ROM_QSTR(MP_QSTR_loop), MP_ROM_PTR(&audiomixer_mixervoice_loop_obj) },
};
static MP_DEFINE_CONST_DICT(audiomixer_mixervoice_locals_dict, audiomixer_mixervoice_locals_dict_table);

Expand Down
3 changes: 3 additions & 0 deletions shared-bindings/audiomixer/MixerVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ mp_float_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_
void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_float_t gain);

bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t *self);

void common_hal_audiomixer_mixervoice_set_loop(audiomixer_mixervoice_obj_t *self, bool loop);
bool common_hal_audiomixer_mixervoice_get_loop(audiomixer_mixervoice_obj_t *self);
8 changes: 8 additions & 0 deletions shared-module/audiomixer/MixerVoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *sel
self->level = (uint16_t)(level * (1 << 15));
}

bool common_hal_audiomixer_mixervoice_get_loop(audiomixer_mixervoice_obj_t *self) {
return self->loop;
}

void common_hal_audiomixer_mixervoice_set_loop(audiomixer_mixervoice_obj_t *self, bool loop) {
self->loop = loop;
}

void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop) {
if (audiosample_sample_rate(sample) != self->parent->sample_rate) {
mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_sample_rate);
Expand Down

0 comments on commit 8eb1103

Please sign in to comment.