mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
panning and attenuation for pickaxe audio cue
This commit is contained in:
@@ -335,7 +335,7 @@ Sound from <https://freesound.org/people/richwise>
|
|||||||
- effects/explosion/fuse.ogg
|
- effects/explosion/fuse.ogg
|
||||||
- effects/explosion/fuse_continue.ogg
|
- effects/explosion/fuse_continue.ogg
|
||||||
℗ 2012, 2015 j1987 and ScouseMouseJB
|
℗ 2012, 2015 j1987 and ScouseMouseJB
|
||||||
Sound from <https://freesound.org/people/j1987> and <https://freesound.org/people/ScouseMouseJB>
|
Remixed sound from <https://freesound.org/people/j1987> and <https://freesound.org/people/ScouseMouseJB>
|
||||||
|
|
||||||
- effects/accessibility/pickaxe_valuable.ogg
|
- effects/accessibility/pickaxe_valuable.ogg
|
||||||
℗ 2009 Benboncan
|
℗ 2009 Benboncan
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.badlogic.gdx.Input
|
|||||||
import com.badlogic.gdx.utils.Disposable
|
import com.badlogic.gdx.utils.Disposable
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
|
import net.torvald.terrarum.audio.MusicContainer
|
||||||
|
import net.torvald.terrarum.audio.dsp.BinoPan
|
||||||
import net.torvald.terrarum.gameactors.Actor
|
import net.torvald.terrarum.gameactors.Actor
|
||||||
import net.torvald.terrarum.gameactors.ActorID
|
import net.torvald.terrarum.gameactors.ActorID
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
@@ -442,6 +444,16 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
|||||||
loadedTime_t = App.getTIME_T()
|
loadedTime_t = App.getTIME_T()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun playGUIsound(sound: MusicContainer, volume: Double = 1.0, pan: Float = 0f) {
|
||||||
|
App.audioMixer.guiTrack.let {
|
||||||
|
it.currentTrack = sound
|
||||||
|
it.maxVolumeFun= { volume }
|
||||||
|
it.volume = volume
|
||||||
|
it.playRequested.set(true)
|
||||||
|
it.getFilter<BinoPan>().pan = pan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies most recent `save` to `save.1`, leaving `save` for overwriting, previous `save.1` will be copied to `save.2`
|
* Copies most recent `save` to `save.1`, leaving `save` for overwriting, previous `save.1` will be copied to `save.2`
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -226,10 +226,12 @@ class AudioMixer : Disposable {
|
|||||||
init {
|
init {
|
||||||
// initialise audio paths //
|
// initialise audio paths //
|
||||||
|
|
||||||
listOf(musicTrack, ambientTrack1, ambientTrack2, ambientTrack3, ambientTrack4).forEach {
|
listOf(musicTrack, ambientTrack1, ambientTrack2, ambientTrack3, ambientTrack4, guiTrack).forEach {
|
||||||
it.filters[0] = Gain(1f)
|
it.filters[0] = Gain(1f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guiTrack.filters[0] = BinoPan(0f)
|
||||||
|
|
||||||
masterTrack.filters[0] = SoftClp
|
masterTrack.filters[0] = SoftClp
|
||||||
masterTrack.filters[1] = Buffer
|
masterTrack.filters[1] = Buffer
|
||||||
masterTrack.filters[2] = Vecto(1.4142f)
|
masterTrack.filters[2] = Vecto(1.4142f)
|
||||||
@@ -369,7 +371,7 @@ class AudioMixer : Disposable {
|
|||||||
it.getFilter<Gain>().gain = ambientVolume.toFloat()
|
it.getFilter<Gain>().gain = ambientVolume.toFloat()
|
||||||
}
|
}
|
||||||
sfxSumBus.volume = sfxVolume
|
sfxSumBus.volume = sfxVolume
|
||||||
guiTrack.volume = guiVolume
|
guiTrack.getFilter<Gain>().gain = guiVolume.toFloat()
|
||||||
|
|
||||||
|
|
||||||
// process fades
|
// process fades
|
||||||
|
|||||||
@@ -24,6 +24,28 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
|||||||
private var buffertaille = bufferSize
|
private var buffertaille = bufferSize
|
||||||
|
|
||||||
companion object {
|
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
|
@Volatile var running = true; private set
|
||||||
@@ -310,29 +332,6 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
|||||||
// } // uncomment to multithread
|
// } // 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.applyVolume(volume: Float) = FloatArray(this.size) { (this[it] * volume) }
|
||||||
/*private fun FloatArray.applyVolumeInline(volume: Float): FloatArray {
|
/*private fun FloatArray.applyVolumeInline(volume: Float): FloatArray {
|
||||||
for (i in this.indices) {
|
for (i in this.indices) {
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
|
import com.jme3.math.FastMath.pow
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
|
import net.torvald.terrarum.audio.MixerTrackProcessor
|
||||||
import net.torvald.terrarum.audio.MusicContainer
|
import net.torvald.terrarum.audio.MusicContainer
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
@@ -246,8 +248,14 @@ object PickaxeCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// play sound cue
|
// play sound cue
|
||||||
|
val mvec = Vector2(Terrarum.mouseX, Terrarum.mouseY)
|
||||||
|
val dist = distBetween(actor, mvec)
|
||||||
|
val relX = relativeXposition(actor, mvec)
|
||||||
|
val distFallOff = 1.3 * 128.0
|
||||||
|
val pan = 1.3 * relX / distFallOff
|
||||||
|
val vol = MixerTrackProcessor.getVolFun(dist / distFallOff).coerceAtLeast(0.0)
|
||||||
if (!tooltipWasShown && tooltipSet) {
|
if (!tooltipWasShown && tooltipSet) {
|
||||||
actor.startAudio(soundCue, 0.7) // TODO play on the GUI track
|
INGAME.playGUIsound(soundCue, 0.25 * vol, pan.toFloat())
|
||||||
}
|
}
|
||||||
|
|
||||||
true // just a placeholder
|
true // just a placeholder
|
||||||
|
|||||||
Reference in New Issue
Block a user