mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
slightly improved audio processing performance by giving some time to the CPU
This commit is contained in:
@@ -144,6 +144,10 @@ class AudioMixer : Disposable {
|
||||
return (headSize0 ?: 0f).times(scale).coerceAtLeast(BinoPan.EARDIST_DEFAULT)
|
||||
}
|
||||
|
||||
private val millisecUnitTime = 400L // 384 * p, p is multiplied to compensate the time takes for writing samples
|
||||
private val sleepMS = App.audioBufferSize / millisecUnitTime
|
||||
private val sleepNS = (App.audioBufferSize / millisecUnitTime * 1000000).toInt() % 1000000
|
||||
|
||||
fun createProcessingThread(): Thread = Thread {
|
||||
// serial precessing
|
||||
while (processing) {
|
||||
@@ -168,6 +172,8 @@ class AudioMixer : Disposable {
|
||||
while (processing && !masterTrack.pcmQueue.isEmpty) {
|
||||
masterTrack.adev!!.writeSamples(masterTrack.pcmQueue.removeFirst()) // it blocks until the queue is consumed
|
||||
}
|
||||
|
||||
Thread.sleep(sleepMS, sleepNS)
|
||||
}
|
||||
|
||||
// parallel processing, it seems even on the 7950X this is less efficient than serial processing...
|
||||
|
||||
@@ -103,6 +103,8 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
||||
return newRead
|
||||
}
|
||||
|
||||
var bufEmpty = true; private set
|
||||
|
||||
override fun run() {
|
||||
// while (running) { // uncomment to multithread
|
||||
/*synchronized(pauseLock) { // uncomment to multithread
|
||||
@@ -196,7 +198,7 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
||||
var samplesL1: FloatArray
|
||||
var samplesR1: FloatArray
|
||||
|
||||
var bufEmpty = false
|
||||
bufEmpty = false
|
||||
|
||||
// get samples and apply the fader
|
||||
if (track.trackType == TrackType.MASTER || track.trackType == TrackType.BUS) {
|
||||
|
||||
Reference in New Issue
Block a user