From 8517406d8bf921aaca5cc5be7428266b91499acd Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 23 Jan 2023 15:34:22 +0900 Subject: [PATCH] fix: mp2 384k would cause stack overflow error --- assets/disk0/tvdos/bin/encodemov.js | 2 +- terranmon.txt | 1 + .../torvald/tsvm/peripheral/AudioAdapter.kt | 6 ++++- .../src/net/torvald/tsvm/peripheral/MP2Env.kt | 8 ++++++- .../src/net/torvald/tsvm/AudioMenu.kt | 24 +++++++++++++++---- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/assets/disk0/tvdos/bin/encodemov.js b/assets/disk0/tvdos/bin/encodemov.js index c0ebd8c..c29ba07 100644 --- a/assets/disk0/tvdos/bin/encodemov.js +++ b/assets/disk0/tvdos/bin/encodemov.js @@ -9,7 +9,7 @@ let PATHFUN = (i) => `/ddol2/${(''+i).padStart(5,'0')}.bmp` // how can be the im let AUDIOTRACK = 'ddol.mp2' let AUDIOFORMAT = 'MP2fr' // PCMu8 or MP2fr // to export video to its frames: -// ffmpeg -i file.mp4 file/%05d.bmp +// ffmpeg -i file.mp4 file/%05d.png // the input frames must be resized (and cropped) beforehand, using ImageMagick is recommended, like so: // mogrify -path ./path/to/write/results/ -resize 560x448^ -gravity Center -extent 560x448 ./path/to/source/files/* // diff --git a/terranmon.txt b/terranmon.txt index 7a11fa4..0fd1594 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -621,6 +621,7 @@ Sound Adapter MMIO 64..2367 RW: MP2 Decoded Samples (unsigned 8-bit stereo) 2368..4095 RW: MP2 Frame to be decoded +4096..4097 RO: MP2 Frame guard bytes; always return 0 on read Sound Hardware Info - Sampling rate: 32000 Hz diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt index d1d17d5..d03c886 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/AudioAdapter.kt @@ -233,11 +233,15 @@ class AudioAdapter(val vm: VM) : PeriBase(VM.PERITYPE_SOUND) { 41 -> mp2Busy.toInt().toByte() in 64..2367 -> mediaDecodedBin[addr - 64] in 2368..4095 -> mediaFrameBin[addr - 2368] + in 4096..4097 -> 0 in 32768..65535 -> (adi - 32768).let { cueSheet[it / 16].read(it % 15) } in 65536..131071 -> pcmBin[addr - 65536] - else -> mmio_read(addr % 131072) + else -> { + println("[AudioAdapter] Bus mirroring on mmio_reading while trying to read address $addr") + mmio_read(addr % 131072) + } } } diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/MP2Env.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/MP2Env.kt index 7d7918e..8e3db98 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/MP2Env.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/MP2Env.kt @@ -338,7 +338,13 @@ class MP2Env(val vm: VM) { samplesR[pushSizeR++] = sampleR } - val ret = _decodeFrame(mp2, framePtr, pcm, pushL, pushR) + val ret = try { + _decodeFrame(mp2, framePtr, pcm, pushL, pushR) + } + catch (e: Throwable) { + e.printStackTrace() + intArrayOf(0, 0) + } // dither samples and store them to the given "out" pointer var outPos = out diff --git a/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt b/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt index 97cf662..e78d117 100644 --- a/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt +++ b/tsvm_executable/src/net/torvald/tsvm/AudioMenu.kt @@ -39,18 +39,26 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe val adev = parent.currentlyPersistentVM?.vm?.peripheralTable?.getOrNull(cardIndex ?: -1)?.peripheral as? AudioAdapter if (adev != null) { + + // draw status LCD batch.inUse { // draw backgrounds batch.color = COL_WELL for (i in 0..3) { batch.fillRect(7, 5 + 115*i, 102, 8*FONT.H + 4) } - batch.color = COL_SOUNDSCOPE_BACK - for (i in 0..3) { batch.fillRect(117, 5 + 115*i, 512, 8*FONT.H + 4) } } - - for (i in 0..3) { val ahead = (adev.extortField("playheads") as Array)[i] drawStatusLCD(adev, ahead, batch, i, 9f + 7, 7f + 7 + 115 * i) + } + + // draw Soundscope like this so that the overflown queue sparkline would not be overlaid on top of the envelopes + batch.inUse { + // draw backgrounds + batch.color = COL_SOUNDSCOPE_BACK + for (i in 0..3) { batch.fillRect(117, 5 + 115*i, 512, 8*FONT.H + 4) } + } + for (i in 0..3) { + val ahead = (adev.extortField("playheads") as Array)[i] drawSoundscope(adev, ahead, batch, i, 117f, 5f + 115 * i) } } @@ -64,6 +72,8 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe } private fun drawStatusLCD(audio: AudioAdapter, ahead: AudioAdapter.Playhead, batch: SpriteBatch, index: Int, x: Float, y: Float) { + // NOTE: Samples count for PCM mode is drawn by drawSoundscope() function, not this one! + batch.inUse { batch.color = Color.WHITE // PLAY icon @@ -156,6 +166,12 @@ class AudioMenu(parent: VMEmuExecutable, x: Int, y: Int, w: Int, h: Int) : EmuMe batch.fillRect(x + s, y + 27, 1, smpLHi) batch.fillRect(x + s, y + 81, 1, smpRHi) } + + batch.color = Color.WHITE + FONT.draw(batch, "Samples", x - 101, y + 5*FONT.H + 9) + batch.color = COL_ACTIVE3 + FONT.drawRalign(batch, "${smpCnt+1}", x - 17, y + 5*FONT.H + 9) + } else {