still wip modularisation, game somehow boots

This commit is contained in:
minjaesong
2018-06-21 17:33:22 +09:00
parent f0a6f8b9c2
commit a6ea2b4e18
266 changed files with 2409 additions and 1122 deletions

View File

@@ -6,19 +6,22 @@ package net.torvald.terrarum.audio
*
* Channels and their mapping:
*
* Notation: (front/side/rear.subwoofer/top-front)
* Notation: (front/rear.subwoofer/top-front)
* Plugs: G-Front (green), K-Rear (black), Y-Centre/Subwoofer (yellow), E-Side (grey)
* e.g. E-RC,NULL means GREY jack outputs REAR-CENTRE to its left and nothing to its right channel.
*
* = Headphones: Binaural
* = Stereo ---------- (2/0/0.0/0): G-FL,FR
* = Quadraphonic ---- (2/0/2.0/0): G-FL,FR; K-RL,RR
* = 4.0 ------------- (3/0/1.0/0): G-FL,FR; Y-FC,RC
* = 5.1 ------------- (3/0/2.1/0): G-FL,FR; Y-FC,SW; K-RL,RR
* = 6.1 ------------- (3/0/3.1/0): G-FL,FR; Y-FC,SW; K-RL,RR, E-RC,RC
* = 7.1 ------------- (3/2/2.1/0): G-FL,FR; Y-FC,SW; K-RL,RR, E-SL,SR
* = Dolby Atmos 5.1.2 (3/0/2.1/2): G-FL,FR; Y-FC,SW; K-RL,RR, E-TL,TR
* = Stereo ---------- (2/0.0/0): G-FL,FR
* = Quadraphonic ---- (2/2.0/0): G-FL,FR; K-RL,RR
* = 4.0 ------------- (3/1.0/0): G-FL,FR; Y-FC,RC
* = 5.1 ------------- (3/2.1/0): G-FL,FR; Y-FC,SW; K-RL,RR
* = 6.1 ------------- (3/3.1/0): G-FL,FR; Y-FC,SW; K-RL,RR, E-RC,RC
* = 7.1 ------------- (3/4.1/0): G-FL,FR; Y-FC,SW; K-RL,RR, E-SL,SR
* = Dolby Atmos*5.1.2 (3/2.1/2): G-FL,FR; Y-FC,SW; K-RL,RR, E-TL,TR
*
* = Extra options:
* = No centre speaker (5.1 and above)
* = No subwoofer (5.1 and above)
*
* Channel uses:
*
@@ -31,10 +34,115 @@ package net.torvald.terrarum.audio
* * If both side and rear speakers are not there, play weather/ambient to the stereo speakers but NOT TO THE CENTRE
* * For non-existent speakers, use channel phantoming
*
* Note: 5.1.2 does NOT output Dolby-compatible signals.
* Note: 5.1.2 does NOT output Dolby-compatible signals. It's just a customised 8 channel setup.
*
* @see spatialAudioMixMat.xlsx
*/
object SpatialAudioMixer {
const val centreQuotient = 0.7071f
const val PANNING_THREE = 0.708f
const val PANNING_FOUR_POINT_FIVE = 0.596f
const val PANNING_SIX = 0.5f
fun getPanning(coefficient: Float, panningLaw: Float = PANNING_FOUR_POINT_FIVE): Float {
val k = panningLaw.toDouble()
val a = 2.0 - 2.0 * k
val b = 4.0 * k - 1.0
return (coefficient*a*a + coefficient*b).toFloat()
}
const val PRESET_QUADRAPHONIC = """
FL=1,0,0,0,0,0,0,0
FC=0.5,0.5,0,0,0,0,0,0
FR=0,1,0,0,0,0,0,0
RL=0,0,0,0,0.75,0.25,0,0
RR=0,0,0,0,0.25,0.75,0,0
SL=0.25,0,0,0,0.75,0,0,0
RC=0,0,0,0,0.5,0.5,0,0
SR=0,0.25,0,0,0,0.75,0,0
AMB=0.25,0.25,0,0,0.25,0.25,0,0
LFE=0,0,0,0,0.5,0.5,0,0
"""
const val PRESET_FIVE_POINT_ONE = """
FL=1,0,0,0,0,0,0,0
FC=0,0,1,0,0,0,0,0
FR=0,1,0,0,0,0,0,0
RL=0,0,0,0,0.75,0.25,0,0
RR=0,0,0,0,0.25,0.75,0,0
SL=0.25,0,0,0,0.75,0,0,0
RC=0,0,0,0,0.5,0.5,0,0
SR=0,0.25,0,0,0,0.75,0,0
AMB=0.25,0.25,0,0,0.25,0.25,0,0
LFE=0,0,0,1,0,0,0,0
"""
const val PRESET_SEVEN_POINT_ONE = """
FL=1,0,0,0,0,0,0,0
FC=0,0,1,0,0,0,0,0
FR=0,1,0,0,0,0,0,0
SL=0,0,0,0,0,0,1,0
SR=0,0,0,0,0,0,0,1
RL=0,0,0,0,1,0,0,0
RC=0,0,0,0,0.5,0.5,0,0
RR=0,0,0,0,0,1,0,0
AMB=0.125,0.125,0,0,0.125,0.125,0.25,0.25
LFE=0,0,0,1,0,0,0,0
"""
const val PRESET_FIVE_POINT_ONE_POINT_TWO = """
FL=1,0,0,0,0,0,0,0
FC=0,0,1,0,0,0,0,0
FR=0,1,0,0,0,0,0,0
RL=0,0,0,0,0.75,0.25,0,0
RR=0,0,0,0,0.25,0.75,0,0
SL=0.25,0,0,0,0.75,0,0,0
RC=0,0,0,0,0.5,0.5,0,0
RR=0,0.25,0,0,0,0.75,0,0
AMB=0,0,0,0,0.125,0.125,0.375,0.375
LFE=0,0,0,1,0,0,0,0
"""
const val PRESET_FOUR_POINT_ONE = """
FL=0.75,0.25,0,0,0,0,0,0
FC=0,0,1,0,0,0,0,0
FR=0.25,0.75,0,0,0,0,0,0
SL=1,0,0,0,0,0,0,0
SR=0,1,0,0,0,0,0,0
RL=0.5,0,0,0,0.5,0,0,0
RC=0,0,0,0,1,0,0,0
RR=0,0.5,0,0,0.5,0,0,0
AMB=0.25,0.25,0,0,0.5,0,0,0
LFE=0,0,0,1,0,0,0,0
"""
const val PRESET_SIX_POINT_ONE = """
FL=1,0,0,0,0,0,0,0
FC=0,0,1,0,0,0,0,0
FR=0,1,0,0,0,0,0,0
RL=0,0,0,0,0.75,0.25,0,0
RR=0,0,0,0,0.25,0.75,0,0
SL=0.25,0,0,0,0.75,0,0,0
RC=0,0,0,0,0,0,1,0
SR=0,0.25,0,0,0,0.75,0,0
AMB=0.25,0.25,0,0,0.25,0.25,0,0
LFE=0,0,0,1,0,0,0,0
"""
const val PRESET_STEREO = """
FL=0.75,0.25,0,0,0,0,0,0
FC=0.5,0.5,0,0,0,0,0,0
FR=0.25,0.75,0,0,0,0,0,0
SL=1,0,0,0,0,0,0,0
SR=0,1,0,0,0,0,0,0
RL=1,0,0,0,0,0,0,0
RC=0.5,0.5,0,0,0,0,0,0
RR=0,1,0,0,0,0,0,0
AMB=0.5,0.5,0,0,0,0,0,0
LFE=0.5,0.5,0,0,0,0,0,0
"""
}

View File

@@ -0,0 +1,174 @@
package net.torvald.terrarum.audio.surroundpanner
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.files.FileHandle
import java.awt.BorderLayout
import javax.swing.*
/**
* Created by minjaesong on 2018-05-18.
*/
class SurroundPannerTest : JFrame() {
val mixerPanel = JPanel(BorderLayout()) // LR slider
val mixerPanSlider = JSlider(JSlider.HORIZONTAL, -32768, 32767, 0)
init {
val sliderPanel = JPanel(); sliderPanel.add(mixerPanSlider)
mixerPanel.add(sliderPanel, BorderLayout.CENTER)
this.add(mixerPanel, BorderLayout.CENTER)
this.defaultCloseOperation = EXIT_ON_CLOSE
this.isVisible = true
this.setSize(400, 600)
}
}
class AudioPlayerSlave : Game() {
lateinit var audioSample: FileHandle
lateinit var gdxSound: Sound
var soundID = 0L
lateinit var surroundPanner: SurroundPannerTest
override fun create() {
audioSample = Gdx.files.internal("assets/loopey.wav")
gdxSound = Gdx.audio.newSound(audioSample)
surroundPanner = SurroundPannerTest()
soundID = gdxSound.loop()
}
override fun render() {
gdxSound.setPan(soundID, surroundPanner.mixerPanSlider.value.toFloat() / 32768f, 0.5f)
}
override fun dispose() {
super.dispose()
gdxSound.dispose()
}
}
fun main(args: Array<String>) {
val appConfig = LwjglApplicationConfiguration()
appConfig.vSyncEnabled = false
appConfig.resizable = true
appConfig.width = 256
appConfig.height = 256
appConfig.backgroundFPS = 20
appConfig.foregroundFPS = 20
LwjglApplication(AudioPlayerSlave(), appConfig)
}
/*
package net.torvald.terrarum.audio.surroundpanner
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.files.FileHandle
import net.torvald.terrarum.audio.SpatialAudioMixer
import java.awt.BorderLayout
import java.io.StringReader
import java.util.*
import javax.swing.*
/**
* Created by minjaesong on 2018-05-18.
*/
class SurroundPannerTest(val panningMatrix: String) : JFrame() {
val panningSettings = Properties()
val mixerPanel = JPanel(BorderLayout()) // LR slider, options (pan-rear threshold: Double, panning law: Double)
val matricesPanel = JPanel(BorderLayout()) // show and edit panning matrix
val mixerPanSlider = JSlider(JSlider.HORIZONTAL, -32768, 32767, 0)
val mixerPanRearSelector = JSpinner(SpinnerNumberModel(6667, 0, 10000, 1))
val mixerPanLawSelector = JSpinner(SpinnerListModel(arrayOf(0.0, -3.0, -4.5, -6.0)))
init {
val sliderPanel = JPanel(); sliderPanel.add(mixerPanSlider)
sliderPanel.isVisible = true
val panRearPanel = JPanel(); panRearPanel.add(JLabel("Pan-rear threshold")); panRearPanel.add(mixerPanRearSelector)
panRearPanel.isVisible = true
val panLawPanel = JPanel(); panLawPanel.add(JLabel("Panning law")); panLawPanel.add(mixerPanLawSelector)
panLawPanel.isVisible = true
val optionsPanel = JPanel(); optionsPanel.add(panRearPanel); optionsPanel.add(panLawPanel)
optionsPanel.isVisible = true
mixerPanel.add(sliderPanel, BorderLayout.CENTER)
mixerPanel.add(optionsPanel, BorderLayout.SOUTH)
panningSettings.load(StringReader(panningMatrix))
this.add(mixerPanel, BorderLayout.CENTER)
this.add(matricesPanel, BorderLayout.SOUTH)
this.defaultCloseOperation = EXIT_ON_CLOSE
this.isVisible = true
this.setSize(400, 600)
}
}
class AudioPlayerSlave : Game() {
lateinit var audioSample: FileHandle
lateinit var gdxSound: Sound
var soundID = 0L
lateinit var surroundPanner: SurroundPannerTest
override fun create() {
audioSample = Gdx.files.internal("assets/loopey.wav")
gdxSound = Gdx.audio.newSound(audioSample)
surroundPanner = SurroundPannerTest(SpatialAudioMixer.PRESET_QUADRAPHONIC)
soundID = gdxSound.loop()
}
override fun render() {
gdxSound.setPan(soundID, surroundPanner.mixerPanSlider.value.toFloat() / 32768f, 1f)
}
override fun dispose() {
super.dispose()
gdxSound.dispose()
}
}
fun main(args: Array<String>) {
val appConfig = LwjglApplicationConfiguration()
appConfig.vSyncEnabled = false
appConfig.resizable = true
appConfig.width = 256
appConfig.height = 256
appConfig.backgroundFPS = 20
appConfig.foregroundFPS = 20
LwjglApplication(AudioPlayerSlave(), appConfig)
}
*/