mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-11 14:21:52 +09:00
more musicplayer things
This commit is contained in:
@@ -177,7 +177,10 @@ object AudioMixer: Disposable {
|
||||
masterTrack.filters[0] = SoftClp
|
||||
masterTrack.filters[1] = Buffer
|
||||
masterTrack.filters[2] = Spectro()
|
||||
masterTrack.filters[3] = Vecto()
|
||||
masterTrack.filters[3] = Vecto(2f)
|
||||
|
||||
musicTrack.filters[1] = Spectro()
|
||||
ambientTrack.filters[1] = Spectro()
|
||||
|
||||
listOf(sumBus, convolveBusOpen, convolveBusCave).forEach {
|
||||
it.addSidechainInput(musicTrack, 1.0)
|
||||
@@ -201,7 +204,7 @@ object AudioMixer: Disposable {
|
||||
masterTrack.addSidechainInput(fadeBus, 1.0)
|
||||
masterTrack.addSidechainInput(guiTrack, 1.0)
|
||||
|
||||
musicTrack.filters[1] = Gain(0.5f)
|
||||
musicTrack.filters[3] = Gain(0.5f)
|
||||
|
||||
dynamicTracks.forEach {
|
||||
it.filters[0] = BinoPan(0f)
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.ui.BasicDebugInfoWindow.Companion.STRIP_W
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import kotlin.math.*
|
||||
|
||||
class Spectro : TerrarumAudioFilter() {
|
||||
class Spectro(val gain: Float = 1f) : TerrarumAudioFilter() {
|
||||
private val FFTSIZE = 1024
|
||||
private val inBuf = Array(2) { FloatArray(FFTSIZE) }
|
||||
|
||||
@@ -51,7 +51,7 @@ class Spectro : TerrarumAudioFilter() {
|
||||
push(inbuf[0], inBuf[0])
|
||||
push(inbuf[1], inBuf[1])
|
||||
for (i in 0 until FFTSIZE) {
|
||||
chsum.reim[2*i] = ((inBuf[0][i] + inBuf[1][i]) / 2f) * fftWin[i]
|
||||
chsum.reim[2*i] = ((inBuf[0][i] + inBuf[1][i]) / 2f) * fftWin[i] * gain
|
||||
}
|
||||
|
||||
// do fft
|
||||
@@ -74,7 +74,7 @@ class Spectro : TerrarumAudioFilter() {
|
||||
for (bin in 0 until FFTSIZE / 2) {
|
||||
val freqL = (SAMPLING_RATED / FFTSIZE) * bin
|
||||
val freqR = (SAMPLING_RATED / FFTSIZE) * (bin + 1)
|
||||
val magn0 = fftOut.reim[2 * bin].absoluteValue / FFTSIZE * (freqR / 10.0) // apply slope
|
||||
val magn0 = fftOut.reim[2 * bin].absoluteValue / FFTSIZE * (freqR / 20.0) // apply slope
|
||||
val magn = FastMath.interpolateLinear(BasicDebugInfoWindow.FFT_SMOOTHING_FACTOR, magn0, oldFFTmagn[bin])
|
||||
val magnLog = fullscaleToDecibels(magn)
|
||||
|
||||
@@ -94,7 +94,7 @@ class Spectro : TerrarumAudioFilter() {
|
||||
}
|
||||
|
||||
|
||||
class Vecto : TerrarumAudioFilter() {
|
||||
class Vecto(val gain: Float = 1f) : TerrarumAudioFilter() {
|
||||
val backbufL = Array((6144f / AUDIO_BUFFER_SIZE).roundToInt().coerceAtLeast(1)) {
|
||||
FloatArray(AUDIO_BUFFER_SIZE)
|
||||
}
|
||||
@@ -115,8 +115,8 @@ class Vecto : TerrarumAudioFilter() {
|
||||
|
||||
// plot dots
|
||||
for (i in 0 until TerrarumAudioMixerTrack.AUDIO_BUFFER_SIZE) {
|
||||
val y0 = +inbuf[0][i] * 2f
|
||||
val x0 = -inbuf[1][i] * 2f// rotate the domain by -90 deg
|
||||
val y0 = +inbuf[0][i] * gain
|
||||
val x0 = -inbuf[1][i] * gain// rotate the domain by -90 deg
|
||||
|
||||
val x = (+x0*sqrt2p -y0*sqrt2p) * 1.4142
|
||||
val y = (-x0*sqrt2p -y0*sqrt2p) * 1.4142 // further rotate by -45 deg then flip along the y axis
|
||||
|
||||
@@ -148,6 +148,9 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
private var diskJockeyingMode = "intermittent" // intermittent, continuous
|
||||
|
||||
private fun registerSongsFromDir(musicDir: String, fileToName: ((String) -> String)?) {
|
||||
printdbg(this, "registerSongsFromDir $musicDir")
|
||||
|
||||
|
||||
val fileToName = if (fileToName == null) {
|
||||
{ name: String -> name.substringBeforeLast('.').replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" ") }
|
||||
}
|
||||
@@ -295,11 +298,11 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
if (!musicFired) {
|
||||
musicFired = true
|
||||
|
||||
val song = songs[musicBin.removeAt(0)]
|
||||
// prevent same song to play twice
|
||||
if (musicBin.isEmpty()) {
|
||||
restockMUsicBin()
|
||||
}
|
||||
val song = songs[musicBin.removeAt(0)]
|
||||
|
||||
startMusic(song)
|
||||
}
|
||||
@@ -322,11 +325,11 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
if (!ambFired) {
|
||||
ambFired = true
|
||||
|
||||
val song = ambients[ambientsBin.removeAt(0)]
|
||||
// prevent same song to play twice
|
||||
if (ambientsBin.isEmpty()) {
|
||||
ambientsBin = ArrayList(ambients.indices.toList().shuffled())
|
||||
}
|
||||
val song = ambients[ambientsBin.removeAt(0)]
|
||||
|
||||
startAmbient(song)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user