{"record":{"id":"7ee0c47b61f59d77","repo":"DrKLO/Telegram","slug":"insufficient-sample-data-lu-i-n","errorCode":null,"errorMessage":"Insufficient sample data (%lu<%i).\\n","messagePattern":"Insufficient sample data \\(%lu<(.+?)\\)\\.\\\\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/opus_compare.c","lineNumber":244,"sourceCode":"    fprintf(stderr,\"Error opening '%s'.\\n\",_argv[2]);\n    fclose(fin1);\n    return EXIT_FAILURE;\n  }\n  /*Read in the data and allocate scratch space.*/\n  xlength=read_pcm16(&x,fin1,2);\n  if(nchannels==1){\n    for(xi=0;xi<xlength;xi++)x[xi]=.5*(x[2*xi]+x[2*xi+1]);\n  }\n  fclose(fin1);\n  ylength=read_pcm16(&y,fin2,nchannels);\n  fclose(fin2);\n  if(xlength!=ylength*downsample){\n    fprintf(stderr,\"Sample counts do not match (%lu!=%lu).\\n\",\n     (unsigned long)xlength,(unsigned long)ylength*downsample);\n    return EXIT_FAILURE;\n  }\n  if(xlength<TEST_WIN_SIZE){\n    fprintf(stderr,\"Insufficient sample data (%lu<%i).\\n\",\n     (unsigned long)xlength,TEST_WIN_SIZE);\n    return EXIT_FAILURE;\n  }\n  nframes=(xlength-TEST_WIN_SIZE+TEST_WIN_STEP)/TEST_WIN_STEP;\n  xb=(float *)opus_malloc(nframes*NBANDS*nchannels*sizeof(*xb));\n  X=(float *)opus_malloc(nframes*NFREQS*nchannels*sizeof(*X));\n  Y=(float *)opus_malloc(nframes*yfreqs*nchannels*sizeof(*Y));\n  /*Compute the per-band spectral energy of the original signal\n     and the error.*/\n  band_energy(xb,X,BANDS,NBANDS,x,nchannels,nframes,\n   TEST_WIN_SIZE,TEST_WIN_STEP,1);\n  free(x);\n  band_energy(NULL,Y,BANDS,ybands,y,nchannels,nframes,\n   TEST_WIN_SIZE/downsample,TEST_WIN_STEP/downsample,downsample);\n  free(y);\n  for(xi=0;xi<nframes;xi++){\n    /*Frequency masking (low to high): 10 dB/Bark slope.*/\n    for(bi=1;bi<NBANDS;bi++){","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/opus_compare.c#L226-L262","documentation":"opus_compare is a quality-assessment tool that compares a 48 kHz stereo reference PCM16 file against a degraded file at a possibly lower sample rate. After reading both files, it checks that the reference has at least TEST_WIN_SIZE (480) samples. With fewer samples than the analysis window, the per-band spectral energy computation in band_energy() cannot produce even one analysis frame, so the tool aborts with EXIT_FAILURE. The 480-sample floor corresponds to 10 ms of audio at 48 kHz.","triggerScenarios":"The reference file (file1) contains fewer than 480 stereo sample-pairs after read_pcm16 returns. This happens when the raw PCM16 input is truncated, shorter than ~1920 bytes of stereo data, or in a format read_pcm16 does not expect (it reads raw little-endian int16, not WAV/OGUS containers). A corrupted file that causes fread to return 0 early in read_pcm16 also produces a short xlength.","commonSituations":"Using very short audio clips as Opus regression test vectors; generating the reference file with a different tool that writes a WAV header (opus_compare expects headerless raw PCM); file truncation during network copy or incomplete encode; accidentally passing the degraded file as file1 when it is at a much lower sample rate without the -r flag.","solutions":["Ensure the reference input is raw PCM16 (signed 16-bit little-endian, no header) with at least 480 stereo frames (~1920 bytes).","Verify file1 is the 48 kHz reference and file2 is the degraded output; swap them if reversed.","If the degraded file is at a lower sample rate, pass -r <rate> so downsample is computed correctly and the sample-count check (xlength == ylength*downsample) holds.","Generate test vectors with opus_demo at sufficient duration (at least 1 second of audio is safe)."],"exampleFix":"// before: short or wrong-format reference\nopus_compare ref_short.sw degraded.sw\n// after: use a properly-sized raw PCM16 reference\nopus_compare ref_48k_stereo.sw degraded.sw\n// verify minimum size before running:\n//   ref must be >= 480 * 2 channels * 2 bytes = 1920 bytes","handlingStrategy":"validation","validationCode":"// Before running opus_compare, verify file size meets minimum\n// 480 stereo frames * 2 channels * 2 bytes = 1920 bytes minimum\n#include <sys/stat.h>\nint check_min_samples(const char *path) {\n    struct stat st;\n    if (stat(path, &st) != 0) return -1;\n    size_t min_bytes = 480 * 2 * 2; // TEST_WIN_SIZE * 2ch * sizeof(int16)\n    return (st.st_size >= (off_t)min_bytes) ? 0 : -1;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always generate test vectors with at least 1 second of audio to stay well above the 480-sample floor.","Verify the input is raw PCM16 (no WAV header) using `file` or checking the first bytes for RIFF.","In CI scripts, add a pre-check on file size before invoking opus_compare."],"tags":["opus","audio","test-tool","input-validation","pcm"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}