random sound audio bank

This commit is contained in:
minjaesong
2024-08-16 22:38:47 +09:00
parent 1c27966322
commit fc92fe6f55
6 changed files with 75 additions and 36 deletions

View File

@@ -19,9 +19,9 @@ abstract class AudioBank : Disposable {
abstract val name: String
abstract val samplingRate: Float
abstract val channels: Int
abstract val totalSizeInSamples: Long
abstract var samplingRate: Float
abstract var channels: Int
abstract var totalSizeInSamples: Long
abstract fun currentPositionInSamples(): Long
open fun sendMessage(msg: String) {}
@@ -30,5 +30,5 @@ abstract class AudioBank : Disposable {
abstract fun readSamples(bufferL: FloatArray, bufferR: FloatArray): Int
abstract fun reset()
abstract val songFinishedHook: (AudioBank) -> Unit
abstract var songFinishedHook: (AudioBank) -> Unit
}

View File

@@ -382,33 +382,19 @@ class FeedSamplesToAdev(val bufferSize: Int, val rate: Int, val track: TerrarumA
if (track.trackType != TrackType.MASTER) throw IllegalArgumentException("Track is not master")
}
val sleepTime = (1000000000.0 * ((bufferSize / 4.0) / TerrarumAudioMixerTrack.SAMPLING_RATED)).toLong()
val sleepMS = sleepTime / 1000000
val sleepNS = (sleepTime % 1000000).toInt()
private fun printdbg(msg: Any) {
if (true) println("[AudioAdapter ${track.name}] $msg")
}
@Volatile private var exit = false
override fun run() {
while (!exit) {
val writeQueue = track.pcmQueue
val queueSize = writeQueue.size
if (queueSize > 0) {
// printdbg("PULL; Queue size: $queueSize")
val samples = writeQueue.removeFirst()
track.adev!!.writeSamples(samples)
while (!Thread.currentThread().isInterrupted) {
try {
val writeQueue = track.pcmQueue
val queueSize = writeQueue.size
if (queueSize > 0) {
val samples = writeQueue.removeFirst()
track.adev!!.writeSamples(samples)
}
}
catch (_: InterruptedException) {
Thread.currentThread().interrupt()
}
// else {
// printdbg("QUEUE EMPTY QUEUE EMPTY QUEUE EMPTY ")
// }
// Thread.sleep(sleepMS, sleepNS)
}
}
fun stop() {
exit = true
}
}

View File

@@ -30,8 +30,8 @@ class MusicContainer(
val samplingRateOverride: Float?, // this is FIXED sampling rate
override var songFinishedHook: (AudioBank) -> Unit = {}
): AudioBank() {
override val samplingRate: Float
override val channels: Int
override var samplingRate: Float
override var channels: Int
val codec: String
// make Java code shorter
@@ -58,7 +58,7 @@ class MusicContainer(
var samplesReadCount = 0L; internal set
override val totalSizeInSamples: Long
override var totalSizeInSamples: Long
private val totalSizeInBytes: Long
private val gdxMusic: Music = Gdx.audio.newMusic(FileHandle(file))