Skip to content

Commit dc6db28

Browse files
committed
cleanup docstrings, example, and comments
1 parent b531a07 commit dc6db28

7 files changed

Lines changed: 35 additions & 28 deletions

File tree

shared-bindings/audiowriter/AudioWriter.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT
66

@@ -20,13 +20,12 @@
2020
//|
2121
//| ``AudioWriter`` is the inverse of `audiocore.WaveFile`: rather than being
2222
//| an audio *source* played by an `audioio.AudioOut`, it is a *sink* that
23-
//| drives an audio source (a microphone, or an ``audiofilters``/
23+
//| drives an audio source (a microphone, ``synthio``, or an ``audiofilters``/
2424
//| ``audiodelays``/``audiofreeverb``/``audiospeed`` effect chain) and writes
2525
//| the resulting PCM to a file as a WAV.
2626
//|
2727
//| Recording runs on a background pump paced to the source's real-time rate,
28-
//| so it does not block and does not require a Python read loop (which is
29-
//| what makes hand-rolled recorders choppy)."""
28+
//| so it does not block and does not require a Python read loop."""
3029
//|
3130
//| def __init__(self, file: typing.BinaryIO, *, buffer_size: int = 32768) -> None:
3231
//| """Create an ``AudioWriter`` that writes to ``file``.
@@ -42,15 +41,29 @@
4241
//| The audio format (sample rate, channel count, bit depth) is taken from
4342
//| the source at `play()` time, so there are no format arguments here.
4443
//|
45-
//| Recording a microphone through an effect chain to SD::
44+
//| Recording synthio to SD::
4645
//|
47-
//| import audiowriter, board
48-
//| # ``amp`` is the top of an effect chain pulling from a mic
49-
//| with open("/sd/recording.wav", "wb") as f:
50-
//| writer = audiowriter.AudioWriter(f)
51-
//| writer.play(amp)
52-
//| time.sleep(5)
46+
//| import time
47+
//| import synthio
48+
//| from audiowriter import AudioWriter
49+
//| import storage
50+
//|
51+
//| SAMPLE_RATE = 16000
52+
//| OUTPUT_PATH = "/sd/demo_file.wav"
53+
//|
54+
//| C_major_scale = [60, 62, 64, 65, 67, 69, 71, 72, 71, 69, 67, 65, 64, 62, 60]
55+
//| synth = synthio.Synthesizer(sample_rate=SAMPLE_RATE)
56+
//|
57+
//| with open(OUTPUT_PATH, "wb") as f:
58+
//| writer = AudioWriter(f)
59+
//| writer.play(synth)
60+
//| for note in C_major_scale:
61+
//| synth.press(note)
62+
//| time.sleep(0.1)
63+
//| synth.release(note)
64+
//| time.sleep(0.10)
5365
//| writer.stop()
66+
//| print("Done ->", OUTPUT_PATH)
5467
//| """
5568
//| ...
5669
//|

shared-bindings/audiowriter/AudioWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT
66

shared-bindings/audiowriter/__init__.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT
66

@@ -12,13 +12,7 @@
1212
#include "shared-bindings/audiowriter/__init__.h"
1313
#include "shared-bindings/audiowriter/AudioWriter.h"
1414

15-
//| """Support for streaming audio to a WAV file
16-
//|
17-
//| The `audiowriter` module contains `AudioWriter`, a *sink* that records an
18-
//| audio source (a microphone or an effect chain) to a ``.wav`` file in the
19-
//| background -- the inverse of `audiocore.WaveFile`.
20-
//|
21-
//| """
15+
//| """Support for streaming audio to a WAV file"""
2216

2317
static const mp_rom_map_elem_t audiowriter_module_globals_table[] = {
2418
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiowriter) },

shared-bindings/audiowriter/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT
66

shared-module/audiowriter/AudioWriter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT
66

shared-module/audiowriter/AudioWriter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT
66

@@ -11,10 +11,10 @@
1111

1212
#include "py/obj.h"
1313

14-
// A streaming WAV *sink*: it consumes an audiosample source (a mic or an effect
15-
// chain) and writes the resulting PCM to a file. Unlike WaveFile it is NOT an
16-
// audiosample (it has no audiosample_base_t) -- it is the thing that drives a
17-
// source, playing the role an AudioOut would.
14+
// A streaming WAV *sink*: it consumes an audiosample source (a mic, synthio,
15+
// or an effect chain) and writes the resulting PCM to a file. Unlike WaveFile
16+
// it is NOT an audiosample, it is the thing that drives a source, playing the
17+
// role an AudioOut would.
1818
typedef struct _audiowriter_audiowriter_obj_t {
1919
mp_obj_base_t base;
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is part of the CircuitPython project: https://circuitpython.org
22
//
3-
// SPDX-FileCopyrightText: Copyright (c) 2026 Adafruit Industries
3+
// SPDX-FileCopyrightText: Copyright (c) 2026 Tim Cocks for Adafruit Industries
44
//
55
// SPDX-License-Identifier: MIT

0 commit comments

Comments
 (0)