audio:short function to enqueue decoded mp2; playmov:no more choppy audio

This commit is contained in:
minjaesong
2023-01-21 19:43:11 +09:00
parent b60b5bada6
commit 99212adea3
7 changed files with 18 additions and 48 deletions

View File

@@ -83,7 +83,7 @@ function getRepeatCount(fnum) {
return (fnum == 1) ? 2 : 1
}
else if ("MP2fr" == AUDIOFORMAT) {
let r = Math.ceil((AUDIO_SAMPLE_SIZE*2 - audioSamplesWrote) / AUDIO_SAMPLE_SIZE) + ((fnum == 1) ? 1 : 0)
let r = Math.ceil((AUDIO_SAMPLE_SIZE - audioSamplesWrote) / AUDIO_SAMPLE_SIZE) + ((fnum == 1) ? 1 : 0)
return (fnum > TOTAL_FRAMES) ? Math.ceil(audioRemaining / MP2_PACKETSIZE) : r
}
}

View File

@@ -236,7 +236,10 @@ while (!stopPlay && seqread.getReadCount() < FILE_LENGTH) {
AUDIO_QUEUE_LENGTH += 1
audioQueue.push(sys.malloc(AUDIO_QUEUE_BYTES))
}
if (!mp2Initialised) audio.mp2Init()
if (!mp2Initialised) {
mp2Initialised = true
audio.mp2Init()
}
seqread.readBytes(readLength, SND_BASE_ADDR - 2368)
audio.mp2Decode()

View File

@@ -79,47 +79,7 @@ let bytes_left = FILE_SIZE
let decodedLength = 0
serial.println(`Frame size: ${FRAME_SIZE}`)
function decodeAndResample(inPtrL, inPtrR, outPtr, inputLen) {
// TODO resample
for (let k = 0; k < inputLen; k+=2) {
let sample1 = pcm.u16Tos16(sys.peek(inPtrL + k + 0) | (sys.peek(inPtrL + k + 1) << 8))
let sample2 = pcm.u16Tos16(sys.peek(inPtrR + k + 0) | (sys.peek(inPtrR + k + 1) << 8))
sys.poke(outPtr + k, pcm.s16Tou8(sample1))
sys.poke(outPtr + k + 1, pcm.s16Tou8(sample2))
}
}
function decodeEvent(frameSize, len) {
let t2 = sys.nanoTime()
// printdbg(`Audio queue size: ${audio.getPosition(0)}/${QUEUE_MAX}`)
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)
}
}
// decodeAndResample(samplePtrL, samplePtrR, decodePtr, len)
audio.putPcmDataByPtr(decodePtr, len, 0)
audio.setSampleUploadLength(0, len)
audio.startSampleUpload(0)
sys.sleep(10)
let decodingTime = (t2 - t1) / 1000000.0
bufRealTimeLen = (len) / 64000.0 * 1000
t1 = t2
// println(`Decoded ${decodedLength} bytes; target: ${bufRealTimeLen} ms, lag: ${decodingTime - bufRealTimeLen} ms`)
}
//serial.println(`Frame size: ${FRAME_SIZE}`)
con.curs_set(0)
@@ -203,9 +163,7 @@ try {
sys.sleep(bufRealTimeLen)
}
}
audio.putPcmDataByPtr(SND_BASE_ADDR - 64, 2304, 0)
audio.setSampleUploadLength(0, 2304)
audio.startSampleUpload(0)
audio.mp2UploadDecoded(0)
sys.sleep(10)