mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 04:54:05 +09:00
working gapless playback but musicplayer anim is not
This commit is contained in:
@@ -45,12 +45,27 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
|
||||
|
||||
private fun allocateStreamBuf(track: TerrarumAudioMixerTrack) {
|
||||
printdbg("Allocating a StreamBuf with rate ${track.currentTrack!!.samplingRate}")
|
||||
streamBuf = AudioProcessBuf(track.currentTrack!!.samplingRate, {
|
||||
val l = track.currentTrack?.gdxMusic?.forceInvoke<Int>("read", arrayOf(it))
|
||||
track.currentTrack?.let {
|
||||
it.samplesRead += l!! / 4
|
||||
streamBuf = AudioProcessBuf(track.currentTrack!!.samplingRate, { buffer ->
|
||||
var bytesRead = track.currentTrack?.gdxMusic?.forceInvoke<Int>("read", arrayOf(buffer)) ?: 0
|
||||
|
||||
// increment samplesRead of the current track
|
||||
track.currentTrack?.let { it.samplesRead += bytesRead / 4 }
|
||||
|
||||
// do gapless fetch if there is space in the buffer
|
||||
if (track.doGaplessPlayback && bytesRead < buffer.size) {
|
||||
track.currentTrack?.reset()
|
||||
track.pullNextTrack()
|
||||
|
||||
val tmpBuf = ByteArray(buffer.size - bytesRead)
|
||||
val newRead = track.currentTrack?.gdxMusic?.forceInvoke<Int>("read", arrayOf(tmpBuf)) ?: 0
|
||||
|
||||
track.currentTrack?.let { it.samplesRead += newRead / 4 }
|
||||
System.arraycopy(tmpBuf, 0, buffer, bytesRead, tmpBuf.size)
|
||||
|
||||
bytesRead += newRead
|
||||
}
|
||||
l
|
||||
|
||||
bytesRead
|
||||
}, {
|
||||
track.stop()
|
||||
this.streamBuf = null
|
||||
|
||||
@@ -22,7 +22,14 @@ enum class TrackType {
|
||||
STATIC_SOURCE, DYNAMIC_SOURCE, BUS, MASTER
|
||||
}
|
||||
|
||||
class TerrarumAudioMixerTrack(val name: String, val trackType: TrackType, var maxVolumeFun: () -> Double = {1.0}): Disposable {
|
||||
class TerrarumAudioMixerTrack(
|
||||
val name: String,
|
||||
val trackType: TrackType,
|
||||
var doGaplessPlayback: Boolean = false, // if true, the audio will be pulled from the `nextTrack` to always fully fill the read-buffer
|
||||
var maxVolumeFun: () -> Double = {1.0}
|
||||
): Disposable {
|
||||
|
||||
var pullNextTrack = {}
|
||||
|
||||
companion object {
|
||||
const val SAMPLING_RATE = 48000
|
||||
@@ -138,8 +145,8 @@ class TerrarumAudioMixerTrack(val name: String, val trackType: TrackType, var ma
|
||||
override fun equals(other: Any?) = this.hash == (other as TerrarumAudioMixerTrack).hash
|
||||
|
||||
fun stop() {
|
||||
currentTrack?.samplesRead = 0L
|
||||
currentTrack?.gdxMusic?.forceInvoke<Int>("reset", arrayOf())
|
||||
currentTrack?.reset()
|
||||
|
||||
streamPlaying = false
|
||||
// playStartedTime = 0L
|
||||
|
||||
|
||||
Reference in New Issue
Block a user