fix: mp2 player would not play the very first frame

This commit is contained in:
minjaesong
2023-01-16 23:29:41 +09:00
parent 5b86e88779
commit dfe5bf3390
5 changed files with 17 additions and 12 deletions

View File

@@ -777,7 +777,7 @@ class AudioJSR223Delegate(private val vm: VM) {
};
// check for valid header: syncword OK, MPEG-Audio Layer 2
if ((syspeek(mp2_frame!!) != 0xFF) || ((syspeek(mp2_frame!! +1) and 0xFE) != 0xFC)){
throw Error("Invalid header")
throw Error("Invalid header at $mp2_frame: ${syspeek(mp2_frame!!).toString(16)} ${syspeek(mp2_frame!! +1).toString(16)}")
};
// set up the bitstream reader

View File

@@ -1,8 +1,9 @@
package net.torvald.tsvm
import com.badlogic.gdx.utils.Base64Coder
import net.torvald.UnsafeHelper
object Base64Delegate {
class Base64Delegate(val vm: VM) {
fun atob(inputstr: String): ByteArray {
return Base64Coder.decode(inputstr)
@@ -18,4 +19,11 @@ object Base64Delegate {
return sb.toString()
}
fun atoptr(inputstr: String): Int {
val b = atob(inputstr)
val ptr = vm.malloc(b.size)
UnsafeHelper.memcpyRaw(b, UnsafeHelper.getArrayOffset(b), null, vm.usermem.ptr + ptr, b.size.toLong())
return ptr
}
}

View File

@@ -72,7 +72,7 @@ object VMRunnerFactory {
bind.putMember("graphics", GraphicsJSR223Delegate(vm))
bind.putMember("serial", VMSerialDebugger(vm))
bind.putMember("gzip", CompressorDelegate(vm))
bind.putMember("base64", Base64Delegate)
bind.putMember("base64", Base64Delegate(vm))
bind.putMember("com", SerialHelperDelegate(vm))
bind.putMember("dma", DMADelegate(vm))
bind.putMember("audio", AudioJSR223Delegate(vm))