adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.12k stars 1.22k forks source link

Add BlockBiquad shelf & peaking, AudioFilter support #9804

Open jepler opened 1 week ago

jepler commented 1 week ago

@relic-se @gamblor21 @todbot for interest.

A potential limitation is:

Using the same LFO as an input to multiple other LFOs or Notes is OK, but the result if an LFO is tied to multiple Synthtesizer[sic, someone should fix that doc typo] objects is undefined.

(besides which, LFOs can now be used with AudioFilters, BlockBiquads, and other types of objects; LFOs, Math blocks and BlockBiquads should in the medium term be moved out of synthio into their own modules and the documentation updated to reflect what they can be used with)

AudioFilter is more likely to be used with AudioMixer. But you can't have one LFO drive the filters of two different AudioFilter objects.

I honestly don't know what the fix for this is. The lfo_tick routine needs to run once every SYNTHIO_MAX_DUR samples, but other parts of the audio pipeline produce or consume in different chunks. Using AudioMixer to gather up multiple chunks of synthio data is a common trick, but you still want the LFOs to tick every 256 samples even if AudioMixer is gathering 1024 samples at a time (ssay) In fact, this is making me doubt that a BlockBiquad with varying inputs is even working right in Filter with a single Filter and no mixer since it is using buffer_size of 512 bytes which might or might not be 256 samples.

This needs more thought, so I'm entering this as a draft.

jepler commented 1 week ago

[two builds overflowed, looks like]