mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 12:04:06 +09:00
even more panning
This commit is contained in:
@@ -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 distFromActor = distBetweenActors(AudioMixer.actorNowPlaying!!, track.trackingTarget as ActorWithBody)
|
||||||
val vol = track.maxVolume * getVolFun(distFromActor / distFalloff).coerceAtLeast(0.0)
|
val vol = track.maxVolume * getVolFun(distFromActor / distFalloff).coerceAtLeast(0.0)
|
||||||
track.volume = vol
|
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(
|
(track.filters[1] as Lowpass).setCutoff(
|
||||||
(SAMPLING_RATED*0.5) / (24.0 * (distFromActor / distFalloff).sqr() + 1.0)
|
(SAMPLING_RATED*0.5) / (24.0 * (distFromActor / distFalloff).sqr() + 1.0)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import net.torvald.terrarum.ui.BasicDebugInfoWindow.Companion.toIntAndFrac
|
|||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.math.sqrt
|
||||||
import kotlin.math.tanh
|
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_DEFAULT = 0.18f
|
||||||
const val EARDIST_MAX = 16f
|
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 L = 0
|
||||||
private const val R = 1
|
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 {
|
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]}")
|
// printdbg(this, "$sym\tpan=$pan, mults=${mults[L]}\t${mults[R]}")
|
||||||
}
|
}
|
||||||
override fun thru(inbuf: List<FloatArray>, outbuf: List<FloatArray>) {
|
override fun thru(inbuf: List<FloatArray>, outbuf: List<FloatArray>) {
|
||||||
thru("L", -60f, inbuf[L], outLs, delayLineL)
|
thru("L", -50f, inbuf[L], outLs, delayLineL) // 50 will become 59.036 on panningFieldMap
|
||||||
thru("R", +60f, inbuf[R], outRs, delayLineR)
|
thru("R", +50f, inbuf[R], outRs, delayLineR)
|
||||||
|
|
||||||
for (i in 0 until AUDIO_BUFFER_SIZE) {
|
for (i in 0 until AUDIO_BUFFER_SIZE) {
|
||||||
val outL = (outLs[L][i] + outRs[L][i]) / 2f
|
val outL = (outLs[L][i] + outRs[L][i]) / 2f
|
||||||
|
|||||||
Reference in New Issue
Block a user