Skip to content

Commit

Permalink
docs: Rename wave->waveform from SoundEffect. (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-carlos committed Nov 15, 2022
1 parent 98d44d7 commit 6f4fb42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 10 additions & 9 deletions docs/audio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Sound Effects **V2**
====================

.. py:class::
SoundEffect(freq_start=500, freq_end=2500, duration=500, vol_start=255, vol_end=0, wave=WAVE_SQUARE, fx=FX_NONE, shape=SHAPE_LOG)
SoundEffect(freq_start=500, freq_end=2500, duration=500, vol_start=255, vol_end=0, waveform=WAVEFORM_SQUARE, fx=FX_NONE, shape=SHAPE_LOG)

An ``SoundEffect`` instance represents a sound effect, composed by a set of
parameters configured via the constructor or attributes.
Expand All @@ -129,9 +129,10 @@ Sound Effects **V2**
:param duration: Duration of the sound (ms), default: ``500``
:param vol_start: Start volume value, range 0-255, default: ``255``
:param vol_end: End volume value, range 0-255, default: ``0``
:param wave: Type of wave shape, one of these values: ``WAVE_SINE``,
``WAVE_SAWTOOTH``, ``WAVE_TRIANGLE``, ``WAVE_SQUARE``,
``WAVE_NOISE`` (randomly generated noise). Default: ``WAVE_SQUARE``
:param waveform: Type of waveform shape, one of these values:
``WAVEFORM_SINE``, ``WAVEFORM_SAWTOOTH``, ``WAVEFORM_TRIANGLE``,
``WAVEFORM_SQUARE``, ``WAVEFORM_NOISE`` (randomly generated noise).
Default: ``WAVEFORM_SQUARE``
:param fx: Effect to add on the sound, one of the following values:
``FX_TREMOLO``, ``FX_VIBRATO``, ``FX_WARBLE``, or ``FX_NONE``.
Default: ``FX_NONE``
Expand Down Expand Up @@ -165,11 +166,11 @@ Sound Effects **V2**
End volume value, a number between ``0`` and ``255``.

.. py:attribute:: wave
.. py:attribute:: waveform
Type of wave shape, one of these values: ``WAVE_SINE``,
``WAVE_SAWTOOTH``, ``WAVE_TRIANGLE``, ``WAVE_SQUARE``,
``WAVE_NOISE`` (randomly generated noise).
Type of waveform shape, one of these values: ``WAVEFORM_SINE``,
``WAVEFORM_SAWTOOTH``, ``WAVEFORM_TRIANGLE``, ``WAVEFORM_SQUARE``,
``WAVEFORM_NOISE`` (randomly generated noise).

.. py:attribute:: fx
Expand All @@ -193,7 +194,7 @@ For example, with the :doc:`REPL </devguide/repl>` you can inspect the
default SoundEffects::

>>> print(audio.SoundEffect())
SoundEffect(freq_start=500, freq_end=2500, duration=500, vol_start=255, vol_end=0, wave=WAVE_SQUARE, fx=FX_NONE, shape=SHAPE_LOG)
SoundEffect(freq_start=500, freq_end=2500, duration=500, vol_start=255, vol_end=0, waveform=WAVE_SQUARE, fx=FX_NONE, shape=SHAPE_LOG)

This format is "human readable", which means it is easy for us to read,
and it looks very similar to the code needed to create that SoundEffect,
Expand Down
8 changes: 4 additions & 4 deletions examples/soundeffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
duration=500,
vol_start=100,
vol_end=255,
wave=audio.SoundEffect.WAVE_TRIANGLE,
waveform=audio.SoundEffect.WAVEFORM_TRIANGLE,
fx=audio.SoundEffect.FX_VIBRATO,
shape=audio.SoundEffect.SHAPE_LOG
))
Expand All @@ -27,13 +27,13 @@
# You can also create a new effect based on an existing one, and modify
# any of its characteristics via arguments
my_modified_effect = my_effect.copy()
my_modified_effect.wave = audio.SoundEffect.WAVE_NOISE
my_modified_effect.waveform = audio.SoundEffect.WAVEFORM_NOISE
audio.play(my_modified_effect)

# Use sensor data to modify and play an existing Sound Effect instance
my_effect.duration = 600
while True:
# int() might be temporarily neededhttps://github.com/microbit-foundation/micropython-microbit-v2/issues/121
# int() might be temporarily needed: https://github.com/microbit-foundation/micropython-microbit-v2/issues/121
my_effect.freq_start = int(scale(accelerometer.get_x(), from_=(-2000, 2000), to=(0, 9999)))
my_effect.freq_end = int(scale(accelerometer.get_y(), from_=(-2000, 2000), to=(0, 9999)))
audio.play(my_effect)
Expand All @@ -44,7 +44,7 @@
display.show(Image("09090:00000:00900:09990:00900"))
sleep(500)
elif button_b.is_pressed():
# On button B re-enable speaker & play an effect while showing an image
# Button B re-enables the speaker & plays an effect while showing an image
speaker.on()
audio.play(audio.SoundEffect(), wait=False)
display.show(Image.MUSIC_QUAVER)
Expand Down

0 comments on commit 6f4fb42

Please sign in to comment.