Search code examples
javadiscorddiscord-jdalavaplayer

Bass Boost - JDA Lavaplayer


How would you create a bass boost command when you are using Lavaplayer with JDA (Java Discord API)?

Have a command like !bassboost 0-100.


Solution

  • After hours of trying different things to get it to function correctly I ended up using a Lavaplayer EqualizerFactory.

    Firstly I copied these values from here

        public static final float[] BASS_BOOST = {
                0.2f,
                0.15f,
                0.1f,
                0.05f,
                0.0f,
                -0.05f,
                -0.1f,
                -0.1f,
                -0.1f,
                -0.1f,
                -0.1f,
                -0.1f,
                -0.1f,
                -0.1f,
                -0.1f
        };
    

    then I created a new EqualizerFactory and added it as a filter to the guild music manager and also set the frame buffer duration to make the bass-boost take less time to take effect like so:

            this.equalizer = new EqualizerFactory();
    
            this.player.setFilterFactory(equalizer);
            this.player.setFrameBufferDuration(500); // prevent bass boost taking time to take effect
    

    then I finally created a little method that you can provide from 0-200 to set the bass-boost level

        public void bassBoost(float percentage)
        {
            final float multiplier = percentage / 100.00f;
    
            for (int i = 0; i < BASS_BOOST.length; i++)
            {
                equalizer.setGain(i, BASS_BOOST[i] * multiplier);
            }
        }
    

    so that the bass-boost took effect on the current playing song I needed this:

    playerManager.getConfiguration().setFilterHotSwapEnabled(true);
    

    and that's about it really!