mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
trying to fix glitchy audio after load
This commit is contained in:
@@ -147,7 +147,7 @@ class AudioProcessBuf(val inputSamplingRate: Int, val audioReadFun: (ByteArray)
|
||||
private val readBuf = ByteArray(fetchSize * 4)
|
||||
|
||||
init {
|
||||
printdbg(this, "App.audioMixerBufferSize=${App.audioBufferSize}")
|
||||
// printdbg(this, "App.audioMixerBufferSize=${App.audioBufferSize}")
|
||||
}
|
||||
|
||||
private fun shift(array: FloatArray, size: Int) {
|
||||
|
||||
@@ -162,6 +162,8 @@ class TerrarumAudioMixerTrack(
|
||||
override fun equals(other: Any?) = this.hash == (other as TerrarumAudioMixerTrack).hash
|
||||
|
||||
fun stop() {
|
||||
printdbg(this, "Stop music (mixertrack=${this.name}, musictrack=$currentTrack)")
|
||||
|
||||
currentTrack?.reset()
|
||||
|
||||
streamPlaying.set(false)
|
||||
|
||||
@@ -161,6 +161,9 @@ abstract class Actor : Comparable<Actor>, Runnable {
|
||||
musicTracks1.add(track.name)
|
||||
track.stop()
|
||||
}
|
||||
else {
|
||||
// printdbg(this, "Could not get a free track")
|
||||
}
|
||||
}
|
||||
|
||||
// printdbg(this, "Dynamic Source ${track?.name}")
|
||||
@@ -182,9 +185,9 @@ abstract class Actor : Comparable<Actor>, Runnable {
|
||||
it.currentTrack = music
|
||||
it.maxVolumeFun = { volume }
|
||||
it.volume = volume
|
||||
doSomethingWithTrack(it)
|
||||
// it.play()
|
||||
it.playRequested.set(true)
|
||||
doSomethingWithTrack(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
* Condition for (if the tile is solid) is always implied regardless of this function. See [canSpawnHere0]
|
||||
*/
|
||||
open fun canSpawnOnThisFloor(itemID: ItemID): Boolean {
|
||||
return true
|
||||
val blockprop = BlockCodex[itemID]
|
||||
return blockprop.isSolid || blockprop.isPlatform
|
||||
}
|
||||
|
||||
fun canSpawnHere(posX0: Int, posY0: Int): Boolean {
|
||||
@@ -277,7 +278,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
val xs = posX until posX + blockBox.width
|
||||
cannotSpawn = cannotSpawn or xs.any { x ->
|
||||
world!!.getTileFromTerrain(x, y).let {
|
||||
!BlockCodex[it].isSolid || !canSpawnOnThisFloor(it)
|
||||
!canSpawnOnThisFloor(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.decibelsToFullscale
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
@@ -19,6 +20,7 @@ import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
|
||||
import net.torvald.terrarum.modulebasegame.ui.UICrafting
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unsafe.UnsafeHelper
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2023-12-05.
|
||||
@@ -81,6 +83,8 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
private var nextDelay = 0.25f
|
||||
private var spawnTimer = 0f
|
||||
|
||||
@Transient private var audioStatus = 0
|
||||
|
||||
override fun updateImpl(delta: Float) {
|
||||
super.updateImpl(delta)
|
||||
|
||||
@@ -108,17 +112,33 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
|
||||
// manage audio
|
||||
getTrackByAudio(static).let {
|
||||
if (it != null && !it.isPlaying) {
|
||||
startAudio(static) {
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
printdbg(this, "hasbuf=${it?.processor?.streamBuf}, playing=${it?.isPlaying}, playRequested=${it?.playRequested}")
|
||||
|
||||
if (it != null) {
|
||||
|
||||
if (audioStatus == 0) {
|
||||
startAudio(static) {
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
audioStatus = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getTrackByAudio(static)?.let {
|
||||
if (it.filters[filterIndex] !is Gain) // just in case...
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
else {
|
||||
// printdbg(this, "Track is null! (old audio status=$audioStatus")
|
||||
audioStatus = 0
|
||||
}
|
||||
|
||||
(it.filters[filterIndex] as Gain).gain = 0.4f * volRand.get()
|
||||
if (it != null) {
|
||||
if (it.processor.streamBuf != null || it.playRequested.get()) {
|
||||
if (it.filters[filterIndex] !is Gain) // just in case...
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
|
||||
(it.filters[filterIndex] as Gain).gain = 0.4f * volRand.get()
|
||||
}
|
||||
else {
|
||||
audioStatus = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
|
||||
// manage audio
|
||||
getTrackByAudio(static).let {
|
||||
if (it == null || (temperature > 0f && !it.isPlaying)) {
|
||||
if (it == null || (temperature > 0f && !it.isPlaying && !it.playRequested.get())) {
|
||||
startAudio(static) {
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
}
|
||||
@@ -300,12 +300,13 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
it.filters[filterIndex] = NullFilter
|
||||
}
|
||||
}
|
||||
}
|
||||
getTrackByAudio(static)?.let {
|
||||
if (it.filters[filterIndex] !is Gain) // just in case...
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
|
||||
(it.filters[filterIndex] as Gain).gain = (it.maxVolume * temperature * volRand.get()).toFloat()
|
||||
if (it != null) {
|
||||
if (it.filters[filterIndex] !is Gain) // just in case...
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
|
||||
(it.filters[filterIndex] as Gain).gain = (it.maxVolume * temperature * volRand.get()).toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user