mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
fix bug in audio system
This commit is contained in:
parent
27ba498f40
commit
28e28288cd
@ -19,6 +19,7 @@ import glm_.vec3.Vec3
|
||||
import org.lwjgl.openal.AL10.*
|
||||
|
||||
class SoundSource {
|
||||
private var playTime = -1L
|
||||
private val source: Int = alGenSources()
|
||||
|
||||
var loop: Boolean = false
|
||||
@ -72,9 +73,10 @@ class SoundSource {
|
||||
get() = alGetSourcei(source, AL_SOURCE_STATE) == AL_PLAYING
|
||||
|
||||
val available: Boolean
|
||||
get() = !isPlaying
|
||||
get() = !isPlaying || System.currentTimeMillis() - playTime > sound?.length ?: 0L // ToDo: Allow pause
|
||||
|
||||
fun play() {
|
||||
playTime = System.currentTimeMillis()
|
||||
alSourcePlay(source)
|
||||
}
|
||||
|
||||
@ -83,6 +85,7 @@ class SoundSource {
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
playTime = -1L
|
||||
alSourceStop(source)
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ data class Sound(
|
||||
val preload: Boolean = false,
|
||||
// ToDo: type
|
||||
) {
|
||||
var length: Long = -1L
|
||||
private set
|
||||
var loaded: Boolean = false
|
||||
private set
|
||||
var loadFailed: Boolean = false
|
||||
@ -79,6 +81,7 @@ data class Sound(
|
||||
|
||||
samplesLength = stb_vorbis_stream_length_in_samples(vorbis)
|
||||
sampleSeconds = stb_vorbis_stream_length_in_seconds(vorbis)
|
||||
length = (sampleSeconds * 1000).toLong()
|
||||
|
||||
|
||||
val pcm = BufferUtils.createShortBuffer(samplesLength)
|
||||
|
Loading…
x
Reference in New Issue
Block a user