8000 atmel-samd: Enable 8-bit audio recording support even though it'll be · sparkfun/circuitpython@6d9d683 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d9d683

Browse files
committed
atmel-samd: Enable 8-bit audio recording support even though it'll be
quiet. Also update the examples. Fixes adafruit#226
1 parent e1eb180 commit 6d9d683

File tree

2 files changed

+19
-5
lines changed
  • atmel-samd/common-hal/audiobusio
  • shared-bindings/audiobusio

2 files changed

+19
-5
lines changed

atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
9696
mp_raise_RuntimeError("Unable to allocate audio DMA block counter.");
9797
}
9898

99-
if (bit_depth != 16 || !mono || oversample != 64) {
100-
mp_raise_NotImplementedError("");
99+
if (!(bit_depth == 16 || bit_depth == 8) || !mono || oversample != 64) {
100+
mp_raise_NotImplementedError("Only 8 or 16 bit mono with 64 oversample is supported.");
101101
}
102102

103103
// TODO(tannewt): Use the DPLL to get a more precise sampling rate.

shared-bindings/audiobusio/PDMIn.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,28 @@
5353
//| :param bool mono: True when capturing a single channel of audio, captures two channels otherwise
5454
//| :param int oversample: Number of single bit samples to decimate into a final sample. Must be divisible by 8
5555
//|
56-
//| Simple record to buffer::
56+
//| Record 8-bit unsigned samples to buffer::
5757
//|
5858
//| import audiobusio
5959
//| import board
6060
//|
6161
//| # Prep a buffer to record into
6262
//| b = bytearray(200)
63-
//| with audiobusio.PDMIn(board.MICROPHONE_DATA, board.MICROPHONE_CLOCK) as mic:
63+
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA) as mic:
64+
//| mic.record(b, len(b))
65+
//|
66+
//| Record 16-bit unsigned samples to buffer::
67+
//|
68+
//| import audiobusio
69+
//| import board
70+
//|
71+
//| # Prep a buffer to record into. The array interface doesn't allow for
72+
//| # constructing with a set size so we append to it until we have the size
73+
//| # we want.
74+
//| b = array.array("H")
75+
//| for i in range(200):
76+
//| b.append(0)
77+
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, bit_depth=16) as mic:
6478
//| mic.record(b, len(b))
6579
//|
6680
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
7084
static const mp_arg_t allowed_args[] = {
7185
{ MP_QSTR_frequency, MP_ARG_INT, {.u_int = 8000} },
7286
{ MP_QSTR_bit_depth, MP_ARG_INT, {.u_int = 8} },
73-
{ MP_QSTR_mono, MP_ARG_BOOL,{.u_bool = false} },
87+
{ MP_QSTR_mono, MP_ARG_BOOL,{.u_bool = true} },
7488
{ MP_QSTR_oversample, MP_ARG_INT, {.u_int = 64} },
7589
};
7690
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];

0 commit comments

Comments
 (0)
0