mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 12:34:05 +09:00
trying to fix the crackling sound issue
This commit is contained in:
@@ -105,7 +105,7 @@ object AudioMixer: Disposable {
|
|||||||
// musicTrack.filters[0] = BinoPan((Math.random() * 2.0 - 1.0).toFloat())
|
// musicTrack.filters[0] = BinoPan((Math.random() * 2.0 - 1.0).toFloat())
|
||||||
// musicTrack.filters[1] = Reverb(36f, 0.92f, 1200f)
|
// musicTrack.filters[1] = Reverb(36f, 0.92f, 1200f)
|
||||||
|
|
||||||
masterTrack.filters[0] = SoftClp
|
// masterTrack.filters[0] = SoftClp
|
||||||
masterTrack.filters[1] = Buffer
|
masterTrack.filters[1] = Buffer
|
||||||
masterTrack.filters[2] = Scope()
|
masterTrack.filters[2] = Scope()
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ object AudioMixer: Disposable {
|
|||||||
fadeBus.addSidechainInput(ambientTrack, 1.0)
|
fadeBus.addSidechainInput(ambientTrack, 1.0)
|
||||||
fadeBus.addSidechainInput(sfxMixTrack, 1.0)
|
fadeBus.addSidechainInput(sfxMixTrack, 1.0)
|
||||||
fadeBus.filters[0] = Lowpass(SAMPLING_RATE / 2f)
|
fadeBus.filters[0] = Lowpass(SAMPLING_RATE / 2f)
|
||||||
fadeBus.filters[1] = Convolv(ModMgr.getFile("basegame", "audio/convolution/EchoThief - TransitCenter.bin"))
|
fadeBus.filters[1] = Convolv(ModMgr.getFile("basegame", "audio/convolution/WoodruffLane.bin"))
|
||||||
|
|
||||||
masterTrack.addSidechainInput(fadeBus, 1.0)
|
masterTrack.addSidechainInput(fadeBus, 1.0)
|
||||||
masterTrack.addSidechainInput(guiTrack, 1.0)
|
masterTrack.addSidechainInput(guiTrack, 1.0)
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ object SoftClp : TerrarumAudioFilter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Scope : TerrarumAudioFilter() {
|
class Scope : TerrarumAudioFilter() {
|
||||||
val backbufL = Array(BUFFER_SIZE / 16) { FloatArray(BUFFER_SIZE / 4) }
|
val backbufL = Array((4096f / BUFFER_SIZE * 4).roundToInt()) { FloatArray(BUFFER_SIZE / 4) }
|
||||||
val backbufR = Array(BUFFER_SIZE / 16) { FloatArray(BUFFER_SIZE / 4) }
|
val backbufR = Array((4096f / BUFFER_SIZE * 4).roundToInt()) { FloatArray(BUFFER_SIZE / 4) }
|
||||||
|
|
||||||
private val sqrt2p = 0.7071067811865475
|
private val sqrt2p = 0.7071067811865475
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ class Convolv(ir: File, val gain: Float = decibelsToFullscale(-12.0).toFloat()):
|
|||||||
val t1 = System.nanoTime()
|
val t1 = System.nanoTime()
|
||||||
for (ch in outbuf1.indices) {
|
for (ch in outbuf1.indices) {
|
||||||
|
|
||||||
push(inbuf1[ch].toDoubleArray(), inbuf[ch])
|
push(inbuf1[ch].toDoubleArray(gain), inbuf[ch])
|
||||||
|
|
||||||
val inputFFT = FastFourier(inbuf[ch]).let { it.transform(); it.getComplex(false) }
|
val inputFFT = FastFourier(inbuf[ch]).let { it.transform(); it.getComplex(false) }
|
||||||
|
|
||||||
@@ -366,7 +366,10 @@ class Convolv(ir: File, val gain: Float = decibelsToFullscale(-12.0).toFloat()):
|
|||||||
val Y = multiply(inputFFT, convFFT[ch])
|
val Y = multiply(inputFFT, convFFT[ch])
|
||||||
val y = real(ifft(Y))
|
val y = real(ifft(Y))
|
||||||
|
|
||||||
val u = y.sliceArray(Ny - BLOCKSIZE until Ny).toFloatArray(gain)
|
// val u = y.sliceArray(Ny - BLOCKSIZE until Ny).toFloatArray(gain) // y size == Ny
|
||||||
|
val u = y.takeLast(BLOCKSIZE).map { it.toFloat() }.toFloatArray()
|
||||||
|
|
||||||
|
// println("y size: ${y.size}; Ny=$Ny")
|
||||||
|
|
||||||
System.arraycopy(u, 0, outbuf1[ch], 0, BLOCKSIZE)
|
System.arraycopy(u, 0, outbuf1[ch], 0, BLOCKSIZE)
|
||||||
}
|
}
|
||||||
@@ -374,10 +377,10 @@ class Convolv(ir: File, val gain: Float = decibelsToFullscale(-12.0).toFloat()):
|
|||||||
val ptime = (t2 - t1).toDouble()
|
val ptime = (t2 - t1).toDouble()
|
||||||
val realtime = BLOCKSIZE / SAMPLING_RATED * 1000000000L
|
val realtime = BLOCKSIZE / SAMPLING_RATED * 1000000000L
|
||||||
if (realtime >= ptime) {
|
if (realtime >= ptime) {
|
||||||
println("Processing speed: ${realtime / ptime}x FASTER than realtime")
|
// println("Processing speed: ${realtime / ptime}x FASTER than realtime")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println("Processing speed: ${ptime / realtime}x SLOWER than realtime")
|
// println("Processing speed: ${ptime / realtime}x SLOWER than realtime")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,10 +415,10 @@ class Convolv(ir: File, val gain: Float = decibelsToFullscale(-12.0).toFloat()):
|
|||||||
|
|
||||||
private fun push(samples: DoubleArray, buf: DoubleArray) {
|
private fun push(samples: DoubleArray, buf: DoubleArray) {
|
||||||
System.arraycopy(buf, samples.size, buf, 0, buf.size - samples.size)
|
System.arraycopy(buf, samples.size, buf, 0, buf.size - samples.size)
|
||||||
System.arraycopy(samples, 0, buf, buf.size - samples.size - 1, samples.size)
|
System.arraycopy(samples, 0, buf, buf.size - samples.size, samples.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FloatArray.toDoubleArray() = this.map { it.toDouble() }.toDoubleArray()
|
private fun FloatArray.toDoubleArray(gain: Float = 1f) = this.map { it.toDouble() * gain }.toDoubleArray()
|
||||||
private fun DoubleArray.toFloatArray(gain: Float = 1f) = this.map { it.toFloat() * gain }.toFloatArray()
|
private fun DoubleArray.toFloatArray(gain: Float = 1f) = this.map { it.toFloat() * gain }.toFloatArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user