{"record":{"id":"c6b5e3e3bd37616b","repo":"DrKLO/Telegram","slug":"sample-counts-do-not-match-lu-lu-n","errorCode":null,"errorMessage":"Sample counts do not match (%lu!=%lu).\\n","messagePattern":"Sample counts do not match \\(%lu!=%lu\\)\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/opus_compare.c","lineNumber":239,"sourceCode":"    fprintf(stderr,\"Error opening '%s'.\\n\",_argv[1]);\n    return EXIT_FAILURE;\n  }\n  fin2=fopen(_argv[2],\"rb\");\n  if(fin2==NULL){\n    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,","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/opus_compare.c#L221-L257","documentation":"The two input files have mismatched sample counts. After reading both, opus_compare asserts xlength == ylength*downsample. file1 is always read as stereo (2 channels) internally then optionally mono-mixed; file2 is read at nchannels. When the -r rate2 downsampling is active, file1 (48000-equivalent) must be 'downsample' times longer than file2.","triggerScenarios":"xlength != ylength*downsample. With default 48000 (downsample=1), both files must have identical sample counts. With -r 8000 (downsample=6), file1 must have 6x the samples of file2. Mismatch means the files weren't produced from the same source at the expected rates.","commonSituations":"Comparing a reference file against a decode that has a different length (trimming/padding at encode time); wrong -r rate making the expected ratio wrong; comparing files from different source material; off-by-one frame rounding at decode boundaries.","solutions":["Ensure both files derive from the same audio source and have lengths consistent with the chosen rate (file1 length == file2 length * downsample).","Verify the -r value matches the actual rate of file2.","Trim or pad the shorter file so the counts satisfy the ratio.","Re-decode file2 from the same source used for file1."],"exampleFix":"// before: file2 was decoded at 16000 but -r omitted (assumed 48000)\n./opus_compare ref48000.sw dec16000.sw\n# => Sample counts do not match (300000!=100000).\n\n// after: tell opus_compare the second file is 16000\n./opus_compare -r 16000 ref48000.sw dec16000.sw","handlingStrategy":"validation","validationCode":"// Verify sample-count ratio before the expensive analysis.\nif (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}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive both files from the same audio source so lengths are consistent.","Set -r to the actual rate of the second file so the expected ratio holds.","Trim or pad the shorter file to satisfy xlength == ylength*downsample."],"tags":["opus","opus-compare","sample-count","validation","audio","sample-rate","c"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}