fix: track fader was applied at PRE instead of POST

This commit is contained in:
minjaesong
2024-01-24 19:10:04 +09:00
parent 2016be562b
commit b67c0837d8
2 changed files with 16 additions and 6 deletions

View File

@@ -188,10 +188,12 @@ class AudioProcessBuf(val inputSamplingRate: Int, val audioReadFun: (ByteArray)
// printdbg(this, "phase = $fPhaseL") // printdbg(this, "phase = $fPhaseL")
} }
fun getLR(volume: Double): Pair<FloatArray, FloatArray> { fun getLR(): Pair<FloatArray, FloatArray> {
// copy into the out // copy into the out
val outL = FloatArray(App.audioBufferSize) { (foutL[it] * volume).toFloat() } val outL = FloatArray(App.audioBufferSize)
val outR = FloatArray(App.audioBufferSize) { (foutR[it] * volume).toFloat() } val outR = FloatArray(App.audioBufferSize)
System.arraycopy(foutL, 0, outL, 0, App.audioBufferSize)
System.arraycopy(foutR, 0, outR, 0, App.audioBufferSize)
// shift bytes in the fout // shift bytes in the fout
System.arraycopy(foutL, App.audioBufferSize, foutL, 0, validSamplesInBuf - App.audioBufferSize) System.arraycopy(foutL, App.audioBufferSize, foutL, 0, validSamplesInBuf - App.audioBufferSize)
System.arraycopy(foutR, App.audioBufferSize, foutR, 0, validSamplesInBuf - App.audioBufferSize) System.arraycopy(foutR, App.audioBufferSize, foutR, 0, validSamplesInBuf - App.audioBufferSize)

View File

@@ -184,8 +184,8 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
// add all up // add all up
sidechains.forEach { (side, mix) -> sidechains.forEach { (side, mix) ->
for (i in samplesL1.indices) { for (i in samplesL1.indices) {
samplesL1[i] += side.processor.fout1[0][i] * (mix * track.volume).toFloat() samplesL1[i] += side.processor.fout1[0][i] * mix.toFloat()
samplesR1[i] += side.processor.fout1[1][i] * (mix * track.volume).toFloat() samplesR1[i] += side.processor.fout1[1][i] * mix.toFloat()
} }
} }
} }
@@ -198,7 +198,7 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
bufEmpty = true bufEmpty = true
} }
else { else {
streamBuf!!.getLR(track.volume).let { streamBuf!!.getLR().let {
samplesL1 = it.first samplesL1 = it.first
samplesR1 = it.second samplesR1 = it.second
} }
@@ -225,6 +225,14 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
} }
// apply fader at post
fout1.forEach { ch ->
ch.forEachIndexed { index, sample ->
ch[index] = (sample * track.volume).toFloat()
}
}
// scan the finished sample for mapping signal level and clipping detection // 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()