mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
panning and attenuation for pickaxe audio cue
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user