|
29 | 29 | #include "py/obj.h" |
30 | 30 | #include "py/runtime.h" |
31 | 31 |
|
32 | | -#include "shared-bindings/microcontroller/Pin.h" |
33 | 32 | #include "shared-bindings/audiocore/__init__.h" |
34 | 33 | #include "shared-bindings/audiocore/RawSample.h" |
35 | 34 | #include "shared-bindings/audiocore/WaveFile.h" |
36 | 35 | // #include "shared-bindings/audiomixer/Mixer.h" |
37 | 36 |
|
38 | 37 | //| """Support for audio samples""" |
39 | 38 |
|
| 39 | +#if CIRCUITPY_AUDIOCORE_DEBUG |
| 40 | +// (no docstrings so that the debug functions are not shown on docs.circuitpython.org) |
| 41 | +STATIC mp_obj_t audiocore_get_buffer(mp_obj_t sample_in) { |
| 42 | + uint8_t *buffer = NULL; |
| 43 | + uint32_t buffer_length = 0; |
| 44 | + audioio_get_buffer_result_t gbr = audiosample_get_buffer(sample_in, false, 0, &buffer, &buffer_length); |
| 45 | + |
| 46 | + mp_obj_t result[2] = {mp_obj_new_int_from_uint(gbr), mp_const_none}; |
| 47 | + |
| 48 | + if (gbr != GET_BUFFER_ERROR) { |
| 49 | + // copies the data because the gc semantics of get_buffer are unclear |
| 50 | + result[1] = mp_obj_new_bytes(buffer, buffer_length); |
| 51 | + } |
| 52 | + |
| 53 | + return mp_obj_new_tuple(2, result); |
| 54 | +} |
| 55 | +STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_get_buffer_obj, audiocore_get_buffer); |
| 56 | + |
| 57 | +STATIC mp_obj_t audiocore_get_structure(mp_obj_t sample_in) { |
| 58 | + bool single_buffer, samples_signed; |
| 59 | + uint32_t max_buffer_length; |
| 60 | + uint8_t spacing; |
| 61 | + |
| 62 | + audiosample_get_buffer_structure(sample_in, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); |
| 63 | + mp_obj_t result[4] = { |
| 64 | + mp_obj_new_int_from_uint(single_buffer), |
| 65 | + mp_obj_new_int_from_uint(samples_signed), |
| 66 | + mp_obj_new_int_from_uint(max_buffer_length), |
| 67 | + mp_obj_new_int_from_uint(spacing), |
| 68 | + }; |
| 69 | + return mp_obj_new_tuple(4, result); |
| 70 | +} |
| 71 | +STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_get_structure_obj, audiocore_get_structure); |
| 72 | + |
| 73 | +STATIC mp_obj_t audiocore_reset_buffer(mp_obj_t sample_in) { |
| 74 | + audiosample_reset_buffer(sample_in, false, 0); |
| 75 | + return mp_const_none; |
| 76 | +} |
| 77 | +STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_reset_buffer_obj, audiocore_reset_buffer); |
| 78 | + |
| 79 | +#endif |
| 80 | + |
40 | 81 | STATIC const mp_rom_map_elem_t audiocore_module_globals_table[] = { |
41 | 82 | { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiocore) }, |
42 | 83 | { MP_ROM_QSTR(MP_QSTR_RawSample), MP_ROM_PTR(&audioio_rawsample_type) }, |
43 | 84 | { MP_ROM_QSTR(MP_QSTR_WaveFile), MP_ROM_PTR(&audioio_wavefile_type) }, |
| 85 | + #if CIRCUITPY_AUDIOCORE_DEBUG |
| 86 | + { MP_ROM_QSTR(MP_QSTR_get_buffer), MP_ROM_PTR(&audiocore_get_buffer_obj) }, |
| 87 | + { MP_ROM_QSTR(MP_QSTR_reset_buffer), MP_ROM_PTR(&audiocore_reset_buffer_obj) }, |
| 88 | + { MP_ROM_QSTR(MP_QSTR_get_structure), MP_ROM_PTR(&audiocore_get_structure_obj) }, |
| 89 | + #endif |
44 | 90 | }; |
45 | 91 |
|
46 | 92 | STATIC MP_DEFINE_CONST_DICT(audiocore_module_globals, audiocore_module_globals_table); |
|
0 commit comments