DrKLO/Telegram · warning
Sampling rate must be 8000, 12000, 16000, 24000, or 48000\n
Error message
Sampling rate must be 8000, 12000, 16000, 24000, or 48000\n
What it means
The -r rate2 value is not one of the five Opus-supported sample rates. opus_compare only operates at 8000, 12000, 16000, 24000, or 48000 Hz because those are the only rates for which the psychoacoustic band tables (ybands) are defined.
Source
Thrown at TMessagesProj/jni/opus/src/opus_compare.c:205
int max_compare;
if(_argc<3||_argc>6){
fprintf(stderr,"Usage: %s [-s] [-r rate2] <file1.sw> <file2.sw>\n",
_argv[0]);
return EXIT_FAILURE;
}
nchannels=1;
if(strcmp(_argv[1],"-s")==0){
nchannels=2;
_argv++;
}
rate=48000;
ybands=NBANDS;
yfreqs=NFREQS;
downsample=1;
if(strcmp(_argv[1],"-r")==0){
rate=atoi(_argv[2]);
if(rate!=8000&&rate!=12000&&rate!=16000&&rate!=24000&&rate!=48000){
fprintf(stderr,
"Sampling rate must be 8000, 12000, 16000, 24000, or 48000\n");
return EXIT_FAILURE;
}
downsample=48000/rate;
switch(rate){
case 8000:ybands=13;break;
case 12000:ybands=15;break;
case 16000:ybands=17;break;
case 24000:ybands=19;break;
}
yfreqs=NFREQS/downsample;
_argv+=2;
}
fin1=fopen(_argv[1],"rb");
if(fin1==NULL){
fprintf(stderr,"Error opening '%s'.\n",_argv[1]);
return EXIT_FAILURE;
}View on GitHub (pinned to 45ab8f4308)
Solutions
- Use one of the five supported rates with -r.
- Resample the input .sw files to a supported rate before comparing.
- Omit -r entirely to default to 48000.
Example fix
// before ./opus_compare -r 44100 file1.sw file2.sw // after ./opus_compare -r 48000 file1.sw file2.sw
Defensive patterns
Strategy: validation
Validate before calling
// Validate the rate against the allowed set.
if (rate!=8000&&rate!=12000&&rate!=16000&&rate!=24000&&rate!=48000) {
fprintf(stderr, "Sampling rate must be 8000, 12000, 16000, 24000, or 48000\n");
return EXIT_FAILURE;
} Prevention
- Resample inputs to one of the five supported rates before comparing.
- Omit -r to default to 48000.
- Validate the -r argument is numeric before atoi.
When it happens
Trigger: rate (from atoi(_argv[2]) after -r) is not in {8000,12000,16000,24000,48000}. The tool then exits before opening any file. The default rate is 48000 if -r is omitted.
Common situations: Passing a common-but-unsupported rate like 22050 or 44100; passing a non-numeric string that atoi turns into 0; typo in the rate.
Related errors
- Sample counts do not match (%lu!=%lu).\n
- failed to create a mode\n
- bytes per packet must be between 0 and %d\n
- Failed to create the encoder: %s\n
- Failed to create the decoder: %s\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/7d88ed8a0e450f7b.
Report an issue: GitHub.