ws-audio: MP3 layer III encoder (Encode3: shine-style CBR, MPEG-1/2/2.5, mono/stereo/joint MS, global-gain rate loop, region/table choice, count1 A/B) + MP2 layer II encoder (Encode2: standard alloc tables, greedy noise allocation, grouping), shared polyphase Analysis, EncTables (PDMP3 public-domain window + Huffman trees -> codeword tables); mp3 init encode() with ID3v2.4; fixtures decode with ffmpeg + lame (no errors, SNR floors); bench lines
This commit is contained in:
1 parent
4dbd236962
commit
e817053a40
14 files changed
+1859
-12
No files matched your search
@@ -133,9 +133,13 @@ def ffdecode(ctx, data, fmt=None, ext="bin", extra=None):
|
||||
return rate, ch, from_f32le(raw)
|
||||
|
||||
|
||||
def snr(ref, test, ch, max_lag=0, skip=0):
|
||||
def snr(ref, test, ch, max_lag=0, skip=0, hints=None):
|
||||
"""SNR (dB) of test vs ref over their common frames (after `skip` frames), best lag in [-max_lag, max_lag]
|
||||
(test[i + lag] ~ ref[i]). Returns (snr, lag)."""
|
||||
(test[i + lag] ~ ref[i]). hints: lags tried first; the search runs only when none gives 10 dB. Returns (snr, lag)."""
|
||||
if hints:
|
||||
got = max(snr(ref, test, ch, 0, skip, None) if h == 0 else _snr_at(ref, test, ch, h, skip) for h in hints)
|
||||
if got[0] >= 10:
|
||||
return got
|
||||
best = (-1e9, 0)
|
||||
nref, ntest = len(ref) // ch, len(test) // ch
|
||||
lags = range(-max_lag, max_lag + 1) if max_lag else [0]
|
||||
@@ -170,6 +174,20 @@ def snr(ref, test, ch, max_lag=0, skip=0):
|
||||
return best
|
||||
|
||||
|
||||
def _snr_at(ref, test, ch, lag, skip):
|
||||
sig = err = 0.0
|
||||
nref, ntest = len(ref) // ch, len(test) // ch
|
||||
for i in range(skip, nref):
|
||||
j = i + lag
|
||||
if 0 <= j < ntest:
|
||||
for c in range(ch):
|
||||
a = ref[i * ch + c]
|
||||
e = a - test[j * ch + c]
|
||||
sig += a * a
|
||||
err += e * e
|
||||
return (200.0 if err == 0 else (10 * math.log10(sig / err) if sig > 0 else -200.0), lag)
|
||||
|
||||
|
||||
def luau_bin():
|
||||
p = shutil.which("luau")
|
||||
if p:
|
||||
|
||||
Reference in new issue
Block a user