mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
ambient audio stuffs
This commit is contained in:
BIN
assets/mods/basegame/audio/ambient/autumn1.ogg
LFS
Normal file
BIN
assets/mods/basegame/audio/ambient/autumn1.ogg
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/audio/ambient/summer1.ogg
LFS
Normal file
BIN
assets/mods/basegame/audio/ambient/summer1.ogg
LFS
Normal file
Binary file not shown.
BIN
assets/mods/basegame/audio/ambient/winter1.ogg
LFS
Normal file
BIN
assets/mods/basegame/audio/ambient/winter1.ogg
LFS
Normal file
Binary file not shown.
@@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.Disposable
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.spriteanimation.AssembledSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATE
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATED
|
||||
import net.torvald.terrarum.audio.dsp.*
|
||||
@@ -205,8 +206,9 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
|
||||
musicTrack.filters[1] = Vecto()
|
||||
musicTrack.filters[2] = Spectro()
|
||||
ambientTrack.filters[1] = Vecto()
|
||||
ambientTrack.filters[1] = Vecto(decibelsToFullscale(24.0).toFloat())
|
||||
ambientTrack.filters[2] = Spectro()
|
||||
ambientTrack.filters[3] = Gain(1f)
|
||||
sfxSumBus.filters[1] = Vecto(0.7071f)
|
||||
sfxSumBus.filters[2] = Spectro()
|
||||
|
||||
@@ -232,7 +234,6 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
masterTrack.addSidechainInput(fadeBus, 1.0)
|
||||
masterTrack.addSidechainInput(guiTrack, 1.0)
|
||||
|
||||
musicTrack.filters[3] = Gain(0.5f)
|
||||
|
||||
dynamicTracks.forEach {
|
||||
it.filters[0] = BinoPan(0f)
|
||||
@@ -333,8 +334,8 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
// the real updates
|
||||
(Gdx.audio as? Lwjgl3Audio)?.update()
|
||||
masterTrack.volume = masterVolume
|
||||
musicTrack.getFilter<Gain>().gain = musicVolume.toFloat()
|
||||
ambientTrack.getFilter<Gain>().gain = ambientVolume.toFloat()
|
||||
musicTrack.getFilter<Gain>().gain = musicVolume.toFloat() * 0.5f
|
||||
ambientTrack.getFilter<Gain>().gain = ambientVolume.toFloat() * 2
|
||||
sfxSumBus.getFilter<Gain>().gain = sfxVolume.toFloat()
|
||||
guiTrack.getFilter<Gain>().gain = guiVolume.toFloat()
|
||||
|
||||
@@ -409,12 +410,17 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
|
||||
if (!ambientTrack.isPlaying && ambientTrack.nextTrack != null) {
|
||||
ambientTrack.queueNext(null)
|
||||
requestFadeIn(ambientTrack, DEFAULT_FADEOUT_LEN * 4, 1.0, 0.00001)
|
||||
if (ambientStopped) {
|
||||
requestFadeIn(ambientTrack, DEFAULT_FADEOUT_LEN * 4, 1.0, 0.00001)
|
||||
}
|
||||
ambientTrack.volume = 1.0
|
||||
ambientTrack.play()
|
||||
ambientStopped = false
|
||||
}
|
||||
}
|
||||
|
||||
private var ambientStopped = true
|
||||
|
||||
fun startMusic(song: MusicContainer) {
|
||||
if (musicTrack.isPlaying) {
|
||||
requestFadeOut(musicTrack, DEFAULT_FADEOUT_LEN)
|
||||
@@ -451,6 +457,9 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
}
|
||||
|
||||
fun requestFadeIn(track: TerrarumAudioMixerTrack, length: Double, target: Double = 1.0, source: Double? = null, jobAfterFadeout: () -> Unit = {}) {
|
||||
printdbg(this, "fadein called by")
|
||||
printStackTrace(this)
|
||||
|
||||
val req = fadeReqs[track]!!
|
||||
if (!req.fadeinFired) {
|
||||
req.fadeLength = length.coerceAtLeast(1.0/1024.0)
|
||||
@@ -484,6 +493,7 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
ambientStopped = true
|
||||
dynamicTracks.forEach { it.stop() }
|
||||
tracks.filter { it.trackType == TrackType.STATIC_SOURCE }.forEach { it.stop() }
|
||||
tracks.forEach {
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.Terrarum.getPlayerSaveFiledesc
|
||||
import net.torvald.terrarum.Terrarum.getWorldSaveFiledesc
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||
import net.torvald.terrarum.blockstats.TileSurvey
|
||||
@@ -312,6 +313,16 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
MaterialCodex[prop.material].sondrefl
|
||||
}
|
||||
)
|
||||
|
||||
TileSurvey.submitProposal(
|
||||
TileSurvey.SurveyProposal(
|
||||
"basegame.Ingame.openness", 73, 73, 2, 4
|
||||
) { world, x, y ->
|
||||
val tileProp = BlockCodex[world.getTileFromTerrain(x, y)]
|
||||
val wallProp = BlockCodex[world.getTileFromWall(x, y)]
|
||||
(!tileProp.isSolid && !wallProp.isSolid).toInt().toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
data class NewGameParams(
|
||||
@@ -904,6 +915,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
App.audioMixer.convolveBusOpen.volume = (1.0 - ratio1).pow(0.75)
|
||||
App.audioMixer.convolveBusCave.volume = 0.0
|
||||
}
|
||||
val openness = (TileSurvey.getRatio("basegame.Ingame.openness") ?: 0.0).times(1.74).coerceIn(0.0, 1.0)
|
||||
(App.audioMixer.ambientTrack.filters[3] as Gain).gain = openness.pow(2.0 / 3.0).toFloat()
|
||||
|
||||
|
||||
|
||||
actorNowPlaying?.let { if (WORLD_UPDATE_TIMER % 4 == 1) updateWorldGenerator(actorNowPlaying!!) }
|
||||
|
||||
|
||||
@@ -269,22 +269,22 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
}
|
||||
|
||||
private val ambients: List<MusicContainer> =
|
||||
File(App.customAmbientDir).listFiles()?.mapNotNull {
|
||||
ModMgr.getFilesFromEveryMod("audio/ambient/").flatMap { it.second.listFiles()?.toList() ?: emptyList() }.mapNotNull {
|
||||
printdbg(this, "Ambient: ${it.absolutePath}")
|
||||
try {
|
||||
MusicContainer(
|
||||
it.nameWithoutExtension.replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" "),
|
||||
it,
|
||||
Gdx.audio.newMusic(Gdx.files.absolute(it.absolutePath))
|
||||
Gdx.audio.newMusic(Gdx.files.absolute(it.absolutePath)).also {
|
||||
it.isLooping = true
|
||||
}
|
||||
) { stopAmbient() }
|
||||
}
|
||||
catch (e: GdxRuntimeException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
} ?: emptyList() // TODO test code
|
||||
|
||||
private var ambientsBin: ArrayList<Int> = ArrayList(ambients.indices.toList().shuffled())
|
||||
}
|
||||
|
||||
private val musicStartHooks = ArrayList<(MusicContainer) -> Unit>()
|
||||
private val musicStopHooks = ArrayList<(MusicContainer) -> Unit>()
|
||||
@@ -367,30 +367,19 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
}
|
||||
}
|
||||
|
||||
// MixerTrackProcessor will call this function externally to make gapless playback work
|
||||
fun pullNextAmbientTrack(): MusicContainer {
|
||||
// prevent same song to play twice in row (for the most time)
|
||||
if (ambientsBin.isEmpty()) {
|
||||
ambientsBin = ArrayList(ambients.indices.toList().shuffled())
|
||||
}
|
||||
return ambients[ambientsBin.removeAt(0)]
|
||||
}
|
||||
|
||||
private fun stopAmbient() {
|
||||
ambState = STATE_INTERMISSION
|
||||
intermissionAkku = 0f
|
||||
intermissionLength = 30f + 30f * Math.random().toFloat() // 30s-60s
|
||||
ambFired = false
|
||||
printdbg(this, "stopAmbient Intermission: $intermissionLength seconds")
|
||||
App.audioMixer.ambientTrack.nextTrack = currentAmbientTrack
|
||||
}
|
||||
|
||||
private fun startAmbient(song: MusicContainer) {
|
||||
currentAmbientTrack = song
|
||||
App.audioMixer.startAmb(song)
|
||||
printdbg(this, "startAmbient Now playing: $song")
|
||||
// INGAME.sendNotification("Now Playing $EMDASH ${song.name}")
|
||||
ambState = STATE_PLAYING
|
||||
}
|
||||
|
||||
private lateinit var currentAmbientTrack: MusicContainer
|
||||
|
||||
override fun update(ingame: IngameInstance, delta: Float) {
|
||||
// start the song queueing if there is one to play
|
||||
@@ -422,7 +411,17 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
STATE_FIREPLAY -> {
|
||||
if (!ambFired) {
|
||||
ambFired = true
|
||||
startAmbient(pullNextAmbientTrack())
|
||||
|
||||
val season = ingame.world.worldTime.ecologicalSeason
|
||||
val seasonName = when (season) {
|
||||
in 0f..2f -> "autumn"
|
||||
in 2f..3f -> "summer"
|
||||
in 3f..5f -> "autumn"
|
||||
else -> "winter"
|
||||
}
|
||||
val track = ambients.filter { it.name.lowercase().startsWith(seasonName) }.random()
|
||||
|
||||
startAmbient(track)
|
||||
}
|
||||
}
|
||||
STATE_PLAYING -> {
|
||||
|
||||
@@ -266,6 +266,11 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
App.bogoflops = maxOf(App.bogoflops, bogoflops)
|
||||
|
||||
|
||||
App.audioMixer.ambientTrack.let {
|
||||
it.stop()
|
||||
it.currentTrack = null
|
||||
it.nextTrack = null
|
||||
}
|
||||
App.audioMixer.reset()
|
||||
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
private val stripGap = 1
|
||||
private val stripFilterHeight = 16
|
||||
private val stripFaderHeight = meterHeight + 20
|
||||
private val numberOfFilters = 14
|
||||
private val numberOfFilters = 16
|
||||
private val stripH = stripFaderHeight + stripFilterHeight * numberOfFilters + 16
|
||||
|
||||
private val trackBack = listOf(COL_WELL, COL_WELL2)
|
||||
|
||||
Reference in New Issue
Block a user