Skip to content
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 audiodelays & audioeffects to unix coverage port #9793

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

jepler
Copy link
Member

@jepler jepler commented Nov 5, 2024

.. and add a very basic audioeffects test, showing that it plausibly is working

I had to address several build errors that occurred in the Unix build, mostly related to conversion from FP types to integral types (replaced by explicit casts) and by
accidental mixing of regular & f-suffixed floating constants (replaced with the MICROPY_FLOAT_CONST macro)

Particularly this change could use consideration:

-    self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * sizeof(uint16_t)); // bytes
+    self->max_echo_buffer_len = (uint32_t)(self->sample_rate / 1000.0f * max_delay_ms) * (self->channel_count * sizeof(uint16_t)); // bytes

The buffer length is being calculated in floating point based on the millisecond delay & the sample rate. The result could then be a fractional number such as 529.2 for a 12ms delay at 44.1kHz. Multiplying a floating number by the size required for each echo buffer item ((self->channel_count * sizeof(uint16_t))) could yield a number of bytes that doesn't correspond to an integral number of buffer items. I grouped the float->int conversion so that it converts the number of echo buffer items to an integer and then multiplies by the size of the item.

ping @relic-se -- I've found it helpful to have host-based tests for synthio. this enables the same thing for filters and echo. Also, see above, maybe I found a bug?

.. and add a very basic audioeffects test, showing that it plausibly
is working

I had to address several build errors that occurred in the Unix build,
mostly related to conversion from FP types to integral types (replaced
by explicit casts) and by
accidental mixing of regular & f-suffixed floating constants (replaced
with the MICROPY_FLOAT_CONST macro)

Particularly this change could use consideration:
```diff
-    self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * sizeof(uint16_t)); // bytes
+    self->max_echo_buffer_len = (uint32_t)(self->sample_rate / 1000.0f * max_delay_ms) * (self->channel_count * sizeof(uint16_t)); // bytes
```

The buffer length is being calculated in floating point based on the
millisecond delay & the sample rate. The result could then be a fractional
number such as 529.2 for a 12ms delay at 44.1kHz. Multiplying a floating
number by the size required for each echo buffer item
(`(self->channel_count * sizeof(uint16_t))`) could yield a number of bytes
that doesn't correspond to an integral number of buffer items. I grouped
the float->int conversion so that it converts the number of echo buffer
items to an integer and then multiplies by the size of the item.
@relic-se
Copy link

relic-se commented Nov 5, 2024

I think your solution to fix the implicit conversion will do the trick. There will be some imperceptible deviation from the actual ms value, but I think that's inevitable. Thanks for scanning through both modules and making those updates throughout. I'll try the filter tests out when I get the chance.

I see you haven't created a test for the audiodelays.Echo yet. When you do, could you make sure that it's testing in stereo? (ie: hard panned sine waves at different intervals) I'm worried that there might be some buffer mishandling when freq_shift=True that I haven't gotten around to investigating. Generating the test output may reveal that error.

@jepler
Copy link
Member Author

jepler commented Nov 5, 2024

I only created one test as an example. I'd hope that after this PR is merged you'd consider creating more tests; you're likely to do better at identifying what's important to test than me, given your familiarity with the code.

@jepler jepler requested a review from FoamyGuy November 7, 2024 15:41
@FoamyGuy
Copy link
Collaborator

FoamyGuy commented Nov 7, 2024

@jepler I tried testing this but I'm not sure that I've figured out the correct way to run it.

make test and make test_full inside of ports/unix/ runs many tests including this new one, but the new one is one of 42 tests that fail for me when I run them this way.

I briefly tried running the new test on it's own with

build-coverage/micropython ../../tests/circuitpython/audiofilter_filter.py

But that raises an ImportError not being able to find audiofilterhelper, which I see is commited along with this PR in testlib folder. I'm not sure how to get the micropython binary to find it there when run like this. As a workaround I tried copying that file into build-coverage/ but that still results in the same error.

Copy link
Collaborator

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out a way to run it individually by copying audiofilterhelper.py into the folder with the py file being executed. I'm sure that is not the intended way.

I was able to successfully run the test inside of the unix port and confirm its output against the .exp file. Didn't test anything on microcontroller.

I'm assuming that my issues running make test to do the full test suite are either me misunderstanding how to use it, or not having proper environment fully set up.

Looks good to me.

@jepler
Copy link
Member Author

jepler commented Nov 7, 2024

You can run a single test with make VARIANT=coverage TEST_EXTRA=circuitpython/audiofilter_filter.py. Or, you can manually include testlib in the import path with MICROPYPATH=../../tests/testlib build-coverage/micropython ../../tests/circuitpython/audiofilter_filter.py

@FoamyGuy FoamyGuy merged commit d7a7221 into adafruit:main Nov 7, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants