34
34
#include "supervisor/shared/translate.h"
35
35
36
36
//|class WaveFile:
37
- //| """.. currentmodule:: audiocore
37
+ //|""".. currentmodule:: audiocore
38
38
//|
39
- //| :class:`WaveFile` -- Load a wave file for audio playback
40
- //| ========================================================
39
+ //|:class:`WaveFile` -- Load a wave file for audio playback
40
+ //|========================================================
41
41
//|
42
- //| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
43
- //| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
44
- //| an internal buffer."""
45
- //| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
46
- //| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
42
+ //|A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
43
+ //|be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
44
+ //|an internal buffer."""
45
+ //|def __init__(self, file: typing.BinaryIO, buffer: bytearray):
46
+ //|"""Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
47
47
//|
48
- //| :param typing.BinaryIO file: Already opened wave file
49
- //| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 512 byte buffers are allocated internally.
48
+ //|:param typing.BinaryIO file: Already opened wave file
49
+ //|:param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 512 byte buffers are allocated internally.
50
50
//|
51
51
//|
52
- //| Playing a wave file from flash::
52
+ //|Playing a wave file from flash::
53
53
//|
54
- //| import board
55
- //| import audiocore
56
- //| import audioio
57
- //| import digitalio
54
+ //|import board
55
+ //|import audiocore
56
+ //|import audioio
57
+ //|import digitalio
58
58
//|
59
- //| # Required for CircuitPlayground Express
60
- //| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
61
- //| speaker_enable.switch_to_output(value=True)
59
+ //|# Required for CircuitPlayground Express
60
+ //|speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
61
+ //|speaker_enable.switch_to_output(value=True)
62
62
//|
63
- //| data = open("cplay-5.1-16bit-16khz.wav", "rb")
64
- //| wav = audiocore.WaveFile(data)
65
- //| a = audioio.AudioOut(board.A0)
63
+ //|data = open("cplay-5.1-16bit-16khz.wav", "rb")
64
+ //|wav = audiocore.WaveFile(data)
65
+ //|a = audioio.AudioOut(board.A0)
66
66
//|
67
- //| print("playing")
68
- //| a.play(wav)
69
- //| while a.playing:
70
- //| pass
71
- //| print("stopped")"""
72
- //| ...
67
+ //|print("playing")
68
+ //|a.play(wav)
69
+ //|while a.playing:
70
+ //|pass
71
+ //|print("stopped")"""
72
+ //|...
73
73
STATIC mp_obj_t audioio_wavefile_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * args , mp_map_t * kw_args ) {
74
74
mp_arg_check_num (n_args , kw_args , 1 , 2 , false);
75
75
@@ -92,9 +92,9 @@ STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_ar
92
92
return MP_OBJ_FROM_PTR (self );
93
93
}
94
94
95
- //| def deinit(self, ) -> Any:
96
- //| """Deinitialises the WaveFile and releases all memory resources for reuse."""
97
- //| ...
95
+ //|def deinit(self, ) -> Any:
96
+ //|"""Deinitialises the WaveFile and releases all memory resources for reuse."""
97
+ //|...
98
98
STATIC mp_obj_t audioio_wavefile_deinit (mp_obj_t self_in ) {
99
99
audioio_wavefile_obj_t * self = MP_OBJ_TO_PTR (self_in );
100
100
common_hal_audioio_wavefile_deinit (self );
@@ -108,27 +108,27 @@ STATIC void check_for_deinit(audioio_wavefile_obj_t *self) {
108
108
}
109
109
}
110
110
111
- //| def __enter__(self, ) -> Any:
112
- //| """No-op used by Context Managers."""
113
- //| ...
111
+ //|def __enter__(self, ) -> Any:
112
+ //|"""No-op used by Context Managers."""
113
+ //|...
114
114
// Provided by context manager helper.
115
115
116
- //| def __exit__(self, ) -> Any:
117
- //| """Automatically deinitializes the hardware when exiting a context. See
118
- //| :ref:`lifetime-and-contextmanagers` for more info."""
119
- //| ...
116
+ //|def __exit__(self, ) -> Any:
117
+ //|"""Automatically deinitializes the hardware when exiting a context. See
118
+ //|:ref:`lifetime-and-contextmanagers` for more info."""
119
+ //|...
120
120
STATIC mp_obj_t audioio_wavefile_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
121
121
(void )n_args ;
122
122
common_hal_audioio_wavefile_deinit (args [0 ]);
123
123
return mp_const_none ;
124
124
}
125
125
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audioio_wavefile___exit___obj , 4 , 4 , audioio_wavefile_obj___exit__ );
126
126
127
- //| sample_rate: Any =
128
- //| """32 bit value that dictates how quickly samples are loaded into the DAC
129
- //| in Hertz (cycles per second). When the sample is looped, this can change
130
- //| the pitch output without changing the underlying sample."""
131
- //| ...
127
+ //|sample_rate: Any =
128
+ //|"""32 bit value that dictates how quickly samples are loaded into the DAC
129
+ //|in Hertz (cycles per second). When the sample is looped, this can change
130
+ //|the pitch output without changing the underlying sample."""
131
+ //|...
132
132
STATIC mp_obj_t audioio_wavefile_obj_get_sample_rate (mp_obj_t self_in ) {
133
133
audioio_wavefile_obj_t * self = MP_OBJ_TO_PTR (self_in );
134
134
check_for_deinit (self );
@@ -151,9 +151,9 @@ const mp_obj_property_t audioio_wavefile_sample_rate_obj = {
151
151
(mp_obj_t )& mp_const_none_obj },
152
152
};
153
153
154
- //| bits_per_sample: Any =
155
- //| """Bits per sample. (read only)"""
156
- //| ...
154
+ //|bits_per_sample: Any =
155
+ //|"""Bits per sample. (read only)"""
156
+ //|...
157
157
STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample (mp_obj_t self_in ) {
158
158
audioio_wavefile_obj_t * self = MP_OBJ_TO_PTR (self_in );
159
159
check_for_deinit (self );
@@ -168,9 +168,9 @@ const mp_obj_property_t audioio_wavefile_bits_per_sample_obj = {
168
168
(mp_obj_t )& mp_const_none_obj },
169
169
};
170
170
171
- //| channel_count: Any =
172
- //| """Number of audio channels. (read only)"""
173
- //| ...
171
+ //|channel_count: Any =
172
+ //|"""Number of audio channels. (read only)"""
173
+ //|...
174
174
STATIC mp_obj_t audioio_wavefile_obj_get_channel_count (mp_obj_t self_in ) {
175
175
audioio_wavefile_obj_t * self = MP_OBJ_TO_PTR (self_in );
176
176
check_for_deinit (self );
0 commit comments