mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
parallelised audio processing
This commit is contained in:
@@ -9,10 +9,12 @@ import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATE
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATED
|
||||
import net.torvald.terrarum.concurrent.ThreadExecutor
|
||||
import net.torvald.terrarum.modulebasegame.MusicContainer
|
||||
import net.torvald.terrarum.tryDispose
|
||||
import java.lang.Thread.MAX_PRIORITY
|
||||
import java.util.*
|
||||
import java.util.concurrent.Callable
|
||||
import kotlin.math.*
|
||||
|
||||
/**
|
||||
@@ -86,8 +88,9 @@ object AudioMixer: Disposable {
|
||||
|
||||
var processing = true
|
||||
|
||||
private val processingExecutor = ThreadExecutor()
|
||||
val processingThread = Thread {
|
||||
while (processing) {
|
||||
/*while (processing) {
|
||||
// process
|
||||
tracks.forEach {
|
||||
if (!it.processor.paused) {
|
||||
@@ -100,12 +103,32 @@ object AudioMixer: Disposable {
|
||||
Thread.sleep(1)
|
||||
}*/
|
||||
|
||||
while (!masterTrack.pcmQueue.isEmpty) {
|
||||
masterTrack.adev!!.writeSamples(masterTrack.pcmQueue.removeFirst()) // it blocks until the queue is consumed
|
||||
}
|
||||
}*/
|
||||
|
||||
while (processing) {
|
||||
parallelProcessingSchedule.forEach { tracks ->
|
||||
val callables = tracks.map { Callable {
|
||||
if (!it.processor.paused) {
|
||||
it.processor.run()
|
||||
}
|
||||
} }
|
||||
|
||||
processingExecutor.renew()
|
||||
processingExecutor.submitAll(callables)
|
||||
processingExecutor.join()
|
||||
}
|
||||
|
||||
while (!masterTrack.pcmQueue.isEmpty) {
|
||||
masterTrack.adev!!.writeSamples(masterTrack.pcmQueue.removeFirst()) // it blocks until the queue is consumed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val parallelProcessingSchedule: Array<Array<TerrarumAudioMixerTrack>>
|
||||
|
||||
// val feeder = FeedSamplesToAdev(BUFFER_SIZE, SAMPLING_RATE, masterTrack)
|
||||
// val feedingThread = Thread(feeder)
|
||||
|
||||
@@ -149,6 +172,14 @@ object AudioMixer: Disposable {
|
||||
masterTrack.addSidechainInput(guiTrack, 1.0)
|
||||
|
||||
|
||||
parallelProcessingSchedule = arrayOf(
|
||||
arrayOf(musicTrack, ambientTrack, sfxMixTrack, guiTrack),
|
||||
arrayOf(sumBus, convolveBusOpen, convolveBusCave),
|
||||
arrayOf(fadeBus),
|
||||
arrayOf(masterTrack)
|
||||
)
|
||||
|
||||
|
||||
processingThread.priority = MAX_PRIORITY // higher = more predictable; audio delay is very noticeable so it gets high priority
|
||||
processingThread.start()
|
||||
// feedingThread.priority = MAX_PRIORITY
|
||||
|
||||
@@ -312,7 +312,7 @@ class Reverb(val delayMS: Float = 36f, var feedback: Float = 0.92f, var lowpass:
|
||||
|
||||
class Convolv(ir: File, val gain: Float = 1f / 256f): TerrarumAudioFilter() {
|
||||
|
||||
private val fftLen: Int
|
||||
val fftLen: Int
|
||||
private val convFFT: Array<ComplexArray>
|
||||
// private val convFFTpartd: Array<Array<ComplexArray>> // index: Channel, partition, frequencies
|
||||
private val inbuf: Array<FloatArray>
|
||||
|
||||
@@ -20,7 +20,7 @@ class TerrarumAudioMixerTrack(val name: String, val isMaster: Boolean = false, v
|
||||
const val SAMPLING_RATE = 48000
|
||||
const val SAMPLING_RATEF = 48000f
|
||||
const val SAMPLING_RATED = 48000.0
|
||||
const val BUFFER_SIZE = 512*4 // n ms -> 384 * n
|
||||
const val BUFFER_SIZE = 256*4 // n ms -> 384 * n
|
||||
}
|
||||
|
||||
val hash = getHashStr()
|
||||
|
||||
Reference in New Issue
Block a user