{"record":{"id":"82a02a5118e1c9d8","repo":"DrKLO/Telegram","slug":"test-vector-fails-n","errorCode":null,"errorMessage":"Test vector FAILS\\n","messagePattern":"Test vector FAILS\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/opus_compare.c","lineNumber":372,"sourceCode":"          Eb+=im;\n        }\n      }\n      Eb /= (BANDS[bi+1]-BANDS[bi])*nchannels;\n      Ef += Eb*Eb;\n    }\n    /*Using a fixed normalization value means we're willing to accept slightly\n       lower quality for lower sampling rates.*/\n    Ef/=NBANDS;\n    Ef*=Ef;\n    err+=Ef*Ef;\n  }\n  free(xb);\n  free(X);\n  free(Y);\n  err=pow(err/nframes,1.0/16);\n  Q=100*(1-0.5*log(1+err)/log(1.13));\n  if(Q<0){\n    fprintf(stderr,\"Test vector FAILS\\n\");\n    fprintf(stderr,\"Internal weighted error is %f\\n\",err);\n    return EXIT_FAILURE;\n  }\n  else{\n    fprintf(stderr,\"Test vector PASSES\\n\");\n    fprintf(stderr,\n     \"Opus quality metric: %.1f %% (internal weighted error is %f)\\n\",Q,err);\n    return EXIT_SUCCESS;\n  }\n}\n","sourceCodeStart":354,"sourceCodeEnd":383,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/opus_compare.c#L354-L383","documentation":"After computing a psychoacoustic error metric across all analysis frames, the tool derives a quality score Q = 100*(1 - 0.5*log(1+err)/log(1.13)). The error `err` is the 16th-root of the accumulated per-frame weighted noise-to-mask ratio across 21 Bark bands. If Q < 0, the degraded signal is so different from the reference that it fails the quality threshold, and the tool returns EXIT_FAILURE. A passing test requires Q >= 0, which corresponds to an internal weighted error below ~0.13.","triggerScenarios":"The spectral error ratio Y/X (degraded energy divided by reference energy) is consistently large across frames and bands, driving `err` above the threshold. This occurs with severe encoding artifacts, wrong decoder output, comparing files at mismatched sample rates without the -r flag, or a genuine Opus codec regression. The cross-over damping at bins 79-81 (line 352-353) shows the metric is tuned for the SILK/CELT boundary.","commonSituations":"Opus CI regression where a code change degrades quality; testing at extremely low bitrates where artifacts are expected; comparing a stereo reference against a mono degraded file without the -s flag; decoder bug producing silence or noise; encoding with wrong application mode (VOIP vs audio) causing different band allocation.","solutions":["Check the internal weighted error printed on the next line — if it is only slightly above threshold, investigate minor regressions; if very high, suspect a fundamental mismatch.","Verify both files use the same channel configuration (use -s for stereo comparisons).","Verify the sample rate matches the actual encode rate via -r; a missing -r causes the sample-count check at line 238 to silently pass when rate=48000 default is correct, but frequency alignment will be wrong for non-48kHz files.","Re-encode the degraded file with the same opus_demo parameters used for passing baselines and compare.","If the quality drop is expected (e.g., lower bitrate), adjust the test expectation rather than treating it as a bug."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// In a test harness, capture opus_compare stderr and parse the Q score\n// to decide pass/fail with a configurable threshold rather than relying\n// solely on exit code (which fails at Q<0).\nint run_quality_check(const char *ref, const char *deg, int rate) {\n    char cmd[1024];\n    snprintf(cmd, sizeof(cmd), \"opus_compare %s %s %s 2>&1\",\n             rate > 0 ? \"-r\" : \"\", rate > 0 ? \"%d\" : \"\", ref, deg);\n    // ... run and parse 'Opus quality metric: NN.N %' from output\n    // treat Q below your threshold (e.g., 50%%) as failure\n    return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the -s flag when comparing stereo files and omit it for mono.","Always pass -r <rate> when the degraded file is not 48 kHz.","Establish a baseline Q score with known-good encoder output before making codec changes.","Use the internal weighted error value to set a custom threshold in CI rather than relying on the binary pass/fail."],"tags":["opus","audio","quality-metric","test-tool","regression"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}