slightly improved audio processing performance by giving some time to the CPU

This commit is contained in:
minjaesong
2024-02-19 16:07:34 +09:00
parent d24ec8296f
commit 11a7a1f48d
2 changed files with 9 additions and 1 deletions

View File

@@ -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...

View File

@@ -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) {