-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for tuple of Biquad objects within audiofilters.Filter.
#9772
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
Changes from 2 commits
6badb92
14b1383
941e122
5f8ec0a
c96d142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "py/runtime.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mp_obj_t filter, mp_obj_t mix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mp_obj_t filters, mp_obj_t mix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uint32_t buffer_size, uint8_t bits_per_sample, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -60,11 +60,11 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The below section sets up the effect's starting values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (filter == MP_OBJ_NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter = mp_const_none; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (filters == MP_OBJ_NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filters = mp_obj_new_list(0, NULL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
relic-se marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| synthio_biquad_filter_assign(&self->filter_state, filter); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filter_obj = filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filters = filters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reset_filter_states(self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If we did not receive a BlockInput we need to create a default float value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (mix == MP_OBJ_NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -87,15 +87,37 @@ void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->buffer[0] = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->buffer[1] = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filter_buffer = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filter_states = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self->filter_obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void reset_filter_states(audiofilters_filter_obj_t *self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filter_states_len = self->filters->len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filter_states = NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (self->filter_states_len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->filter_states = m_malloc(self->filter_states_len * sizeof(biquad_filter_state)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (self->filter_states == NULL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| common_hal_audiofilters_filter_deinit(self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_malloc_fail(self->filter_states_len * sizeof(biquad_filter_state)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self->first_buffer = m_malloc(self->len); | |
| if (self->first_buffer == NULL) { | |
| common_hal_audiomixer_mixer_deinit(self); | |
| m_malloc_fail(self->len); | |
| } | |
| self->second_buffer = m_malloc(self->len); | |
| if (self->second_buffer == NULL) { | |
| common_hal_audiomixer_mixer_deinit(self); | |
| m_malloc_fail(self->len); | |
| } |
circuitpython/shared-module/audiomp3/MP3Decoder.c
Lines 306 to 327 in ddfa519
| self->inbuf.buf = m_malloc(DEFAULT_INPUT_BUFFER_SIZE); | |
| if (self->inbuf.buf == NULL) { | |
| common_hal_audiomp3_mp3file_deinit(self); | |
| m_malloc_fail(DEFAULT_INPUT_BUFFER_SIZE); | |
| } | |
| if (buffer_size >= 2 * MAX_BUFFER_LEN) { | |
| self->pcm_buffer[0] = (int16_t *)(void *)buffer; | |
| self->pcm_buffer[1] = (int16_t *)(void *)(buffer + MAX_BUFFER_LEN); | |
| } else { | |
| self->pcm_buffer[0] = m_malloc(MAX_BUFFER_LEN); | |
| if (self->pcm_buffer[0] == NULL) { | |
| common_hal_audiomp3_mp3file_deinit(self); | |
| m_malloc_fail(MAX_BUFFER_LEN); | |
| } | |
| self->pcm_buffer[1] = m_malloc(MAX_BUFFER_LEN); | |
| if (self->pcm_buffer[1] == NULL) { | |
| common_hal_audiomp3_mp3file_deinit(self); | |
| m_malloc_fail(MAX_BUFFER_LEN); | |
| } | |
| } |
circuitpython/shared-module/audiocore/WaveFile.c
Lines 100 to 110 in ddfa519
| self->buffer = m_malloc(self->len); | |
| if (self->buffer == NULL) { | |
| common_hal_audioio_wavefile_deinit(self); | |
| m_malloc_fail(self->len); | |
| } | |
| self->second_buffer = m_malloc(self->len); | |
| if (self->second_buffer == NULL) { | |
| common_hal_audioio_wavefile_deinit(self); | |
| m_malloc_fail(self->len); | |
| } |
circuitpython/ports/stm/common-hal/pulseio/PulseIn.c
Lines 87 to 91 in ddfa519
| self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t)); | |
| if (self->buffer == NULL) { | |
| // TODO: free the EXTI here? | |
| m_malloc_fail(maxlen * sizeof(uint16_t)); | |
| } |
There are other cases where instead of m_malloc(...) there are calls to port_malloc(...), malloc(...), realloc(...), malloc_with_finaliser(...), ringbuf_alloc(...), and gc_alloc(...) before m_malloc_fail(...). Maybe someone down the line copied that over but with m_malloc(...) and it stuck within audio and pulseio modules?
Rather than experimenting and going outside of the accepted formatting, I'm copying a lot of my homework from other portions of CircuitPython. This is something I borrowed from audiodelays without fully understanding the underlying principles. I plan on keeping it as is for now until we develop a plan for all other instances of this methodology (likely another PR).
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.
Finally looked this up, and I see what you mean. The additional check and m_malloc_fail is definitely not necessary. I'll remove it from this class, but let me know if you'd like me to go around and remove it throughout CircuitPython or save it for a separate PR. @jepler
Lines 86 to 89 in d7a7221
| void *ptr = malloc(num_bytes); | |
| if (ptr == NULL && num_bytes != 0) { | |
| m_malloc_fail(num_bytes); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.