Skip to content

Add DSP convolution filter - #4947

Merged
maximmaxim345 merged 17 commits into
devfrom
dsp-convolution-filter
Aug 3, 2026
Merged

maximmaxim345 merged 17 commits into
devfrom
dsp-convolution-filter

Conversation

@OzGav

@OzGav OzGav commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this implement/fix?

Adds the new ConvolutionFilter DSP type, which applies an impulse response to the audio, room correction (REW, Acourate, Audiolense), speaker correction, or headphone simulation.

Impulse responses are uploaded and stored server side rather than embedded in the filter, so the DSP config only carries a small id and the same file can be shared across players and presets. Files live in a dsp_irs subdirectory of the storage path with a metadata record in the config store, managed by three new commands: config/dsp_irs/list, /upload and /remove. Uploads are transcoded to wav on the way in, which validates they are really audio. Removing an impulse response that is still in use blanks it from any config or preset referencing it instead of leaving a dangling id.

Frontend PR music-assistant/frontend#2190
Models PR: music-assistant/models#336

Related issue (if applicable):

  • related issue

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

@codspeed

codspeed Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 11 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing dsp-convolution-filter (f7ad001) with dev (f3aacf5)2

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on dev (bb06b45) during the generation of this report, so f3aacf5 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@OzGav
OzGav requested a review from maximmaxim345 July 23, 2026 23:43
@OzGav
OzGav marked this pull request as draft July 24, 2026 00:20
@OzGav
OzGav marked this pull request as ready for review July 24, 2026 00:55
@OzGav
OzGav force-pushed the dsp-convolution-filter branch 2 times, most recently from e1c4c0f to 23f32fe Compare July 25, 2026 12:05
@OzGav
OzGav marked this pull request as draft July 27, 2026 10:00
@OzGav

OzGav commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Setting as draft as Steven identified we need a new event so need a models bump to permit that.

@OzGav
OzGav force-pushed the dsp-convolution-filter branch 2 times, most recently from 453dd08 to 2a8a1bf Compare July 29, 2026 23:46
OzGav added 4 commits July 30, 2026 18:49
Impulse responses are uploaded once and stored server side, so any player can reference one by id. Changes to the library are announced with DSP_IRS_UPDATED so clients do not have to infer them from unrelated config updates.

Requires the DSP_IRS_UPDATED event type (music-assistant-models); pin bump and green CI to follow.
Map a ConvolutionFilter to an afir graph that pulls in the stored impulse response, resamples it to the stream rate, and applies the output gain. Removing an impulse response clears it from any player config or preset that referenced it.

Requires the ConvolutionFilter model (music-assistant-models #319); pin bump and green CI to follow.
A mono impulse response is applied to both channels and a stereo one
channel per side, but afir silently downmixes anything wider to match
the stream. A four channel true stereo response, which describes how
each speaker reaches each ear, is therefore blended into two channels
and does not produce the effect it was measured for.

Rejecting the upload with an explanation is clearer than storing a file
that will quietly misbehave at playback time. Supporting these properly
needs four convolutions summed as a matrix, which also rules out afir's
auto gain, so it is left for later.
Pass the impulse response to ffmpeg as its own input instead of naming it
inside the filtergraph. A path containing a quote, comma or bracket could not
be escaped for the graph parser, and the graph failed to initialise, so the
player got no audio at all.

Reject an upload longer than ten seconds, which afir refuses at graph build
time, and lower the size cap to match. Bound the transcode with a timeout so
a crafted upload cannot leave ffmpeg running indefinitely.

Validate ir_id with the same rule at playback as at upload; isalnum() also
accepted uppercase and non-ascii characters. Hold the convolution at unity
gain with irnorm, since afir's gtype is deprecated and has no effect.

Require ir_dir, so a caller cannot disable convolution by omitting it, and
drop a stored record before resolving its path, so an id that no longer
passes validation can still be removed.
@OzGav
OzGav force-pushed the dsp-convolution-filter branch from 2a8a1bf to 5552b02 Compare July 30, 2026 08:49
@MarvinSchenkel
MarvinSchenkel force-pushed the dsp-convolution-filter branch 2 times, most recently from 1b09b08 to 89aa614 Compare July 30, 2026 12:40
@MarvinSchenkel
MarvinSchenkel force-pushed the dsp-convolution-filter branch from 89aa614 to 64203e4 Compare July 30, 2026 12:48
@OzGav
OzGav marked this pull request as ready for review July 30, 2026 13:39
A 9.7MB silent flac, well under the upload size cap, decodes to 22GB of pcm_f32le on disk before the duration check rejects it and cleans up.
A player mid-playback kept convolving with the deleted impulse response until the next stream start.
A config or preset naming an impulse response this server does not have makes ffmpeg fail to open the graph, so the player gets no audio at all.
An error the upload does not anticipate left the wav in the store with no metadata record, so nothing could reach it again.
A lossy encode smears the impulse across neighbouring samples, corrupting the measurement the response is meant to apply. Checking the container rather than the stream codec also rejects flac in ogg and alac in mp4, neither of which is used to distribute impulse responses.
A stale client could save a config or preset referencing a removed impulse response, storing a dangling reference that silently does nothing at playback.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new DSP convolution capability to Music Assistant by introducing a ConvolutionFilter that applies an impulse response (IR) during FFmpeg processing. To support this, it also adds server-side IR storage/management APIs and updates the FFmpeg filtergraph builder to handle complex DSP fragments that require additional audio inputs.

Changes:

  • Added convolution DSP support via ConvolutionFilter, backed by a new ComplexFilterInput model and updated filtergraph argument generation to attach extra -i inputs.
  • Implemented server-side IR library management (list/upload/remove), including transcoding and validation (duration/codec/channels) and reference clearing on removal.
  • Updated stream pipelines and tests to accept/propagate complex DSP fragments, and adjusted CI to run tests in an environment matching production FFmpeg expectations.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/helpers/test_ffmpeg.py Updates expectations for _build_filtergraph_args returning extra input args + filter args, and validates convolution inputs are real FFmpeg inputs.
tests/helpers/test_dsp.py Adds convolution filter mapping tests and updates existing DSP tests to pass ir_dir.
tests/controllers/streams/test_audio_processing.py Adds coverage for dropping unknown IRs and keeping known IRs in output planning.
tests/controllers/config/test_dsp.py Adds extensive upload/list/remove IR tests (validation, cleanup, signaling, reference clearing).
music_assistant/providers/universal_group/ugp_stream.py Broadens filter_params typing to accept complex DSP fragments.
music_assistant/providers/squeezelite/multi_client_stream.py Broadens filter_params typing to accept complex DSP fragments.
music_assistant/providers/snapcast/ma_stream.py Allows stored filter settings to include complex DSP fragments.
music_assistant/providers/sendspin/playback.py Updates pipeline config typing and logic to treat complex fragments as “custom filter graph present”.
music_assistant/providers/msx_bridge/http_server.py Broadens _stream_with_prebuffer filter params typing to accept complex DSP fragments.
music_assistant/helpers/ffmpeg.py Changes _build_filtergraph_args to return extra -i args plus filter args to support complex inputs safely.
music_assistant/helpers/dsp.py Introduces ComplexFilterInput, updates convolution filter mapping, and changes filter_to_ffmpeg_params return type.
music_assistant/controllers/streams/audio.py Passes IR directory into DSP mapping and drops convolution filters referencing unknown IR ids.
music_assistant/controllers/streams/audio_processing.py Updates output plan typing to allow complex DSP fragments in filter_params.
music_assistant/controllers/config/dsp.py Adds IR library APIs (list/upload/remove), validation, cleanup, signaling, and clearing references on IR removal.
music_assistant/constants.py Adds constants for IR config key, storage dir name, and IR id validation regex.
.github/workflows/test.yml Switches test job to a containerized environment and adjusts dependencies/user execution to better match production constraints.

Comment thread music_assistant/helpers/dsp.py Resolved

@maximmaxim345 maximmaxim345 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @OzGav !
Even when doing Room Correction, some things just can't be done with a simpler PEQ.
This makes me want to try out measuring my Speakers again with fancy DRC software.

@maximmaxim345
maximmaxim345 merged commit 0766c93 into dev Aug 3, 2026
16 checks passed
@maximmaxim345
maximmaxim345 deleted the dsp-convolution-filter branch August 3, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants