jukebox
All repositories: gitoria
2.4 KB
// lib/mpeg.hl — the duration of an mp3 from its first audio frame: the Xing/Info or VBRI header when there is one// (variable bit rate), else the bit rate of the first frame and the length of the audio (constant bit rate).// Input: a Bytes that holds the first audio frame, where to start looking, and how many bytes of audio the file has.static bitrates = {'1-1' = [0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448]'1-2' = [0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384]'1-3' = [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]'2-1' = [0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256]'2-2' = [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160]'2-3' = [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160]}static sampleRates = { '3' = [44100, 48000, 32000] '2' = [22050, 24000, 16000] '0' = [11025, 12000, 8000] }static hasText = (b, at, t) => {let k = 0while (k < t.length) {if (at + k >= b.length || b[at + k] != t.charCodeAt(k)) { return false }k = k + 1}return true}// seconds (whole), or null when no valid frame header is found within 4096 bytes from `start`static mp3Seconds = (b, start, audioBytes) => {let i = startlet stop = start + 4096if (stop > b.length - 4) { stop = b.length - 4 }while (i < stop) {if (b[i] == 255 && (b[i + 1] & 224) == 224) {vbits = (b[i + 1] >> 3) & 3lbits = (b[i + 1] >> 1) & 3bidx = (b[i + 2] >> 4) & 15sidx = (b[i + 2] >> 2) & 3if (vbits != 1 && lbits != 0 && bidx != 0 && bidx != 15 && sidx != 3) {layer = 4 - lbitsmpeg1 = vbits == 3table = bitrates[(mpeg1 ? '1' : '2') + '-' + layer]kbps = table[bidx]rate = sampleRates['' + vbits][sidx]let spf = 1152if (layer == 1) { spf = 384 }else if (layer == 3 && !mpeg1) { spf = 576 }mono = ((b[i + 3] >> 6) & 3) == 3side = mpeg1 ? (mono ? 17 : 32) : (mono ? 9 : 17)x = i + 4 + sideif (hasText(b, x, 'Xing') || hasText(b, x, 'Info')) {if ((b[x + 7] & 1) != 0) {frames = b[x + 8] * 16777216 + b[x + 9] * 65536 + b[x + 10] * 256 + b[x + 11]return frames * spf / rate}}if (hasText(b, i + 36, 'VBRI')) {frames = b[i + 36 + 14] * 16777216 + b[i + 36 + 15] * 65536 + b[i + 36 + 16] * 256 + b[i + 36 + 17]return frames * spf / rate}return audioBytes * 8 / (kbps * 1000)}}i = i + 1}return null}
Branches
Latest commits
- df8f5205Records: jukebox#19-21, #11 closedmre
- b7a4e692Records: hybriel#298mre
- 9bcbb017Records: day38b waits for day39 fixmre
- f80504e1Records: day38b repro sentmre
- 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
- 68aace7fRecords: mission 003 day38bmre
- d105d8a9Records: mpackdb integrity check cleanmre
- 6e980c53Records: mpackdb rule refinementmre
- 6d335ac4Records: storage copy rulingmre
- 7eb2898dRecords: mpackdb second-opener rule until day38mre
- b011f98eRecords: style form live on day35mre
- 60d90cb2Records: L1 woken for the restartmre
- 75ae544fRecords: restart waits for the connection to closemre
- e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
- f2b5db98styles: format styles with nested rules and bare queriesmre
- f036bab4search: format styles with nested rules and bare queriesmre
- ef9a9d4asongs: format styles with nested rules and bare queriesmre
- f22f9aacmain: format styles with nested rules and bare queriesmre
- f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
- d56e5054Sync theme and shared tokens from layouts 17e0f03mre