even more panning

This commit is contained in:
minjaesong
2024-01-12 17:28:03 +09:00
parent 236d4e4e53
commit 40365fd828
2 changed files with 8 additions and 6 deletions

View File

@@ -131,7 +131,7 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
val distFromActor = distBetweenActors(AudioMixer.actorNowPlaying!!, track.trackingTarget as ActorWithBody)
val vol = track.maxVolume * getVolFun(distFromActor / distFalloff).coerceAtLeast(0.0)
track.volume = vol
(track.filters[0] as BinoPan).pan = tanh(1.5 * relativeXpos / distFalloff).toFloat()
(track.filters[0] as BinoPan).pan = (1.3f * relativeXpos / distFalloff).toFloat()
(track.filters[1] as Lowpass).setCutoff(
(SAMPLING_RATED*0.5) / (24.0 * (distFromActor / distFalloff).sqr() + 1.0)
)

View File

@@ -18,6 +18,7 @@ import net.torvald.terrarum.ui.BasicDebugInfoWindow.Companion.toIntAndFrac
import net.torvald.terrarum.ui.Toolkit
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
import kotlin.math.sqrt
import kotlin.math.tanh
/**
@@ -50,7 +51,7 @@ class BinoPan(var pan: Float, var earDist: Float = EARDIST_DEFAULT): TerrarumAud
const val EARDIST_DEFAULT = 0.18f
const val EARDIST_MAX = 16f
private val PANNING_CONST = 6.0
private val PANNING_CONST = 6.0 / 2.0
private const val L = 0
private const val R = 1
@@ -58,10 +59,11 @@ class BinoPan(var pan: Float, var earDist: Float = EARDIST_DEFAULT): TerrarumAud
}
/**
* @param intensity -2 to 2
* @param intensity -inf to +inf
*/
private fun panningFieldMap(intensity: Float): Float {
return tanh(intensity)
// https://www.desmos.com/calculator/0c6ivoqr52
return tanh(sqrt(2f) * intensity)
}
@@ -105,8 +107,8 @@ class BinoPan(var pan: Float, var earDist: Float = EARDIST_DEFAULT): TerrarumAud
// printdbg(this, "$sym\tpan=$pan, mults=${mults[L]}\t${mults[R]}")
}
override fun thru(inbuf: List<FloatArray>, outbuf: List<FloatArray>) {
thru("L", -60f, inbuf[L], outLs, delayLineL)
thru("R", +60f, inbuf[R], outRs, delayLineR)
thru("L", -50f, inbuf[L], outLs, delayLineL) // 50 will become 59.036 on panningFieldMap
thru("R", +50f, inbuf[R], outRs, delayLineR)
for (i in 0 until AUDIO_BUFFER_SIZE) {
val outL = (outLs[L][i] + outRs[L][i]) / 2f