···213213{
214214 unsigned char buf[8] = {0};
215215 bool sbr = false;
216216+ bool sbr_signaled = false;
216217217218 lseek(fd, 4, SEEK_CUR); /* Version and flags. */
218219 read(fd, buf, 1); /* Verify ES_DescrTag. */
···282283 * Object type - 5 bits
283284 * Frequency index - 4 bits
284285 * Channel configuration - 4 bits
286286+ * Also see libfaad/mp4.c AudioSpecificConfig2 (consider using it instead of manual parsing)
285287 */
286288 bits = get_long_be(buf);
287289 type = bits >> 27; /* Object type - 5 bits */
···326328 if (type == 5)
327329 {
328330 sbr = bits >> 31;
331331+ sbr_signaled = true;
329332330333 if (sbr)
331334 {
···353356 }
354357 }
355358356356- if (!sbr && (id3->frequency <= 24000) && (length <= 2))
359359+ if (!sbr && !sbr_signaled && id3->frequency <= 24000)
357360 {
358358- /* Double the frequency for low-frequency files without a "long"
359359- * DecSpecificConfig header. The file may or may not contain SBR,
360360- * but here we guess it does if the header is short. This can
361361- * fail on some files, but it's the best we can do, short of
362362- * decoding (parts of) the file.
361361+ /* As stated in libfaad/mp4.c AudioSpecificConfig2:
362362+ * no SBR signalled, this could mean either implicit signalling or no SBR in this file
363363+ * MPEG specification states: assume SBR on files with samplerate <= 24000 Hz
363364 */
364365 id3->frequency *= 2;
365366 sbr = true;