-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Audio effects #9640
base: main
Are you sure you want to change the base?
Add Audio effects #9640
Conversation
I'm still digging into the code, but my first instinct is to have the Speaking of buffer sizes, it may be nice to explore having a fixed buffer size and altering the rate of playback of that buffer depending on the delay setting. This would be similar to a bucket-brigade style delay pedal and require some more advanced interpolation, etc. I think it be worth exploring an "Analog" delay effect of this nature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the initial PR! This is very exciting.
shared-bindings/audiodelays/Echo.c
Outdated
} | ||
MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_play_obj, 1, audiodelays_echo_obj_play); | ||
|
||
//| def stop_voice(self, voice: int = 0) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//| def stop_voice(self, voice: int = 0) -> None: | |
//| def stop(self) -> None: |
shared-bindings/audiodelays/Echo.c
Outdated
if (decay > 1 || decay < 0) { | ||
mp_raise_ValueError(MP_ERROR_TEXT("decay must be between 0 and 1")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, | ||
{ MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect you'll want delay and decay to be BlockInputs so they can be varied.
circuitpython/shared-bindings/synthio/__init__.c
Lines 75 to 78 in 87f7bc9
//| BlockInput = Union["Math", "LFO", float, None] | |
//| """Blocks and Notes can take any of these types as inputs on certain attributes | |
//| | |
//| A BlockInput can be any of the following types: `Math`, `LFO`, `builtins.float`, `None` (treated same as 0). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As much as I'd like to see BlockInput on delay, it would cause a reallocation of the buffer on each update. I imagine that wouldn't be great for performance. However, I do think that would be a great feature for a fixed buffer delay effect.
void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint32_t delay_ms) {
self->delay_ms = delay_ms;
self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * (self->channel_count * (self->bits_per_sample / 8));
self->echo_buffer = m_realloc(self->echo_buffer, self->echo_buffer_len);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Fixed delay is fine. A future refinement could also specify a "max_delay" that does the alloc and "delay" lets you move within that range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could adjust your initial allocation to be larger if given a non-fixed value. That way you don't need to re-allocate when the value changes. You just don't use all of the buffer for short delays.
I also think it's good to show how to use BlockInput so that further effects use it too. It is more complicated, but it'd be good to show how to use. It is super powerful IMO.
#: shared-module/audioeffects/Echo.c | ||
msgid "The sample's sample rate does not match the effect's" | ||
msgstr "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to drop "the effect's" and "the mixer's" so we can share these messages.
I'm not too worried at this point as I'm using Same thought on the
I think this would be good for another effect. I have tossed about the idea of a generic delay buffer that other effects could use. |
Foundation to add audio effects to CircuitPython as discussed in issue #8974.
This PR aims to create initial modules, some base effects and utilities to help create future effects. The ones included will serve as a template for future creations.
To do:
Looking for feedback on the API and anything else that comes up.
When I have time I plan to document how to create your own effects using the ones provided.
Sample code to run: