mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
reverb filter
This commit is contained in:
@@ -102,7 +102,7 @@ object AudioMixer: Disposable {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
// 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(25f, 1f, 1000f)
|
musicTrack.filters[1] = Reverb(36f, 0.9f, 100f)
|
||||||
|
|
||||||
masterTrack.filters[0] = SoftClp
|
masterTrack.filters[0] = SoftClp
|
||||||
masterTrack.filters[1] = Buffer
|
masterTrack.filters[1] = Buffer
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ class BinoPan(var pan: Float, var earDist: Float = 0.18f): TerrarumAudioFilter()
|
|||||||
|
|
||||||
class Bitcrush(var steps: Int, var inputGain: Float = 1f): TerrarumAudioFilter() {
|
class Bitcrush(var steps: Int, var inputGain: Float = 1f): TerrarumAudioFilter() {
|
||||||
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>) {
|
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>) {
|
||||||
for (ch in 0 until outbuf1.size) {
|
for (ch in outbuf1.indices) {
|
||||||
for (i in 0 until BUFFER_SIZE / 4) {
|
for (i in 0 until BUFFER_SIZE / 4) {
|
||||||
val inn = ((inbuf1[ch][i] * inputGain).coerceIn(-1f, 1f) + 1f) / 2f // 0f..1f
|
val inn = ((inbuf1[ch][i] * inputGain).coerceIn(-1f, 1f) + 1f) / 2f // 0f..1f
|
||||||
val stepped = (inn * (steps - 1)).roundToFloat() / (steps - 1)
|
val stepped = (inn * (steps - 1)).roundToFloat() / (steps - 1)
|
||||||
@@ -249,35 +249,35 @@ class Bitcrush(var steps: Int, var inputGain: Float = 1f): TerrarumAudioFilter()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Reverb(val delayMS: Float, var decay: Float, var lowpass: Float): TerrarumAudioFilter() {
|
class Reverb(val delayMS: Float, var feedback: Float, var lowpass: Float): TerrarumAudioFilter() {
|
||||||
|
|
||||||
private var delay = (SAMPLING_RATEF * delayMS / 1000f).roundToInt()
|
private var delay = (SAMPLING_RATEF * delayMS / 1000f).roundToInt()
|
||||||
|
private val bufSize = delay
|
||||||
private val buf = Array<FloatArray>(2) { FloatArray(delay) }
|
private val buf = Array<FloatArray>(2) { FloatArray(bufSize) }
|
||||||
|
|
||||||
private fun unshift(sample: Float, buf: FloatArray) {
|
private fun unshift(sample: Float, buf: FloatArray) {
|
||||||
for (i in delay - 1 downTo 1) {
|
for (i in bufSize - 1 downTo 1) {
|
||||||
buf[i] = buf[i - 1]
|
buf[i] = buf[i - 1]
|
||||||
}
|
}
|
||||||
buf[0] = sample
|
buf[0] = sample
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>) {
|
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>) {
|
||||||
val RC: Float = 1f / (lowpass * FastMath.TWO_PI)
|
val RC: Float = 1f / (lowpass * FastMath.TWO_PI)
|
||||||
val dt: Float = 1f / SAMPLING_RATEF
|
val dt: Float = 1f / SAMPLING_RATEF
|
||||||
val alpha = dt / (RC + dt)
|
val alpha = dt / (RC + dt)
|
||||||
|
|
||||||
for (ch in 0 until outbuf1.size) {
|
for (ch in outbuf1.indices) {
|
||||||
for (i in 0 until BUFFER_SIZE / 4) {
|
for (i in 0 until BUFFER_SIZE / 4) {
|
||||||
|
// TODO lowpass is not really working
|
||||||
val in1 = inbuf1[ch][i]
|
val in1 = inbuf1[ch][i]
|
||||||
|
|
||||||
val in2 = buf[ch][delay - 2]
|
val rv1 = buf[ch][delay - 1]
|
||||||
val in3 = buf[ch][delay - 1]
|
val rv0 = buf[ch][delay - 2]
|
||||||
|
|
||||||
val dek1 = 1f / (1f + decay)
|
val reverb = (rv1 + alpha * (rv0 - rv1))
|
||||||
val dek2 = decay / (1f + decay)
|
|
||||||
|
|
||||||
val out = in1 * dek1 + (in2 + alpha * (in3 - in2)) * dek2
|
val out = in1 - reverb * feedback
|
||||||
|
|
||||||
unshift(out, buf[ch])
|
unshift(out, buf[ch])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user