mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-19 23:14:05 +09:00
audio engine: resize buffer without restarting the game
This commit is contained in:
@@ -498,35 +498,6 @@ class AudioMixer(val bufferSize: Int): Disposable {
|
||||
}, 500L)
|
||||
}
|
||||
|
||||
fun updateBufferSizeChange() {
|
||||
processing = false
|
||||
processingThread.interrupt()
|
||||
|
||||
|
||||
|
||||
dynamicTracks.forEach { it.stop() }
|
||||
tracks.filter { it.trackType == TrackType.STATIC_SOURCE }.forEach { it.stop() }
|
||||
masterTrack.volume = 0.0
|
||||
|
||||
dynamicTracks.forEach { it.updateBufferSizeChange() }
|
||||
tracks.forEach { it.updateBufferSizeChange() }
|
||||
masterTrack.updateBufferSizeChange()
|
||||
|
||||
|
||||
|
||||
processingThread = createProcessingThread()
|
||||
processing = true
|
||||
processingThread.start()
|
||||
|
||||
|
||||
// give some time for the cave bus to decay before ramping the volume up
|
||||
Timer().schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
masterTrack.volume = 1.0
|
||||
}
|
||||
}, 500L)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
processingExecutor.killAll()
|
||||
// processingSubthreads.forEach { it.interrupt() }
|
||||
|
||||
@@ -21,15 +21,6 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
||||
|
||||
private var buffertaille = bufferSize
|
||||
|
||||
fun reset(newBufferSize: Int) {
|
||||
buffertaille = newBufferSize
|
||||
// printdbg("new buffertaille = $buffertaille")
|
||||
emptyBuf = FloatArray(buffertaille)
|
||||
fout1 = listOf(emptyBuf, emptyBuf)
|
||||
purgeStreamBuf()
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
}
|
||||
|
||||
@@ -178,13 +169,7 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
||||
// add all up
|
||||
sidechains.forEach { (side, mix) ->
|
||||
for (i in samplesL1.indices) {
|
||||
// try {
|
||||
samplesL1[i] += side.processor.fout1[0][i] * (mix * track.volume).toFloat()
|
||||
// }
|
||||
// catch (e: ArrayIndexOutOfBoundsException) {
|
||||
// printdbg("buffertaille = $buffertaille, samplesL1 size = ${samplesL1.size}, side.processor.fout1[0] size = ${side.processor.fout1[0].size}")
|
||||
// throw e
|
||||
// }
|
||||
samplesL1[i] += side.processor.fout1[0][i] * (mix * track.volume).toFloat()
|
||||
samplesR1[i] += side.processor.fout1[1][i] * (mix * track.volume).toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,16 +187,6 @@ class TerrarumAudioMixerTrack(
|
||||
}*/
|
||||
}
|
||||
|
||||
fun updateBufferSizeChange() {
|
||||
// printdbg(this, "new buffer size: $App.audioMixerBufferSize")
|
||||
pcmQueue.clear()
|
||||
pcmQueue.addLast(listOf(FloatArray(App.audioBufferSize), FloatArray(App.audioBufferSize)))
|
||||
pcmQueue.addLast(listOf(FloatArray(App.audioBufferSize), FloatArray(App.audioBufferSize)))
|
||||
processor.reset(App.audioBufferSize)
|
||||
filters.forEach { it.reset() }
|
||||
}
|
||||
|
||||
|
||||
override fun hashCode() = hashCode0
|
||||
}
|
||||
|
||||
|
||||
@@ -55,13 +55,6 @@ class BinoPan(var pan: Float, var earDist: Float = EARDIST_DEFAULT): TerrarumAud
|
||||
private val HALF_PI = (Math.PI / 2.0).toFloat()
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
outLs = Array(2) { FloatArray(App.audioBufferSize) }
|
||||
outRs = Array(2) { FloatArray(App.audioBufferSize) }
|
||||
delayLineL.fill(0f)
|
||||
delayLineR.fill(0f)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intensity -inf to +inf
|
||||
*/
|
||||
|
||||
@@ -34,8 +34,5 @@ class Bitcrush(var steps: Int, var inputGain: Float = 1f): TerrarumAudioFilter()
|
||||
App.fontSmallNumbers.draw(batch, "B:$bits", x+3f, y+1f)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 16
|
||||
}
|
||||
@@ -18,8 +18,5 @@ object Buffer : TerrarumAudioFilter() {
|
||||
App.fontSmallNumbers.draw(batch, "Bs:${App.audioBufferSize}", x+3f, y+1f)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 16
|
||||
}
|
||||
@@ -74,12 +74,6 @@ class Convolv(ir: File, val crossfeed: Float, gain: Float = 1f / 256f): Terrarum
|
||||
private val fftOutL = FloatArray(fftLen)
|
||||
private val fftOutR = FloatArray(fftLen)
|
||||
|
||||
override fun reset() {
|
||||
realtime = (App.audioBufferSize / TerrarumAudioMixerTrack.SAMPLING_RATEF * 1000000000L)
|
||||
processingSpeed = 1f
|
||||
sumbuf.forEach { it.reim.fill(0f) }
|
||||
}
|
||||
|
||||
private fun convolve(x: ComplexArray, h: ComplexArray, output: FloatArray) {
|
||||
FFT.fftInto(x, fftIn)
|
||||
fftIn.mult(h, fftMult)
|
||||
|
||||
@@ -19,9 +19,5 @@ class Gain(var gain: Float): TerrarumAudioFilter() {
|
||||
App.fontSmallNumbers.draw(batch, "G:${fullscaleToDecibels(gain.toDouble()).times(100).roundToInt().div(100f)}", x+3f, y+1f)
|
||||
}
|
||||
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 16
|
||||
}
|
||||
@@ -67,9 +67,4 @@ class Highpass(cutoff0: Float): TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 16
|
||||
|
||||
override fun reset() {
|
||||
in0.fill(0f)
|
||||
out0.fill(0f)
|
||||
}
|
||||
}
|
||||
@@ -67,9 +67,4 @@ class Lowpass(cutoff0: Float): TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 16
|
||||
|
||||
override fun reset() {
|
||||
in0.fill(0f)
|
||||
out0.fill(0f)
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,4 @@ object NullFilter : TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 0
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
}
|
||||
@@ -53,8 +53,4 @@ class Reverb(val delayMS: Float = 36f, var feedback: Float = 0.92f, var lowpass:
|
||||
}
|
||||
|
||||
override val debugViewHeight = 0
|
||||
|
||||
override fun reset() {
|
||||
buf.forEach { it.fill(0f) }
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,4 @@ object SoftClp : TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 0
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,6 @@ class Spectro(val gain: Float = 1f) : TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = STRIP_W
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -157,13 +154,4 @@ class Vecto(val gain: Float = 1f) : TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = STRIP_W
|
||||
|
||||
override fun reset() {
|
||||
backbufL = Array((6144f / App.audioBufferSize).roundToInt().coerceAtLeast(1)) {
|
||||
FloatArray(App.audioBufferSize)
|
||||
}
|
||||
backbufR = Array((6144f / App.audioBufferSize).roundToInt().coerceAtLeast(1)) {
|
||||
FloatArray(App.audioBufferSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ abstract class TerrarumAudioFilter {
|
||||
}
|
||||
else thru(inbuf, outbuf)
|
||||
}
|
||||
abstract fun reset()
|
||||
abstract fun drawDebugView(batch: SpriteBatch, x: Int, y: Int)
|
||||
abstract val debugViewHeight: Int
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ object XYtoMS: TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 0
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
}
|
||||
|
||||
object MStoXY: TerrarumAudioFilter() {
|
||||
@@ -40,7 +37,4 @@ object MStoXY: TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
override val debugViewHeight = 0
|
||||
|
||||
override fun reset() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user