Repository navigation
Add DSP convolution filter - #4947
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
e1c4c0f to
23f32fe
Compare
|
Setting as draft as Steven identified we need a new event so need a models bump to permit that. |
453dd08 to
2a8a1bf
Compare
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.
2a8a1bf to
5552b02
Compare
1b09b08 to
89aa614
Compare
89aa614 to
64203e4
Compare
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.
There was a problem hiding this comment.
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 newComplexFilterInputmodel and updated filtergraph argument generation to attach extra-iinputs. - 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. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
This reverts commit 95da109.
Co-authored-by: OzGav <[email protected]>
maximmaxim345
left a comment
There was a problem hiding this comment.
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.
What does this implement/fix?
Adds the new
ConvolutionFilterDSP 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_irssubdirectory of the storage path with a metadata record in the config store, managed by three new commands:config/dsp_irs/list,/uploadand/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):
Types of changes
bugfixnew-featureenhancementnew-providerbreaking-changerefactordocumentationmaintenancecidependenciesChecklist
pre-commit run --all-filespasses.pytestpasses, and tests have been added/updated undertests/where applicable.music-assistant/modelsis linked.music-assistant/frontendis linked.