mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
circular array is fixed and tested
This commit is contained in:
47
src/net/torvald/terrarum/tests/CircularArrayTest.kt
Normal file
47
src/net/torvald/terrarum/tests/CircularArrayTest.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
import net.torvald.dataclass.CircularArray
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-01-09.
|
||||
*/
|
||||
class CircularArrayTest {
|
||||
|
||||
operator fun invoke() {
|
||||
val testSet = CircularArray<Int?>(5)
|
||||
val testSet2 = CircularArray<Int?>(5)
|
||||
|
||||
for (i in 1..5) {
|
||||
testSet.add(i)
|
||||
}
|
||||
|
||||
println("Metadata:")
|
||||
println(testSet)
|
||||
println("forEach():")
|
||||
testSet.forEach { print("$it ") }
|
||||
println("\nfold(0, sum):")
|
||||
println(testSet.fold(0) { acc, v -> acc + (v ?: 0) })
|
||||
println("Raw:")
|
||||
testSet.buffer.forEach { print("$it ") }
|
||||
println()
|
||||
|
||||
println()
|
||||
for (i in 1..6) {
|
||||
testSet2.add(i)
|
||||
}
|
||||
|
||||
println("Metadata:")
|
||||
println(testSet2)
|
||||
println("forEach():")
|
||||
testSet2.forEach { print("$it ") }
|
||||
println("\nfold(0, sum):")
|
||||
println(testSet2.fold(0) { acc, v -> acc + (v ?: 0) })
|
||||
println("Raw:")
|
||||
testSet2.buffer.forEach { print("$it ") }
|
||||
println()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
CircularArrayTest().invoke()
|
||||
}
|
||||
175
src/net/torvald/terrarum/tests/SurroundPannerTest.kt
Normal file
175
src/net/torvald/terrarum/tests/SurroundPannerTest.kt
Normal file
@@ -0,0 +1,175 @@
|
||||
|
||||
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.JFrame
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.JSlider
|
||||
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user