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

@@ -67,7 +67,7 @@ class SequentialFileBuffer {
let filebuf = new SequentialFileBuffer(_G.shell.resolvePathInput(exec_args[1]).full)
const FILE_SIZE = filebuf.length - 100
const FILE_SIZE = filebuf.length// - 100
let FRAME_SIZE = audio.mp2GetInitialFrameSize(filebuf.fileHeader)
@@ -182,7 +182,7 @@ let bufRealTimeLen = 36
let stopPlay = false
let errorlevel = 0
try {
while (bytes_left >= 0 && !stopPlay) {
while (bytes_left > 0 && !stopPlay) {
if (interactive) {
sys.poke(-40, 1)
@@ -194,9 +194,6 @@ try {
printPlayBar()
filebuf.readBytes(FRAME_SIZE, frame)
bytes_left -= FRAME_SIZE
decodedLength += FRAME_SIZE
let [frameSize, samples] = audio.mp2DecodeFrame(mp2context, frame, true, samplePtrL, samplePtrR)
if (frameSize) {
// println(samples)
@@ -204,6 +201,9 @@ try {
decodeEvent(frameSize, samples)
FRAME_SIZE = frameSize // JUST IN CASE when a vbr mp2 is not filtered and played thru
}
bytes_left -= FRAME_SIZE
decodedLength += FRAME_SIZE
}
}
catch (e) {

View File

@@ -30,10 +30,7 @@ function s16Tou8(i) {
function u16Tos16(i) { return (i > 32767) ? i - 65536 : i }
function randomRound(k) {
let rnd = (Math.random() + Math.random()) / 2.0 // this produces triangular distribution
if (rnd < (k - (k|0)))
return Math.ceil(k)
else
return Math.floor(k)
return (rnd < (k - (k|0))) ? Math.ceil(k) : Math.floor(k)
}
function lerp(start, end, x) {
return (1 - x) * start + x * end