mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
fix: bus fader not working
This commit is contained in:
@@ -124,9 +124,10 @@ object DefaultConfig {
|
|||||||
|
|
||||||
|
|
||||||
"mastervolume" to 1.0,
|
"mastervolume" to 1.0,
|
||||||
"musicvolume" to 1.0,
|
|
||||||
"bgmvolume" to 1.0,
|
"bgmvolume" to 1.0,
|
||||||
|
"ambientvolume" to 1.0,
|
||||||
"sfxvolume" to 1.0,
|
"sfxvolume" to 1.0,
|
||||||
|
"guivolume" to 1.0,
|
||||||
|
|
||||||
"lightpasses" to 3,
|
"lightpasses" to 3,
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,21 @@ import kotlin.math.*
|
|||||||
object AudioMixer: Disposable {
|
object AudioMixer: Disposable {
|
||||||
const val DEFAULT_FADEOUT_LEN = 1.8
|
const val DEFAULT_FADEOUT_LEN = 1.8
|
||||||
|
|
||||||
/** Returns a master volume */
|
|
||||||
val masterVolume: Double
|
val masterVolume: Double
|
||||||
get() = App.getConfigDouble("mastervolume")
|
get() = App.getConfigDouble("mastervolume")
|
||||||
|
|
||||||
/** Returns a (master volume * bgm volume) */
|
|
||||||
val musicVolume: Double
|
val musicVolume: Double
|
||||||
get() = App.getConfigDouble("bgmvolume")
|
get() = App.getConfigDouble("bgmvolume")
|
||||||
|
|
||||||
/** Returns a (master volume * sfx volume */
|
|
||||||
val ambientVolume: Double
|
val ambientVolume: Double
|
||||||
|
get() = App.getConfigDouble("ambientvolume")
|
||||||
|
|
||||||
|
val sfxVolume: Double
|
||||||
get() = App.getConfigDouble("sfxvolume")
|
get() = App.getConfigDouble("sfxvolume")
|
||||||
|
|
||||||
|
val guiVolume: Double
|
||||||
|
get() = App.getConfigDouble("guivolume")
|
||||||
|
|
||||||
|
|
||||||
val tracks = Array(5) { TerrarumAudioMixerTrack(
|
val tracks = Array(5) { TerrarumAudioMixerTrack(
|
||||||
if (it == 0) "BGM"
|
if (it == 0) "BGM"
|
||||||
@@ -88,7 +91,6 @@ object AudioMixer: Disposable {
|
|||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
masterTrack.volume = masterVolume
|
|
||||||
masterTrack.filters[0] = Buffer
|
masterTrack.filters[0] = Buffer
|
||||||
|
|
||||||
fadeBus.addSidechainInput(musicTrack, 1.0)
|
fadeBus.addSidechainInput(musicTrack, 1.0)
|
||||||
@@ -126,9 +128,16 @@ object AudioMixer: Disposable {
|
|||||||
// TODO fadein/out controls the master track
|
// TODO fadein/out controls the master track
|
||||||
|
|
||||||
fun update(delta: Float) {
|
fun update(delta: Float) {
|
||||||
|
// the real updates
|
||||||
(Gdx.audio as? Lwjgl3Audio)?.update()
|
(Gdx.audio as? Lwjgl3Audio)?.update()
|
||||||
|
masterTrack.volume = masterVolume
|
||||||
|
musicTrack.volume = musicVolume
|
||||||
|
ambientTrack.volume = ambientVolume
|
||||||
|
sfxMixTrack.volume = sfxVolume
|
||||||
|
guiTrack.volume = guiVolume
|
||||||
|
|
||||||
|
|
||||||
|
// process fades
|
||||||
if (fadeoutFired) {
|
if (fadeoutFired) {
|
||||||
fadeAkku += delta
|
fadeAkku += delta
|
||||||
val step = fadeAkku / fadeLength
|
val step = fadeAkku / fadeLength
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package net.torvald.terrarum.audio
|
|||||||
|
|
||||||
import com.badlogic.gdx.utils.Queue
|
import com.badlogic.gdx.utils.Queue
|
||||||
import net.torvald.reflection.forceInvoke
|
import net.torvald.reflection.forceInvoke
|
||||||
import net.torvald.terrarum.audio.AudioMixer.masterVolume
|
|
||||||
import net.torvald.terrarum.audio.AudioMixer.musicVolume
|
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,13 +91,14 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
|
|||||||
|
|
||||||
var bufEmpty = false
|
var bufEmpty = false
|
||||||
|
|
||||||
|
// get samples and apply the fader
|
||||||
if (track.isMaster || track.isBus) {
|
if (track.isMaster || track.isBus) {
|
||||||
// TEST CODE must combine all the inputs
|
// TEST CODE must combine all the inputs
|
||||||
track.sidechainInputs[TerrarumAudioMixerTrack.INDEX_BGM]?.let {
|
track.sidechainInputs[TerrarumAudioMixerTrack.INDEX_BGM]?.let { (side, mix) ->
|
||||||
samplesL0 = it.first.processor.fout0[0].applyVolume(musicVolume)
|
samplesL0 = side.processor.fout0[0].applyVolume((mix * track.volume).toFloat())
|
||||||
samplesR0 = it.first.processor.fout0[1].applyVolume(musicVolume)
|
samplesR0 = side.processor.fout0[1].applyVolume((mix * track.volume).toFloat())
|
||||||
samplesL1 = it.first.processor.fout1[0].applyVolume(musicVolume)
|
samplesL1 = side.processor.fout1[0].applyVolume((mix * track.volume).toFloat())
|
||||||
samplesR1 = it.first.processor.fout1[1].applyVolume(musicVolume)
|
samplesR1 = side.processor.fout1[1].applyVolume((mix * track.volume).toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -161,6 +160,8 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// scan the finished sample for mapping signal level and clipping detection
|
||||||
fout1.map { it.maxOf { it.absoluteValue } }.forEachIndexed { index, fl ->
|
fout1.map { it.maxOf { it.absoluteValue } }.forEachIndexed { index, fl ->
|
||||||
maxSigLevel[index] = fl.toDouble()
|
maxSigLevel[index] = fl.toDouble()
|
||||||
}
|
}
|
||||||
@@ -196,9 +197,7 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
// printdbg("PUSHE; Queue size: ${track.pcmQueue.size}")
|
// printdbg("PUSHE; Queue size: ${track.pcmQueue.size}")
|
||||||
val masvol = masterVolume
|
track.pcmQueue.addLast(fout1)
|
||||||
track.volume = masvol
|
|
||||||
track.pcmQueue.addLast(fout1.map { it.applyVolume(masvol) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// spin
|
// spin
|
||||||
@@ -210,6 +209,13 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
|
|||||||
// } // uncomment to multithread
|
// } // uncomment to multithread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FloatArray.applyVolume(volume: Float) = FloatArray(this.size) { (this[it] * volume) }
|
||||||
|
private fun FloatArray.applyVolumeInline(volume: Float) {
|
||||||
|
for (i in this.indices) {
|
||||||
|
this[i] *= volume
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun resumeSidechainsRecursively(track: TerrarumAudioMixerTrack?, caller: String) {
|
private fun resumeSidechainsRecursively(track: TerrarumAudioMixerTrack?, caller: String) {
|
||||||
track?.getSidechains()?.forEach {
|
track?.getSidechains()?.forEach {
|
||||||
@@ -247,8 +253,6 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
|
|||||||
pauseLock.notifyAll() // Unblocks thread
|
pauseLock.notifyAll() // Unblocks thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FloatArray.applyVolume(musicVolume: Double) = FloatArray(this.size) { (this[it] * musicVolume).toFloat() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ class UISoundControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
|||||||
handler.allowESCtoClose = false
|
handler.allowESCtoClose = false
|
||||||
|
|
||||||
ControlPanelCommon.register(this, width, "basegame.soundcontrolpanel", arrayOf(
|
ControlPanelCommon.register(this, width, "basegame.soundcontrolpanel", arrayOf(
|
||||||
arrayOf("mastervolume", { Lang["MENU_OPTIONS_SOUND_VOLUME"] }, "sliderd,0,1"),
|
arrayOf("mastervolume", { Lang["MENU_OPTIONS_MASTER_VOLUME"] }, "sliderd,0,1"),
|
||||||
arrayOf("", { "" }, "p"),
|
arrayOf("", { "" }, "p"),
|
||||||
arrayOf("bgmvolume", { Lang["MENU_LABEL_BACKGROUND_MUSIC"] }, "sliderd,0,1"),
|
arrayOf("bgmvolume", { Lang["MENU_LABEL_MUSIC"] }, "sliderd,0,1"),
|
||||||
arrayOf("", { "" }, "p"),
|
arrayOf("", { "" }, "p"),
|
||||||
arrayOf("musicvolume", { Lang["MENU_LABEL_MUSIC"] }, "sliderd,0,1"),
|
arrayOf("ambientvolume", { Lang["MENU_LABEL_AMBIENT_SOUND"] }, "sliderd,0,1"),
|
||||||
arrayOf("", { "" }, "p"),
|
arrayOf("", { "" }, "p"),
|
||||||
arrayOf("sfxvolume", { Lang["CREDITS_SFX"] }, "sliderd,0,1"),
|
arrayOf("sfxvolume", { Lang["CREDITS_SFX"] }, "sliderd,0,1"),
|
||||||
|
arrayOf("", { "" }, "p"),
|
||||||
|
arrayOf("guivolume", { Lang["MENU_LABEL_INTERFACE"] }, "sliderd,0,1"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -377,7 +377,8 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
private val stripGap = 1
|
private val stripGap = 1
|
||||||
private val stripFilterHeight = 32
|
private val stripFilterHeight = 32
|
||||||
private val stripFaderHeight = 200
|
private val stripFaderHeight = 200
|
||||||
private val stripH = stripFaderHeight + stripFilterHeight * 4 + 16
|
private val numberOfFilters = 5
|
||||||
|
private val stripH = stripFaderHeight + stripFilterHeight * numberOfFilters + 16
|
||||||
|
|
||||||
private val COL_WELL = Color(0x374854_aa)
|
private val COL_WELL = Color(0x374854_aa)
|
||||||
private val COL_WELL2 = Color(0x3f5360_aa)
|
private val COL_WELL2 = Color(0x3f5360_aa)
|
||||||
@@ -440,7 +441,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
|
|
||||||
// filterbank back
|
// filterbank back
|
||||||
batch.color = COL_FILTER_WELL_BACK
|
batch.color = COL_FILTER_WELL_BACK
|
||||||
Toolkit.fillArea(batch, x, y, stripW, stripFilterHeight * 4)
|
Toolkit.fillArea(batch, x, y, stripW, stripFilterHeight * numberOfFilters)
|
||||||
|
|
||||||
track.filters.forEachIndexed { i, filter -> if (filter !is NullFilter) {
|
track.filters.forEachIndexed { i, filter -> if (filter !is NullFilter) {
|
||||||
// draw filter title back
|
// draw filter title back
|
||||||
@@ -455,7 +456,23 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
drawFilterParam(batch, x, y + stripFilterHeight * i + 16, filter, track)
|
drawFilterParam(batch, x, y + stripFilterHeight * i + 16, filter, track)
|
||||||
} }
|
} }
|
||||||
|
|
||||||
val faderY = y + stripFilterHeight * 4
|
val faderY = y + stripFilterHeight * numberOfFilters
|
||||||
|
|
||||||
|
// receives (opposite of "sends")
|
||||||
|
track.sidechainInputs.filterNotNull().reversed().forEachIndexed { i, (side, mix) ->
|
||||||
|
val mixDb = fullscaleToDecibels(mix)
|
||||||
|
val perc = ((mixDb + 24.0).coerceAtLeast(0.0) / 24.0).toFloat()
|
||||||
|
// gauge background
|
||||||
|
batch.color = COL_METER_GRAD2
|
||||||
|
Toolkit.fillArea(batch, x.toFloat(), faderY - (i+1)*16f, stripW * perc, 14f)
|
||||||
|
batch.color = COL_METER_GRAD
|
||||||
|
Toolkit.fillArea(batch, x.toFloat(), faderY - (i+1)*16f + 14f, stripW * perc, 2f)
|
||||||
|
|
||||||
|
// label
|
||||||
|
batch.color = FILTER_NAME_ACTIVE
|
||||||
|
App.fontSmallNumbers.draw(batch, "\u00C0", x.toFloat(), faderY - (i+1)*16f + 1f)
|
||||||
|
App.fontSmallNumbers.draw(batch, side.name, x + 10f, faderY - (i+1)*16f + 1f)
|
||||||
|
}
|
||||||
|
|
||||||
// fader
|
// fader
|
||||||
val dB = track.dBfs
|
val dB = track.dBfs
|
||||||
|
|||||||
Reference in New Issue
Block a user