When opening a PCM wave file for reading, we aren't tracking the
frequency of the opened file, so we treat 16khz files as 8khz and do
half reads.
This patch also cleans up some of the data types and an unnecessarily
complex `if` expression.
ASTERISK-26613 #close
Reported by: Vitaly K
Change-Id: I05f8b263058dc573ea8ffe0c62e7964506e11815
@ -92,7 +91,7 @@ static int check_header_fmt(FILE *f, int hsize, int hz)
return-1;
}
if(ltohs(format)!=1){
ast_log(LOG_WARNING,"Not a supported wav file format (%d). Only PCM encoded, 16 bit, mono, 8kHz files are supported with a lowercase '.wav' extension.\n",ltohs(format));
ast_log(LOG_WARNING,"Not a supported wav file format (%d). Only PCM encoded, 16 bit, mono, 8kHz/16kHz files are supported with a lowercase '.wav' extension.\n",ltohs(format));
return-1;
}
if(fread(&chans,1,2,f)!=2){
@ -107,10 +106,9 @@ static int check_header_fmt(FILE *f, int hsize, int hz)
ast_log(LOG_WARNING,"Read failed (freq)\n");
return-1;
}
if(((ltohl(freq)!=8000)&&(ltohl(freq)!=16000))||
((ltohl(freq)==8000)&&(hz!=8000))||
((ltohl(freq)==16000)&&(hz!=16000))){
ast_log(LOG_WARNING,"Unexpected frequency mismatch %d (expecting %d)\n",ltohl(freq),hz);
freq=ltohl(freq);
if((freq!=8000&&freq!=16000)||freq!=hz){
ast_log(LOG_WARNING,"Unexpected frequency mismatch %d (expecting %d)\n",freq,hz);
return-1;
}
/* Ignore the byte frequency */
@ -323,9 +321,15 @@ static int wav_open(struct ast_filestream *s)
/* We don't have any header to read or anything really, but