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