mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
audio mixer reset() with audio artefact masking
This commit is contained in:
@@ -463,6 +463,20 @@ object AudioMixer: Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
dynamicTracks.forEach { it.stop() }
|
||||
tracks.filter { it.trackType == TrackType.STATIC_SOURCE }.forEach { it.stop() }
|
||||
tracks.forEach {
|
||||
it.processor.purgeBuffer()
|
||||
}
|
||||
fadeBus.getFilter<Lowpass>().setCutoff(TerrarumAudioMixerTrack.SAMPLING_RATEF / 2)
|
||||
// give some time for the cave bus to decay before ramping the volume up
|
||||
Timer().schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
fadeBus.volume = 1.0
|
||||
}
|
||||
}, 500L)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
processingExecutor.killAll()
|
||||
|
||||
@@ -39,6 +39,17 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
|
||||
val maxRMS = arrayOf(0.0, 0.0)
|
||||
val hasClipping = arrayOf(false, false)
|
||||
|
||||
internal fun purgeBuffer() {
|
||||
fout1.forEach { it.fill(0f) }
|
||||
purgeStreamBuf()
|
||||
}
|
||||
|
||||
private fun purgeStreamBuf() {
|
||||
track.stop()
|
||||
streamBuf = null
|
||||
printdbg("StreamBuf is now null")
|
||||
}
|
||||
|
||||
private var breakBomb = false
|
||||
|
||||
private val distFalloff = 1600.0
|
||||
@@ -70,11 +81,7 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
|
||||
}
|
||||
|
||||
bytesRead
|
||||
}, {
|
||||
track.stop()
|
||||
this.streamBuf = null
|
||||
printdbg("StreamBuf is now null")
|
||||
})
|
||||
}, { purgeStreamBuf() })
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
@@ -111,6 +118,7 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
|
||||
if (track.trackType == TrackType.DYNAMIC_SOURCE && track.isPlaying) {
|
||||
if (AudioMixer.actorNowPlaying != null) {
|
||||
if (track.trackingTarget == null || track.trackingTarget == AudioMixer.actorNowPlaying) {
|
||||
// "reset" the track
|
||||
track.volume = track.maxVolume
|
||||
(track.filters[0] as BinoPan).pan = 0f
|
||||
(track.filters[1] as Lowpass).setCutoff(SAMPLING_RATE / 2f)
|
||||
@@ -131,6 +139,12 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
|
||||
// printdbg("dist=$distFromActor\tvol=${fullscaleToDecibels(vol)}\tcutoff=${(track.filters[1] as Lowpass).cutoff}")
|
||||
}
|
||||
}
|
||||
else {
|
||||
// "reset" the track
|
||||
track.volume = track.maxVolume
|
||||
(track.filters[0] as BinoPan).pan = 0f
|
||||
(track.filters[1] as Lowpass).setCutoff(SAMPLING_RATE / 2f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ class TerrarumAudioMixerTrack(
|
||||
var currentTrack: MusicContainer? = null
|
||||
var nextTrack: MusicContainer? = null
|
||||
|
||||
var currentSound: Sound? = null // DYNAMIC_SOURCE only
|
||||
|
||||
var volume: TrackVolume = 1.0
|
||||
get() = field
|
||||
set(value) {
|
||||
|
||||
@@ -300,7 +300,7 @@ class BuildingMaker(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
override fun show() {
|
||||
Gdx.input.inputProcessor = BuildingMakerController(this)
|
||||
AudioMixer.fadeBus.getFilter<Lowpass>().setCutoff(TerrarumAudioMixerTrack.SAMPLING_RATEF / 2)
|
||||
AudioMixer.reset()
|
||||
super.show()
|
||||
}
|
||||
|
||||
|
||||
@@ -298,8 +298,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
IngameRenderer.setRenderedWorld(world)
|
||||
blockMarkingActor.isVisible = true
|
||||
|
||||
AudioMixer.fadeBus.getFilter<Lowpass>().setCutoff(SAMPLING_RATEF / 2)
|
||||
|
||||
AudioMixer.reset()
|
||||
|
||||
super.show() // this function sets gameInitialised = true
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
App.bogoflops = maxOf(App.bogoflops, bogoflops)
|
||||
|
||||
|
||||
AudioMixer.fadeBus.getFilter<Lowpass>().setCutoff(TerrarumAudioMixerTrack.SAMPLING_RATEF / 2)
|
||||
AudioMixer.reset()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.INGAME
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
@@ -73,6 +74,8 @@ class FixtureJukebox : Electric {
|
||||
|
||||
|
||||
private fun playDisc(index: Int) {
|
||||
printdbg(this, "Play disc $index!")
|
||||
|
||||
musicNowPlaying = testMusic // todo use index
|
||||
|
||||
AudioMixer.requestFadeOut(AudioMixer.musicTrack, DEFAULT_FADEOUT_LEN / 2f) {
|
||||
@@ -80,8 +83,14 @@ class FixtureJukebox : Electric {
|
||||
}
|
||||
}
|
||||
|
||||
private fun forceStop() {
|
||||
musicNowPlaying?.let {
|
||||
stopAudio(it)
|
||||
}
|
||||
}
|
||||
|
||||
@Transient override var despawnHook: (FixtureBase) -> Unit = {
|
||||
musicNowPlaying?.let { stopAudio(it) }
|
||||
forceStop()
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(pauseLen = Math.random().toFloat() * 30f + 30f)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user