mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-14 15:06:05 +09:00
"hardware" based mp2 decoding; dma and memcpy can now move data into the "hardware"
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
const SND_BASE_ADDR = audio.getBaseAddr()
|
||||
|
||||
if (!SND_BASE_ADDR) return 10
|
||||
|
||||
const pcm = require("pcm")
|
||||
const interactive = exec_args[2] && exec_args[2].toLowerCase() == "/i"
|
||||
function printdbg(s) { if (0) serial.println(s) }
|
||||
@@ -75,7 +79,7 @@ let bytes_left = FILE_SIZE
|
||||
let decodedLength = 0
|
||||
|
||||
|
||||
//serial.println(`Frame size: ${FRAME_SIZE}`)
|
||||
serial.println(`Frame size: ${FRAME_SIZE}`)
|
||||
|
||||
|
||||
|
||||
@@ -102,7 +106,8 @@ function decodeEvent(frameSize, len) {
|
||||
}
|
||||
|
||||
|
||||
decodeAndResample(samplePtrL, samplePtrR, decodePtr, len)
|
||||
// decodeAndResample(samplePtrL, samplePtrR, decodePtr, len)
|
||||
|
||||
audio.putPcmDataByPtr(decodePtr, len, 0)
|
||||
audio.setSampleUploadLength(0, len)
|
||||
audio.startSampleUpload(0)
|
||||
@@ -168,13 +173,10 @@ audio.setMasterVolume(0, 255)
|
||||
audio.play(0)
|
||||
|
||||
|
||||
let mp2context = audio.mp2Init()
|
||||
//let mp2context = audio.mp2Init()
|
||||
audio.mp2Init()
|
||||
|
||||
// decode frame
|
||||
let frame = sys.malloc(FRAME_SIZE)
|
||||
let samplePtrL = sys.malloc(2304) // 16b samples
|
||||
let samplePtrR = sys.malloc(2304) // 16b samples
|
||||
let decodePtr = sys.malloc(2304) // 8b samples
|
||||
let t1 = sys.nanoTime()
|
||||
let bufRealTimeLen = 36
|
||||
let stopPlay = false
|
||||
@@ -191,14 +193,23 @@ try {
|
||||
|
||||
printPlayBar()
|
||||
|
||||
filebuf.readBytes(FRAME_SIZE, frame)
|
||||
let [frameSize, samples] = audio.mp2DecodeFrame(mp2context, frame, true, samplePtrL, samplePtrR)
|
||||
if (frameSize) {
|
||||
// println(samples)
|
||||
// play using decodedLR
|
||||
decodeEvent(frameSize, samples)
|
||||
FRAME_SIZE = frameSize // JUST IN CASE when a vbr mp2 is not filtered and played thru
|
||||
|
||||
filebuf.readBytes(FRAME_SIZE, SND_BASE_ADDR - 2368)
|
||||
audio.mp2Decode()
|
||||
sys.waitForMemChg(SND_BASE_ADDR - 41, 255, 255)
|
||||
|
||||
if (audio.getPosition(0) >= QUEUE_MAX) {
|
||||
while (audio.getPosition(0) >= (QUEUE_MAX >>> 1)) {
|
||||
printdbg(`Queue full, waiting until the queue has some space (${audio.getPosition(0)}/${QUEUE_MAX})`)
|
||||
sys.sleep(bufRealTimeLen)
|
||||
}
|
||||
}
|
||||
audio.putPcmDataByPtr(SND_BASE_ADDR - 64, 2304, 0)
|
||||
audio.setSampleUploadLength(0, 2304)
|
||||
audio.startSampleUpload(0)
|
||||
sys.sleep(10)
|
||||
|
||||
|
||||
|
||||
bytes_left -= FRAME_SIZE
|
||||
decodedLength += FRAME_SIZE
|
||||
@@ -209,10 +220,6 @@ catch (e) {
|
||||
errorlevel = 1
|
||||
}
|
||||
finally {
|
||||
sys.free(frame)
|
||||
sys.free(decodePtr)
|
||||
sys.free(samplePtrL)
|
||||
sys.free(samplePtrR)
|
||||
}
|
||||
|
||||
return errorlevel
|
||||
@@ -49,6 +49,8 @@ function readBytes(length, ptrToDecode) {
|
||||
let ptr = (ptrToDecode === undefined) ? sys.malloc(length) : ptrToDecode
|
||||
let requiredBlocks = Math.floor((readCount + length) / 4096) - Math.floor(readCount / 4096)
|
||||
|
||||
let destVector = (ptrToDecode >= 0) ? 1 : -1
|
||||
|
||||
let completedReads = 0
|
||||
|
||||
// serial.println(`readBytes(${length}); readCount = ${readCount}`)
|
||||
@@ -74,7 +76,7 @@ function readBytes(length, ptrToDecode) {
|
||||
// serial.println(`Pulled a block (${thisBlockLen}); readCount = ${readCount}, completedReads = ${completedReads}, remaining = ${remaining}`)
|
||||
|
||||
// copy from read buffer to designated position
|
||||
sys.memcpy(-4097 - port*4096, ptr + completedReads, remaining)
|
||||
sys.memcpy(-4097 - port*4096, ptr + completedReads*destVector, remaining)
|
||||
|
||||
// increment readCount properly
|
||||
readCount += remaining
|
||||
@@ -90,7 +92,7 @@ function readBytes(length, ptrToDecode) {
|
||||
// serial.println(`Reusing a block (${thisBlockLen}); readCount = ${readCount}, completedReads = ${completedReads}`)
|
||||
|
||||
// copy from read buffer to designated position
|
||||
sys.memcpy(-4097 - port*4096 - padding, ptr + completedReads, thisBlockLen)
|
||||
sys.memcpy(-4097 - port*4096 - padding, ptr + completedReads*destVector, thisBlockLen)
|
||||
|
||||
// increment readCount properly
|
||||
readCount += thisBlockLen
|
||||
|
||||
Reference in New Issue
Block a user