panning and attenuation for pickaxe audio cue

This commit is contained in:
minjaesong
2024-03-31 21:02:00 +09:00
parent 742b63a8fa
commit f72ed0f706
5 changed files with 48 additions and 27 deletions

View File

@@ -226,10 +226,12 @@ class AudioMixer : Disposable {
init {
// initialise audio paths //
listOf(musicTrack, ambientTrack1, ambientTrack2, ambientTrack3, ambientTrack4).forEach {
listOf(musicTrack, ambientTrack1, ambientTrack2, ambientTrack3, ambientTrack4, guiTrack).forEach {
it.filters[0] = Gain(1f)
}
guiTrack.filters[0] = BinoPan(0f)
masterTrack.filters[0] = SoftClp
masterTrack.filters[1] = Buffer
masterTrack.filters[2] = Vecto(1.4142f)
@@ -369,7 +371,7 @@ class AudioMixer : Disposable {
it.getFilter<Gain>().gain = ambientVolume.toFloat()
}
sfxSumBus.volume = sfxVolume
guiTrack.volume = guiVolume
guiTrack.getFilter<Gain>().gain = guiVolume.toFloat()
// process fades

View File

@@ -24,6 +24,28 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
private var buffertaille = bufferSize
companion object {
fun getVolFun(x: Double): Double {
// https://www.desmos.com/calculator/blcd4s69gl
// val K = 1.225
// fun q(x: Double) = if (x >= 1.0) 0.5 else (K*x - K).pow(2.0) + 0.5
// val x2 = x.pow(q(x))
// method 1.
// https://www.desmos.com/calculator/uzbjw10lna
// val K = 512.0
// return K.pow(-sqrt(1.0+x.sqr())) * K
// method 2.
// https://www.desmos.com/calculator/3xsac66rsp
// method 3.
// comparison with method 1.
// https://www.desmos.com/calculator/rbteowef8v
val Q = 2.0
return 1.0 / cosh(Q * x).sqr()
}
}
@Volatile var running = true; private set
@@ -310,29 +332,6 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
// } // uncomment to multithread
}
private fun getVolFun(x: Double): Double {
// https://www.desmos.com/calculator/blcd4s69gl
// val K = 1.225
// fun q(x: Double) = if (x >= 1.0) 0.5 else (K*x - K).pow(2.0) + 0.5
// val x2 = x.pow(q(x))
// method 1.
// https://www.desmos.com/calculator/uzbjw10lna
// val K = 512.0
// return K.pow(-sqrt(1.0+x.sqr())) * K
// method 2.
// https://www.desmos.com/calculator/3xsac66rsp
// method 3.
// comparison with method 1.
// https://www.desmos.com/calculator/rbteowef8v
val Q = 2.0
return 1.0 / cosh(Q * x).sqr()
}
private fun FloatArray.applyVolume(volume: Float) = FloatArray(this.size) { (this[it] * volume) }
/*private fun FloatArray.applyVolumeInline(volume: Float): FloatArray {
for (i in this.indices) {