fix: explosion cuts off randomly

This commit is contained in:
minjaesong
2024-02-17 00:30:04 +09:00
parent ffd470f2b4
commit 9caf9ab2fa
12 changed files with 110 additions and 41 deletions

View File

@@ -453,9 +453,9 @@ class AudioMixer : Disposable {
}
fun startAmb(song: MusicContainer) {
val ambientTrack = if (!ambientTrack1.streamPlaying)
val ambientTrack = if (!ambientTrack1.streamPlaying.get())
ambientTrack1
else if (!ambientTrack2.streamPlaying)
else if (!ambientTrack2.streamPlaying.get())
ambientTrack2
else if (ambientTrack1.playStartedTime < ambientTrack2.playStartedTime)
ambientTrack1

View File

@@ -181,8 +181,15 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
// fetch deviceBufferSize amount of sample from the disk
if (track.trackType != TrackType.MASTER && track.trackType != TrackType.BUS && track.streamPlaying) {
if (streamBuf == null && track.currentTrack != null) allocateStreamBuf(track)
if (track.playRequested.get()) {
track.play()
}
if (track.trackType != TrackType.MASTER && track.trackType != TrackType.BUS && track.streamPlaying.get()) {
if (streamBuf == null && track.currentTrack != null) {
allocateStreamBuf(track)
}
streamBuf!!.fetchBytes()
}
@@ -208,7 +215,7 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
}
// source channel: skip processing if there's no active input
// else if (track.getSidechains().any { it != null && !it.isBus && !it.isMaster && !it.streamPlaying } && !track.streamPlaying) {
else if (!track.streamPlaying || streamBuf == null || streamBuf!!.validSamplesInBuf < App.audioBufferSize) {
else if (!track.streamPlaying.get() || streamBuf == null || streamBuf!!.validSamplesInBuf < App.audioBufferSize) {
samplesL1 = emptyBuf
samplesR1 = emptyBuf

View File

@@ -41,13 +41,13 @@ data class MusicContainer(
is Wav.Music -> {
val rate = gdxMusic.extortField<Wav.WavInputStream>("input")!!.sampleRate
App.printdbg(this, "music $name is WAV; rate = $rate")
// App.printdbg(this, "music $name is WAV; rate = $rate")
rate
}
is Ogg.Music -> {
val rate = gdxMusic.extortField<OggInputStream>("input")!!.sampleRate
App.printdbg(this, "music $name is OGG; rate = $rate")
// App.printdbg(this, "music $name is OGG; rate = $rate")
rate
}
is Mp3.Music -> {
@@ -62,11 +62,11 @@ data class MusicContainer(
// val rate = header.sampleRate
// gdxMusic.reset()
App.printdbg(this, "music $name is MP3; rate = $rate")
// App.printdbg(this, "music $name is MP3; rate = $rate")
rate
}
else -> {
App.printdbg(this, "music $name is ${gdxMusic::class.qualifiedName}; rate = default")
// App.printdbg(this, "music $name is ${gdxMusic::class.qualifiedName}; rate = default")
TerrarumAudioMixerTrack.SAMPLING_RATE
}
}

View File

@@ -5,11 +5,14 @@ import com.badlogic.gdx.backends.lwjgl3.audio.OpenALLwjgl3Audio
import com.badlogic.gdx.utils.Disposable
import com.badlogic.gdx.utils.Queue
import net.torvald.terrarum.App
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.audio.dsp.NullFilter
import net.torvald.terrarum.audio.dsp.TerrarumAudioFilter
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.getHashStr
import net.torvald.terrarum.hashStrMap
import net.torvald.terrarum.printStackTrace
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.math.log10
import kotlin.math.pow
@@ -60,7 +63,7 @@ class TerrarumAudioMixerTrack(
var trackingTarget: Actor? = null
internal var streamPlaying = false
internal val streamPlaying = AtomicBoolean(false)
var playStartedTime = 0L; internal set
@@ -70,7 +73,7 @@ class TerrarumAudioMixerTrack(
other.nextTrack = this.nextTrack
other.volume = this.volume
other.trackingTarget = this.trackingTarget
other.streamPlaying = this.streamPlaying
other.streamPlaying.set(this.streamPlaying.get())
other.playStartedTime = this.playStartedTime
filters.indices.forEach { i ->
other.filters[i].copyParamsFrom(this.filters[i])
@@ -133,15 +136,18 @@ class TerrarumAudioMixerTrack(
nextTrack = nextNext
}
val playRequested = AtomicBoolean(false)
fun play() {
playStartedTime = System.nanoTime()
streamPlaying = true
streamPlaying.set(true)
playRequested.set(false)
// currentTrack?.gdxMusic?.play()
}
val isPlaying: Boolean
get() = streamPlaying//currentTrack?.gdxMusic?.isPlaying
get() = streamPlaying.get()//currentTrack?.gdxMusic?.isPlaying
override fun dispose() {
/*if (isMaster) { // uncomment to multithread
@@ -158,7 +164,7 @@ class TerrarumAudioMixerTrack(
fun stop() {
currentTrack?.reset()
streamPlaying = false
streamPlaying.set(false)
// playStartedTime = 0L
if (trackingTarget != null && currentTrack != null) {