Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cedargrovestudios/circuitpython_wavebuilder
A CircuitPython class to construct a composite synthio wave table from a collection of oscillators.
https://github.com/cedargrovestudios/circuitpython_wavebuilder
arbitrary-waveform-generator circuitpython circuitpython-community-bundle synthio wave-table waveform-generator waveform-synthesiser
Last synced: about 2 months ago
JSON representation
A CircuitPython class to construct a composite synthio wave table from a collection of oscillators.
- Host: GitHub
- URL: https://github.com/cedargrovestudios/circuitpython_wavebuilder
- Owner: CedarGroveStudios
- License: mit
- Created: 2023-12-22T00:02:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-08T17:31:12.000Z (3 months ago)
- Last Synced: 2024-10-10T22:41:20.817Z (2 months ago)
- Topics: arbitrary-waveform-generator, circuitpython, circuitpython-community-bundle, synthio, wave-table, waveform-generator, waveform-synthesiser
- Language: Python
- Homepage:
- Size: 1000 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Introduction
------------.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://adafru.it/discord
:alt: Discord.. image:: https://github.com/CedarGroveStudios/CircuitPython_Chime/workflows/Build%20CI/badge.svg
:target: https://github.com/CedarGroveStudios/CircuitPython_Chime/actions
:alt: Build Status.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code Style: BlackA CircuitPython class to construct a composite ``synthio`` wave table
from a collection of oscillators. The table is created from a list
of oscillator characteristics, sample length, maximum sample
value, a lambda factor, and loop smoothing parameters.Dependencies
------------
This class depends on:* `Adafruit CircuitPython `_
Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle `_
or individual libraries can be installed using
`circup `_.Installing to a Connected CircuitPython Device with Circup
----------------------------------------------------------Make sure that you have ``circup`` installed in your Python environment.
Install it with the following command if necessary:.. code-block:: shell
pip3 install circup
With ``circup`` installed and your CircuitPython device connected use the
following command to install:.. code-block:: shell
circup install cedargrove_wavebuilder
Or the following command to update an existing version:
.. code-block:: shell
circup update
Usage Example
-------------.. code-block:: python
# SPDX-FileCopyrightText: Copyright (c) 2023 JG for Cedar Grove Maker Studios
# SPDX-License-Identifier: MITimport time
import board
import synthio
import audiobusio
import audiomixer
from cedargrove_wavebuilder import WaveBuilder, WaveShape# Define synth parameters
SAMPLE_RATE = 22050 # The sample rate in SPS
WAVE_TABLE_LENGTH = 512 # The wave table length in samples
SAMPLE_MAXIMUM = 32700 # The maximum value of a sample# Define the oscillator wave shape, overtone ratio, and amplitude
tone = [(WaveShape.Sine, 1.0, 0.6)]# Create the wave table and show the debug messages
wave = WaveBuilder(
oscillators=tone,
table_length=WAVE_TABLE_LENGTH,
sample_max=SAMPLE_MAXIMUM,
lambda_factor=1.0,
loop_smoothing=True,
debug=True,
)# Define the tone's ADSR envelope parameters
tone_envelope = synthio.Envelope(
attack_time=0.02 + 0.01,
attack_level=1.0 * 1.0,
decay_time=0.0,
release_time=2.0,
sustain_level=1.0,
)# Configure synthesizer for I2S output on a Feather S2
audio_output = audiobusio.I2SOut(
bit_clock=board.D12, word_select=board.D9, data=board.D6, left_justified=False
)
mixer = audiomixer.Mixer(
sample_rate=SAMPLE_RATE, buffer_size=4096, voice_count=1, channel_count=1
)
audio_output.play(mixer)
mixer.voice[0].level = 0.50synth = synthio.Synthesizer(sample_rate=SAMPLE_RATE)
mixer.play(synth)note_1 = synthio.Note(880, envelope=tone_envelope, waveform=wave.wave_table)
while True:
# Set the note waveform to sine and play the note
wave.oscillators = [(WaveShape.Sine, 1.0, 0.6)]
note_1.waveform = wave.wave_table
synth.press(note_1)
synth.release(note_1)
time.sleep(1)# Set the note waveform to square and play the note
wave.oscillators = [(WaveShape.Saw, 1.0, 0.6)]
note_1.waveform = wave.wave_table
synth.press(note_1)
synth.release(note_1)
time.sleep(1)Documentation
-------------
API documentation for this library can be found in `Cedargrove_WaveBuilder `_... image:: https://github.com/CedarGroveStudios/CircuitPython_WaveBuilder/blob/main/media/wavebuilder_api_page1a.png
.. image:: https://github.com/CedarGroveStudios/CircuitPython_WaveBuilder/blob/main/media/wavebuilder_api_page2a.png
For additional detail about ``WaveBuilder``, see `Construct a synthio Waveform Object from a List of Oscillators `_
Attribution: Patch Symbols from PATCH & TWEAK by Kim Bjørn and Chris Meyer, published by Bjooks, are licensed under Creative Commons CC BY-ND 4.0.
Some Patch Symbols were modified to create the synthio symbols ``BlockInput``, ``MixerVoice``, ``Note``, ``Synthesizer``, ``sample``, and ``voice``.Planned Updates
---------------
* Add wave table file saving.
* Open external file as the fundamental wave table.
* Include other preset wave types.
* Add examples for filtering and applying ``synthio.Math`` to wave tables.Acknowledgements and Thanks
---------------------------
* Liz Clark, '`Circle of Fifths Euclidean Synth with synthio and CircuitPython`' Adafruit Learning Guide
for the waveform and noise examples.
* Todd Kurt for essential ``synthio`` hints, tricks, and examples
(https://github.com/todbot/circuitpython-synthio-tricks).
* Special thanks to Jeff Epler and Adafruit for the comprehensive design and implementation
of the CircuitPython ``synthio`` module.