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 Configurable DSP with Parametric Equalizer #1795

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

maximmaxim345
Copy link

@maximmaxim345 maximmaxim345 commented Nov 26, 2024

Overview

This Pull Request introduces a sophisticated multi-stage Digital Signal Processing (DSP) system to Music Assistant, featuring a highly-flexible Parametric Equalizer as its core component.

Screenshot

Screenshot 2024-11-26 at 18-12-11 Music Assistant

For me, the main feature missing from Music Assistant was the lack of a Parametric Equalizer, therefore I added one.

Related Changes

This PR is to be viewed in conjunction with music-assistant/frontend#756 and music-assistant/models#18.

This PR depends on music-assistant/models#18.

Future Filters

This modular system allows the addition of other filters in the future, that I will add in future PRs including:

  • Crossfeed: Creates a more natural stereo image by mixing left and right channels
  • Basic Tone Controls: replacing CONF_EQ_BASS, CONF_EQ_MID and CONF_EQ_TREBLE
  • Compressor: Useful for listening in loud environments
  • Limiter: Prevents audio clipping by limiting peak levels
  • Convolution: Applies Room Correction filters using impulse responses
  • AutoEq: Predefined Equalizers for a large number of Headphones

Implementation Details

DSP Configuration is saved in a separate key compared to all other player configuration.
This has the following advantages:

  • Applying changes can be sped up, since main player configuration
    stays the same
  • Changing DSP does not require resending Player options as dictated by
    the provider
  • Later filters like convolution require special handling for the IR WAV
    file
  • This allows saving/loading presets without changing the player's
    configuration

DSP should function with all player providers as I understand, since get_raw_player_config_value is used regardless of the underlying provider.

Tested with DLNA, Chromecast and Sonos.

This method is analogous to `on_player_config_change`, but just restarts
the playback. Since resuming playback restarts ffmpeg, the DSP
configuration is reloaded.
DSP configuration is now handled separately from player configuration.
This has a few advantages:
- Applying changes can be speed up, since main player configuration
stays the same
- Changing DSP does not require to resend Player options as dictated by
the provider
- Later filters like convolution require special handling for the IR wav
file
- This allows saving/loading presets without chaning the players
configuration
Some FFMPEG filters like biquad require knowing the sample rate.
This commit add Parametric Equalizer support to Music Assistant.
By using Biquad Filters, this implementation uses minimal CPU usage and
supports all common filter types typically found in Room/Headphone
correction scenarios.
@marcelveldt
Copy link
Member

marcelveldt commented Nov 26, 2024

Wow, just wow. I was kind of hoping someone would pick up the glove for this (as I did prepare a few hooks for this in the code). You just did. Amazing!

I will give this a proper review tomorrow. First impression: Super nice work!

@maximmaxim345
Copy link
Author

maximmaxim345 commented Nov 27, 2024

I'm thinking, maybe this PR (or another PR in the same release) should also add a Tone Controls Filter?

Then we can easily migrate the CONF_EQ_BASS, CONF_EQ_MID and CONF_EQ_TREBLE settings by:

  • Automatically adding a "Tone Controls" filter to the default DSP config in case the user previously set CONF_EQ_BASS, CONF_EQ_MID or CONF_EQ_TREBLE
  • hiding CONF_EQ_BASS, CONF_EQ_MID and CONF_EQ_TREBLE from the player config UI
  • resetting CONF_EQ_BASS, CONF_EQ_MID and CONF_EQ_TREBLE to 0 if a DSP config is saved

Otherwise it would be more difficult to handle this case:

  1. The user already uses CONF_EQ_BASS, CONF_EQ_MID or CONF_EQ_TREBLE
  2. The user changed the DSP config (by adding a Parametric EQ)
  3. The user updated Music Assistant with the "Tone Controls" moved to DSP Config

Let me know, if I should put this in this set of PRs or open another one.

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.

2 participants