mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
working track volume
This commit is contained in:
@@ -34,9 +34,9 @@ class AudioProcessBuf(val size: Int) {
|
||||
updateFloats()
|
||||
}
|
||||
|
||||
fun getL0() = FloatArray(size / 4) { fbuf0[2*it] }
|
||||
fun getR0() = FloatArray(size / 4) { fbuf0[2*it+1] }
|
||||
fun getL1() = FloatArray(size / 4) { fbuf1[2*it] }
|
||||
fun getR1() = FloatArray(size / 4) { fbuf1[2*it+1] }
|
||||
fun getL0(volume: Double) = FloatArray(size / 4) { (volume * fbuf0[2*it]).toFloat() }
|
||||
fun getR0(volume: Double) = FloatArray(size / 4) { (volume * fbuf0[2*it+1]).toFloat() }
|
||||
fun getL1(volume: Double) = FloatArray(size / 4) { (volume * fbuf1[2*it]).toFloat() }
|
||||
fun getR1(volume: Double) = FloatArray(size / 4) { (volume * fbuf1[2*it+1]).toFloat() }
|
||||
|
||||
}
|
||||
@@ -82,27 +82,29 @@ class MixerTrackProcessor(val bufferSize: Int, val track: TerrarumAudioMixerTrac
|
||||
var samplesR1: FloatArray
|
||||
|
||||
if (track.isMaster) {
|
||||
val streamBuf = track.sidechainInputs[0]!!.first.processor.streamBuf
|
||||
samplesL0 = streamBuf.getL0()
|
||||
samplesR0 = streamBuf.getR0()
|
||||
samplesL1 = streamBuf.getL1()
|
||||
samplesR1 = streamBuf.getR1()
|
||||
// TEST CODE must combine all the inputs
|
||||
samplesL0 = track.sidechainInputs[0]!!.first.processor.fout0[0]
|
||||
samplesR0 = track.sidechainInputs[0]!!.first.processor.fout0[1]
|
||||
samplesL1 = track.sidechainInputs[0]!!.first.processor.fout1[0]
|
||||
samplesR1 = track.sidechainInputs[0]!!.first.processor.fout1[1]
|
||||
}
|
||||
else {
|
||||
samplesL0 = streamBuf.getL0()
|
||||
samplesR0 = streamBuf.getR0()
|
||||
samplesL1 = streamBuf.getL1()
|
||||
samplesR1 = streamBuf.getR1()
|
||||
samplesL0 = streamBuf.getL0(track.volume)
|
||||
samplesR0 = streamBuf.getR0(track.volume)
|
||||
samplesL1 = streamBuf.getL1(track.volume)
|
||||
samplesR1 = streamBuf.getR1(track.volume)
|
||||
}
|
||||
|
||||
|
||||
// run the input through the stack of filters
|
||||
val filterStack = track.filters.filter { !it.bypass }
|
||||
|
||||
val fin0 = listOf(samplesL0, samplesR0)
|
||||
val fin1 = listOf(samplesL1, samplesR1)
|
||||
fout0 = fout1
|
||||
fout1 = listOf(FloatArray(bufferSize / 4), FloatArray(bufferSize / 4))
|
||||
val filter = if (track.isMaster) testFilter else NullFilter
|
||||
filter.thru(fin0, fin1, fout0, fout1)
|
||||
filter(fin0, fin1, fout0, fout1)
|
||||
|
||||
|
||||
// final writeout
|
||||
|
||||
@@ -2,11 +2,20 @@ package net.torvald.terrarum.audio
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
|
||||
interface TerrarumAudioFilter {
|
||||
fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>)
|
||||
abstract class TerrarumAudioFilter {
|
||||
var bypass = false
|
||||
protected abstract fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>)
|
||||
operator fun invoke(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>) {
|
||||
if (bypass) {
|
||||
outbuf1.forEachIndexed { index, outTrack ->
|
||||
System.arraycopy(inbuf1[index], 0, outTrack, 0, outTrack.size)
|
||||
}
|
||||
}
|
||||
else thru(inbuf0, inbuf1, outbuf0, outbuf1)
|
||||
}
|
||||
}
|
||||
|
||||
object NullFilter: TerrarumAudioFilter {
|
||||
object NullFilter: TerrarumAudioFilter() {
|
||||
override fun thru(inbuf0: List<FloatArray>, inbuf1: List<FloatArray>, outbuf0: List<FloatArray>, outbuf1: List<FloatArray>) {
|
||||
outbuf1.forEachIndexed { index, outTrack ->
|
||||
System.arraycopy(inbuf1[index], 0, outTrack, 0, outTrack.size)
|
||||
@@ -15,7 +24,7 @@ object NullFilter: TerrarumAudioFilter {
|
||||
}
|
||||
|
||||
|
||||
class Lowpass(cutoff: Int, rate: Int): TerrarumAudioFilter {
|
||||
class Lowpass(cutoff: Int, rate: Int): TerrarumAudioFilter() {
|
||||
|
||||
val alpha: Float
|
||||
init {
|
||||
|
||||
@@ -114,7 +114,7 @@ class TerrarumAudioMixerTrack(val name: String, val isMaster: Boolean = false):
|
||||
|
||||
// 1st ring of the hell: the THREADING HELL //
|
||||
|
||||
internal var processor = MixerTrackProcessor(32768, this)
|
||||
internal var processor = MixerTrackProcessor(4096, this)
|
||||
private val processorThread = Thread(processor).also {
|
||||
it.start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user