{"id":17261264,"url":"https://github.com/aybe/firconvolution","last_synced_at":"2025-10-05T04:29:05.502Z","repository":{"id":194740931,"uuid":"640564277","full_name":"aybe/FIRConvolution","owner":"aybe","description":"Faster FIR filter convolution for Unity.","archived":false,"fork":false,"pushed_at":"2023-09-23T21:49:34.000Z","size":12400,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-07-30T02:59:48.949Z","etag":null,"topics":["convolution","filter","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aybe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-14T14:09:09.000Z","updated_at":"2024-08-12T09:06:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"cd09a618-1f49-4b81-9ba9-df88a3aeeb0b","html_url":"https://github.com/aybe/FIRConvolution","commit_stats":null,"previous_names":["aybe/firconvolution"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aybe/FIRConvolution","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybe%2FFIRConvolution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybe%2FFIRConvolution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybe%2FFIRConvolution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybe%2FFIRConvolution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aybe","download_url":"https://codeload.github.com/aybe/FIRConvolution/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybe%2FFIRConvolution/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278410299,"owners_count":25982354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolution","filter","unity3d"],"created_at":"2024-10-15T07:50:36.144Z","updated_at":"2025-10-05T04:29:05.456Z","avatar_url":"https://github.com/aybe.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FIRConvolution\n\nFaster FIR filter convolution for Unity.\n\n\u003cimg src=\"Wiki/header.png\" width=\"400\"/\u003e\n\n## Description\n\nThis project is a collection of 12 algorithms for FIR filter convolution, with a focus on half-band filtering.\n\nMost of the algorithms are vectorized, leveraging SIMD extensions through the Unity Burst compiler.\n\nCheck the sample scene to see them perform filtering from within `MonoBehaviour.OnAudioFilterRead`.\n\n\n## Installation\n\n**Consumer audience:**\n\nAdd the package to your Unity project using the following Git URL: \n\n`https://github.com/aybe/FIRConvolution.git?path=Assets/FIRConvolution`\n\n**Developer audience:**\n\nThe project uses symbolic links, for Windows, you can set them up [this way](https://stackoverflow.com/a/59761201).\n\n(this is to alleviate the deficiencies of Unity [sample package authoring](https://docs.unity3d.com/Manual/cus-samples.html))\n\nIncluded, an [MSTest project setup](Projects) that tests directly against the Unity code.\n\n(this neat trick allows to test code in a much friendlier test environment)\n\n## Performance\n\n### Motivation\n\nImplementing a fast FIR filter convolution purely using managed code ended up being an impossible task, because as soon as one tries to use a high-quality filter with many taps; the audio DSP CPU usage immediately ranges between 30% to 50%. This, no matter how hard you'd apply various optimizations in order to try speed up the processing time.\n\n### Profiling environment\n\nThe candidate is a high-quality half-band FIR filter, with 461 taps and for 1 channel @ 44100 Hz.\n\nTrying to mimick the typical use with 10 measurements and 1000 iterations for 1024 samples.\n\nBoth managed and native implementations are tested to give the audience an overall comparison.\n\n### Profiling results\n\nThe results are surprising, some algorithms perform better than some others ought to be worse.\n\nOverall, an algorithm is fit to use without noticeable impact when it spends less than 10 seconds.\n\n\n**Legend:**\n\n- `[Scalar|Vector]`\n  - `Scalar` : 1 sample at a time\n  - `Vector` : 4 samples at a time\n- `[Full|Half]`\n  - `Full` : full-band filter\n  - `Half` : half-band filter\n- `[Full|Half]` (only for half-band filter)\n  - `Full` : iterating the taps loop fully, i.e. using 50% of the taps\n    - in a half-band filter, half of the taps are zeros and thus can be ignored\n  - `Half` : iterating the taps loop first half, i.e. using 25% of the taps\n    - in addition to above, leveraging taps symmetry to halve the iterations\n- `[Inner|Outer|OuterInner]`\n  - `Inner` : taps loop vectorized\n  - `Outer` : samples loop vectorized\n  - `OuterInner` : both loops vectorized\n\n**Managed, alphabetically:**\n\n\u003cimg src=\"Wiki\\managed-abc.png\"/\u003e\n\n**Managed, fastest to slowest:**\n\n\u003cimg src=\"Wiki\\managed-spd.png\"/\u003e\n\n**Native, alphabetically:**\n\n\u003cimg src=\"Wiki\\native-abc.png\"/\u003e\n\n**Native, fastest to slowest:**\n\n\u003cimg src=\"Wiki\\native-spd.png\"/\u003e\n\n**Versus, alphabetically:**\n\n\u003cimg src=\"Wiki\\vs-abc.png\"/\u003e\n\n**Versus, fastest to slowest:**\n\n\u003cimg src=\"Wiki\\vs-spd.png\"/\u003e\n\n### Conclusions\n\nOn the managed side:\n- scalar half-band\n  - almost twice as fast as full-band variant, this is totally expected\n  - half loop variant gain is marginal although halved tap iterations \n- vectorized\n  - outer loop variant is the slowest in most cases, it's the opposite for native\n  - SIMD isn't used while in vanilla .NET it is when inspecting generated code\n\nOn the native side:\n- scalar half-band\n  - little gain, likely due to short input and overhead\n- vectorized, outer/inner variant\n  - full-band, performs worse than the other variants\n  - half-band, performs better but the gain is marginal\n\nOverall, considering native implementations:\n- full-band: outer variant is the fastest\n  - outer/inner variant ought to be the fastest but really isn't in the end\n- half-band: half loop, outer/inner variant is the fastest\n  - when a substantially longer/trickier algorithm ends up being faster\n\n## Notes\n\nPorting it for vanilla .NET should be easy, it already works in the MSTest project:\n\n1. extend the pattern of [shim Unity types](Projects/FIRConvolution/Fakes) to `float2`, `float4` and `math.dot`\n2. use the aligned memory allocator [for vanilla .NET](Assets/FIRConvolution/Runtime/MemoryAllocatorNet.cs) instead of the Unity one\n\n(this is in order to avoid the gray area of using Unity assemblies outside Unity)\n\n\n## Credits\n\nhttps://fiiir.com (filter design)\n\nhttps://thewolfsound.com/fir-filter-with-simd (filter vectorization)\n\nhttps://github.com/Rabadash8820/UnityAssemblies (Unity bindings)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faybe%2Ffirconvolution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faybe%2Ffirconvolution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faybe%2Ffirconvolution/lists"}