From 5be05e8eec6aca09593aa792ef05b24b56dc91ce Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 25 Jan 2023 21:00:15 +0900 Subject: [PATCH] doc: more details in mp2 coding --- assets/disk0/tvdos/include/seqread.js | 16 +++++++++++++--- terranmon.txt | 9 +++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/assets/disk0/tvdos/include/seqread.js b/assets/disk0/tvdos/include/seqread.js index c8eb3c2..73885df 100644 --- a/assets/disk0/tvdos/include/seqread.js +++ b/assets/disk0/tvdos/include/seqread.js @@ -46,6 +46,7 @@ function prepare(fullPath) { function readBytes(length, ptrToDecode) { if (length <= 0) return +// serial.println(`readBytes(${length}); readCount = ${readCount}`) let ptr = (ptrToDecode === undefined) ? sys.malloc(length) : ptrToDecode let requiredBlocks = Math.floor((readCount + length) / 4096) - Math.floor(readCount / 4096) @@ -53,7 +54,6 @@ function readBytes(length, ptrToDecode) { let completedReads = 0 -// serial.println(`readBytes(${length}); readCount = ${readCount}`) for (let bc = 0; bc < requiredBlocks + 1; bc++) { if (completedReads >= length) break @@ -119,10 +119,20 @@ function readShort() { return i } +function readOneByte() { + let b = readBytes(1) + let i = sys.peek(b) + sys.free(b) + return i +} + function readFourCC() { let b = readBytes(4) - let s = String.fromCharCode(sys.peek(b), sys.peek(b+1), sys.peek(b+2), sys.peek(b+3)) + let a = [sys.peek(b), sys.peek(b+1), sys.peek(b+2), sys.peek(b+3)] sys.free(b) + let s = String.fromCharCode.apply(null, a) +// serial.println(`readFourCC: ${s}; ${a.map(it=>"0x"+it.toString(16).padStart(2,'0')).join()}`) + if (s.length != 4) throw Error(`FourCC is not 4 characters long (${s}; ${a.map(it=>"0x"+it.toString(16).padStart(2,'0')).join()})`) return s } @@ -145,4 +155,4 @@ function getReadCount() { return readCount } -exports = {fileHeader, prepare, readBytes, readInt, readShort, readFourCC, readString, skip, getReadCount} \ No newline at end of file +exports = {fileHeader, prepare, readBytes, readInt, readShort, readFourCC, readOneByte, readString, skip, getReadCount} \ No newline at end of file diff --git a/terranmon.txt b/terranmon.txt index 86cb949..b5750ab 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -415,7 +415,7 @@ Packet Types - 32 | 0 | 1 48 | 2 | 3 56 | 4 | 5 - 64 | 6 | 7 (libtwolame does not allow bitrate lower than this on 32 kHz) + 64 | 6 | 7 (libtwolame does not allow bitrate lower than this on 32 kHz stereo) 80 | 8 | 9 96 | 10 | 11 112 | 12 | 13 @@ -429,7 +429,12 @@ Packet Types - Add 128 to the resulting number if the frame has a padding bit (should not happen on 32kHz sampling rate) Special value of 255 may indicate some errors - To encode an audio to compliant format, use ffmpeg: ffmpeg -i -acodec libtwolame -b:a k -ar 32000 + To encode an audio to compliant format, use ffmpeg: ffmpeg -i -acodec libtwolame -psymodel 4 -b:a k -ar 32000 + Rationale: + -acodec libtwolame : ffmpeg has two mp2 encoders, and libtwolame produces vastly higher quality audio + -psymodel 4 : use alternative psychoacoustic model -- the default model (3) tends to insert "clunk" sounds throughout the audio + -b:a : 256k is recommended for high quality audio (trust me, you don't need 384k) + -ar 32000 : resample the audio to 32kHz, the sampling rate of the TSVM soundcard GLOBAL TYPE 0 Packet - uint32 SIZE OF FRAMEDATA