forked from lavalink-devs/Lavalink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lavalink-devs#264 from Devoxin/filters
Working filter stuff
- Loading branch information
Showing
12 changed files
with
267 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
LavalinkServer/src/main/java/lavalink/server/player/filters/FilterChain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package lavalink.server.player.filters | ||
|
||
import com.google.gson.Gson | ||
import com.sedmelluq.discord.lavaplayer.filter.* | ||
import com.sedmelluq.discord.lavaplayer.format.AudioDataFormat | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
class FilterChain : PcmFilterFactory { | ||
|
||
companion object { | ||
private val log: Logger = LoggerFactory.getLogger(FilterChain::class.java) | ||
private val gson = Gson() | ||
fun parse(json: String) = gson.fromJson(json, FilterChain::class.java)!! | ||
} | ||
|
||
var volume: Float? = null | ||
var equalizer: List<Band>? = null | ||
private val karaoke: KaraokeConfig? = null | ||
private val timescale: TimescaleConfig? = null | ||
private val tremolo: TremoloConfig? = null | ||
private val vibrato: VibratoConfig? = null | ||
|
||
private fun buildList() = listOfNotNull( | ||
volume?.let { VolumeConfig(it) }, | ||
equalizer?.let { EqualizerConfig(it) }, | ||
karaoke, | ||
timescale, | ||
tremolo, | ||
vibrato | ||
) | ||
|
||
val isEnabled get() = buildList().any { it.isEnabled } | ||
|
||
override fun buildChain(track: AudioTrack?, format: AudioDataFormat, output: UniversalPcmAudioFilter): MutableList<AudioFilter> { | ||
val enabledFilters = buildList().takeIf { it.isNotEmpty() } | ||
?: return mutableListOf() | ||
|
||
val pipeline = mutableListOf<FloatPcmAudioFilter>() | ||
|
||
for (filter in enabledFilters) { | ||
val outputTo = pipeline.lastOrNull() ?: output | ||
pipeline.add(filter.build(format, outputTo)) | ||
} | ||
|
||
return pipeline.reversed().toMutableList() // Output last | ||
} | ||
|
||
} |
Oops, something went wrong.