aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2017-09-05 12:31:02 -0700
committerScott Shawcroft <scott@tannewt.org>2017-09-05 16:37:02 -0700
commit6d9d683443705a3c06afbf3cc4e64da86e5c9dc6 (patch)
tree9de153a66b865108b4b9995ab953ec23e157c840
parente1eb1802a668ecdfb2703db08b559a3e5fcefc55 (diff)
atmel-samd: Enable 8-bit audio recording support even though it'll be
quiet. Also update the examples. Fixes #226
-rw-r--r--atmel-samd/common-hal/audiobusio/PDMIn.c4
-rw-r--r--shared-bindings/audiobusio/PDMIn.c20
2 files changed, 19 insertions, 5 deletions
diff --git a/atmel-samd/common-hal/audiobusio/PDMIn.c b/atmel-samd/common-hal/audiobusio/PDMIn.c
index b53a3fa7f..555601c9d 100644
--- a/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -96,8 +96,8 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
mp_raise_RuntimeError("Unable to allocate audio DMA block counter.");
}
- if (bit_depth != 16 || !mono || oversample != 64) {
- mp_raise_NotImplementedError("");
+ if (!(bit_depth == 16 || bit_depth == 8) || !mono || oversample != 64) {
+ mp_raise_NotImplementedError("Only 8 or 16 bit mono with 64 oversample is supported.");
}
// TODO(tannewt): Use the DPLL to get a more precise sampling rate.
diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c
index 1f132f9ad..eea1e76ac 100644
--- a/shared-bindings/audiobusio/PDMIn.c
+++ b/shared-bindings/audiobusio/PDMIn.c
@@ -53,14 +53,28 @@
//| :param bool mono: True when capturing a single channel of audio, captures two channels otherwise
//| :param int oversample: Number of single bit samples to decimate into a final sample. Must be divisible by 8
//|
-//| Simple record to buffer::
+//| Record 8-bit unsigned samples to buffer::
//|
//| import audiobusio
//| import board
//|
//| # Prep a buffer to record into
//| b = bytearray(200)
-//| with audiobusio.PDMIn(board.MICROPHONE_DATA, board.MICROPHONE_CLOCK) as mic:
+//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA) as mic:
+//| mic.record(b, len(b))
+//|
+//| Record 16-bit unsigned samples to buffer::
+//|
+//| import audiobusio
+//| import board
+//|
+//| # Prep a buffer to record into. The array interface doesn't allow for
+//| # constructing with a set size so we append to it until we have the size
+//| # we want.
+//| b = array.array("H")
+//| for i in range(200):
+//| b.append(0)
+//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, bit_depth=16) as mic:
//| mic.record(b, len(b))
//|
STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
@@ -70,7 +84,7 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_frequency, MP_ARG_INT, {.u_int = 8000} },
{ MP_QSTR_bit_depth, MP_ARG_INT, {.u_int = 8} },
- { MP_QSTR_mono, MP_ARG_BOOL,{.u_bool = false} },
+ { MP_QSTR_mono, MP_ARG_BOOL,{.u_bool = true} },
{ MP_QSTR_oversample, MP_ARG_INT, {.u_int = 64} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];