Skip to content

Commit

Permalink
Merge pull request lavalink-devs#485 from TopiSenpai/dev
Browse files Browse the repository at this point in the history
new filters from lavadsp
  • Loading branch information
freyacodes authored May 31, 2021
2 parents 8125918 + a946c08 commit c31aecc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
18 changes: 16 additions & 2 deletions IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ Note that filters may take a moment to apply.
"frequency": 2.0, // 0 < x ≤ 14
"depth": 0.5 // 0 < x ≤ 1
},

// Rotates the sound around the stereo channels/user headphones aka Audio Panning. It can produce an effect similar to: https://youtu.be/QB9EB8mTKcc (without the reverb)
"rotation": {
"rotationHz": 0 // The frequency of the audio rotating around the listener in Hz. 0.2 is similar to the example video above.
},
//Distortion effect. It can generate some pretty unique audio effects.

// Distortion effect. It can generate some pretty unique audio effects.
"distortion": {
"sinOffset": 0,
"sinScale": 1,
Expand All @@ -207,9 +209,21 @@ Note that filters may take a moment to apply.
"offset": 0,
"scale": 1
}

// Mixes both channels (left and right), with a configurable factor on how much each channel affects the other.
// With the defaults, both channels are kept independent from each other.
// Setting all factors to 0.5 means both channels get the same audio.
"channelMix": {
"leftToLeft": 1.0,
"leftToRight": 0.0,
"rightToLeft": 0.0,
"rightToRight": 1.0,
}


// Higher frequencies get suppressed, while lower frequencies pass through this filter, thus the name low pass.
"lowPass": {
"smoothing": 20.0
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FilterChain : PcmFilterFactory {
private val vibrato: VibratoConfig? = null
private val distortion: DistortionConfig? = null
private val rotation: RotationConfig? = null
private val channelMix: ChannelMixConfig? = null
private val lowPass: LowPassConfig? = null

private fun buildList() = listOfNotNull(
volume?.let { VolumeConfig(it) },
Expand All @@ -32,7 +34,9 @@ class FilterChain : PcmFilterFactory {
tremolo,
vibrato,
distortion,
rotation
rotation,
channelMix,
lowPass
)

val isEnabled get() = buildList().any { it.isEnabled }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package lavalink.server.player.filters

import com.github.natanbc.lavadsp.channelmix.ChannelMixPcmAudioFilter
import com.github.natanbc.lavadsp.karaoke.KaraokePcmAudioFilter
import com.github.natanbc.lavadsp.timescale.TimescalePcmAudioFilter
import com.github.natanbc.lavadsp.tremolo.TremoloPcmAudioFilter
import com.github.natanbc.lavadsp.vibrato.VibratoPcmAudioFilter
import com.github.natanbc.lavadsp.distortion.DistortionPcmAudioFilter
import com.github.natanbc.lavadsp.lowpass.LowPassPcmAudioFilter
import com.github.natanbc.lavadsp.rotation.RotationPcmAudioFilter
import com.github.natanbc.lavadsp.volume.VolumePcmAudioFilter
import com.sedmelluq.discord.lavaplayer.filter.AudioFilter
Expand Down Expand Up @@ -136,6 +138,35 @@ class RotationConfig(
override val isEnabled: Boolean get() = rotationHz != 0.0
}

class ChannelMixConfig(
private val leftToLeft: Float = 1f,
private val leftToRight: Float = 0f,
private val rightToLeft: Float = 0f,
private val rightToRight: Float = 1f

) : FilterConfig() {
override fun build(format: AudioDataFormat, output: FloatPcmAudioFilter): FloatPcmAudioFilter {
return ChannelMixPcmAudioFilter(output)
.setLeftToLeft(leftToLeft)
.setLeftToRight(leftToRight)
.setRightToLeft(rightToLeft)
.setRightToRight(rightToRight)
}

override val isEnabled: Boolean get() = leftToLeft != 1f || leftToRight != 0f || rightToLeft != 0f || rightToRight != 1f
}

class LowPassConfig(
private val smoothing: Float = 20.0f
) : FilterConfig() {
override fun build(format: AudioDataFormat, output: FloatPcmAudioFilter): FloatPcmAudioFilter {
return LowPassPcmAudioFilter(output, format.sampleRate)
.setSmoothing(smoothing)
}

override val isEnabled: Boolean get() = smoothing != 20.0f
}

abstract class FilterConfig {
abstract fun build(format: AudioDataFormat, output: FloatPcmAudioFilter): FloatPcmAudioFilter
abstract val isEnabled: Boolean
Expand Down

0 comments on commit c31aecc

Please sign in to comment.