Skip to content

Commit b129d16

Browse files
docs: Update the recording default rate from 11k to 7812.
1 parent 4841b60 commit b129d16

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

docs/audio.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ a speaker to pin 0 and GND on the edge connector to hear the sounds.
1212
The ``audio`` module can be imported as ``import audio`` or accessed via
1313
the ``microbit`` module as ``microbit.audio``.
1414

15-
There are three different kinds of audio sources that can be played using the
15+
There are five different kinds of audio sources that can be played using the
1616
:py:meth:`audio.play` function:
1717

1818
1. `Built in sounds <#built-in-sounds-v2>`_ (**V2**),
@@ -268,7 +268,7 @@ AudioRecording
268268
--------------
269269

270270
.. py:class::
271-
AudioRecording(duration, rate=11_000)
271+
AudioRecording(duration, rate=7812)
272272

273273
The ``AudioRecording`` object contains audio data and the sampling rate
274274
associated to it.
@@ -305,6 +305,10 @@ AudioRecording
305305
Create an `AudioTrack <#audio.AudioTrack>`_ instance from a portion of
306306
the data in this ``AudioRecording`` instance.
307307

308+
Out-of-range values will be truncated to the recording limits.
309+
If ``end_ms`` is lower than ``start_ms``, an empty track will be
310+
created.
311+
308312
:param start_ms: Where to start of the track in milliseconds.
309313
:param end_ms: The end of the track in milliseconds.
310314
If the default value of ``-1`` is provided it will end the track
@@ -335,7 +339,7 @@ AudioTrack
335339

336340
When the input buffer has an associated rate (e.g. an ``AudioRecording``
337341
or ``AudioTrack``), the rate is copied. If the buffer object does not have
338-
a rate, the default value of 11_000 is used.
342+
a rate, the default value of 7812 is used.
339343

340344
Changes to an ``AudioTrack`` rate won't affect the original source rate,
341345
so multiple instances pointing to the same buffer can have different

docs/microbit_micropython_api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ The Microphone is accessed via the `microphone` object::
109109
# Returns a representation of the sound pressure level in the range 0 to 255.
110110
sound_level()
111111
# Record audio into a new `AudioRecording`
112-
recording = record(duration, rate=11_000)
112+
recording = record(duration, rate=7812)
113113
# Record audio into an existing `AudioRecording`
114114
record_into(recording, wait=True)
115115
# Returns `True` if the microphone is currently recording audio

docs/microphone.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Functions
141141

142142
:return: A representation of the sound pressure level in the range 0 to 255.
143143

144-
.. py:function:: record(duration, rate=11000)
144+
.. py:function:: record(duration, rate=7812)
145145
146146
Record sound into an ``AudioRecording`` for the amount of time indicated by
147147
``duration`` at the sampling rate indicated by ``rate``.
@@ -267,10 +267,8 @@ An example of recording and playback with a display animation::
267267
"00000"
268268
)
269269

270-
RECORDING_RATE = 3906
271-
RECORDING_MS = 5000
272-
273-
my_recording = audio.AudioRecording(duration=RECORDING_MS, rate=RECORDING_RATE)
270+
RECORDING_RATE = 7812 # The default sample rate
271+
my_recording = audio.AudioRecording(duration=5000, rate=RECORDING_RATE)
274272

275273
while True:
276274
if button_a.is_pressed():
@@ -283,7 +281,10 @@ An example of recording and playback with a display animation::
283281
if button_b.is_pressed():
284282
audio.play(clipped_recording, wait=False)
285283
while audio.is_playing():
286-
x = accelerometer.get_x()
287-
audio.set_rate(scale(x, (-1000, 1000), (2250, 11000)))
284+
clipped_recording.set_rate(scale(
285+
accelerometer.get_x(),
286+
(-1000, 1000),
287+
(RECORDING_RATE // 2, RECORDING_RATE * 2)
288+
))
288289
sleep(50)
289290
sleep(100)

0 commit comments

Comments
 (0)