fix: bus fader not working

This commit is contained in:
minjaesong
2023-11-20 17:11:19 +09:00
parent 224c0f7863
commit d3d52b0b6f
5 changed files with 56 additions and 24 deletions

View File

@@ -124,9 +124,10 @@ object DefaultConfig {
"mastervolume" to 1.0,
"musicvolume" to 1.0,
"bgmvolume" to 1.0,
"ambientvolume" to 1.0,
"sfxvolume" to 1.0,
"guivolume" to 1.0,
"lightpasses" to 3,

View File

@@ -25,18 +25,21 @@ import kotlin.math.*
object AudioMixer: Disposable {
const val DEFAULT_FADEOUT_LEN = 1.8
/** Returns a master volume */
val masterVolume: Double
get() = App.getConfigDouble("mastervolume")
/** Returns a (master volume * bgm volume) */
val musicVolume: Double
get() = App.getConfigDouble("bgmvolume")
/** Returns a (master volume * sfx volume */
val ambientVolume: Double
get() = App.getConfigDouble("ambientvolume")
val sfxVolume: Double
get() = App.getConfigDouble("sfxvolume")
val guiVolume: Double
get() = App.getConfigDouble("guivolume")
val tracks = Array(5) { TerrarumAudioMixerTrack(
if (it == 0) "BGM"
@@ -88,7 +91,6 @@ object AudioMixer: Disposable {
init {
masterTrack.volume = masterVolume
masterTrack.filters[0] = Buffer
fadeBus.addSidechainInput(musicTrack, 1.0)
@@ -126,9 +128,16 @@ object AudioMixer: Disposable {
// TODO fadein/out controls the master track
fun update(delta: Float) {
// the real updates
(Gdx.audio as? Lwjgl3Audio)?.update()
masterTrack.volume = masterVolume
musicTrack.volume = musicVolume
ambientTrack.volume = ambientVolume
sfxMixTrack.volume = sfxVolume
guiTrack.volume = guiVolume
// process fades
if (fadeoutFired) {
fadeAkku += delta
val step = fadeAkku / fadeLength

View File

@@ -2,8 +2,6 @@ package net.torvald.terrarum.audio
import com.badlogic.gdx.utils.Queue
import net.torvald.reflection.forceInvoke
import net.torvald.terrarum.audio.AudioMixer.masterVolume
import net.torvald.terrarum.audio.AudioMixer.musicVolume
import kotlin.math.absoluteValue
/**
@@ -93,13 +91,14 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
var bufEmpty = false
// get samples and apply the fader
if (track.isMaster || track.isBus) {
// TEST CODE must combine all the inputs
track.sidechainInputs[TerrarumAudioMixerTrack.INDEX_BGM]?.let {
samplesL0 = it.first.processor.fout0[0].applyVolume(musicVolume)
samplesR0 = it.first.processor.fout0[1].applyVolume(musicVolume)
samplesL1 = it.first.processor.fout1[0].applyVolume(musicVolume)
samplesR1 = it.first.processor.fout1[1].applyVolume(musicVolume)
track.sidechainInputs[TerrarumAudioMixerTrack.INDEX_BGM]?.let { (side, mix) ->
samplesL0 = side.processor.fout0[0].applyVolume((mix * track.volume).toFloat())
samplesR0 = side.processor.fout0[1].applyVolume((mix * track.volume).toFloat())
samplesL1 = side.processor.fout1[0].applyVolume((mix * track.volume).toFloat())
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 ->
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}")
val masvol = masterVolume
track.volume = masvol
track.pcmQueue.addLast(fout1.map { it.applyVolume(masvol) })
track.pcmQueue.addLast(fout1)
}
// spin
@@ -210,6 +209,13 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
// } // 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) {
track?.getSidechains()?.forEach {
@@ -247,8 +253,6 @@ class MixerTrackProcessor(val bufferSize: Int, val rate: Int, val track: Terraru
pauseLock.notifyAll() // Unblocks thread
}
}
private fun FloatArray.applyVolume(musicVolume: Double) = FloatArray(this.size) { (this[it] * musicVolume).toFloat() }
}

View File

@@ -17,14 +17,15 @@ class UISoundControlPanel(remoCon: UIRemoCon?) : UICanvas() {
handler.allowESCtoClose = false
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("bgmvolume", { Lang["MENU_LABEL_BACKGROUND_MUSIC"] }, "sliderd,0,1"),
arrayOf("bgmvolume", { Lang["MENU_LABEL_MUSIC"] }, "sliderd,0,1"),
arrayOf("", { "" }, "p"),
arrayOf("musicvolume", { Lang["MENU_LABEL_MUSIC"] }, "sliderd,0,1"),
arrayOf("ambientvolume", { Lang["MENU_LABEL_AMBIENT_SOUND"] }, "sliderd,0,1"),
arrayOf("", { "" }, "p"),
arrayOf("sfxvolume", { Lang["CREDITS_SFX"] }, "sliderd,0,1"),
arrayOf("", { "" }, "p"),
arrayOf("guivolume", { Lang["MENU_LABEL_INTERFACE"] }, "sliderd,0,1"),
))
}

View File

@@ -377,7 +377,8 @@ class BasicDebugInfoWindow : UICanvas() {
private val stripGap = 1
private val stripFilterHeight = 32
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_WELL2 = Color(0x3f5360_aa)
@@ -440,7 +441,7 @@ class BasicDebugInfoWindow : UICanvas() {
// filterbank 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) {
// draw filter title back
@@ -455,7 +456,23 @@ class BasicDebugInfoWindow : UICanvas() {
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
val dB = track.dBfs