diff options
author | roman.artiukhin <bahusdrive@gmail.com> | 2023-09-20 16:08:45 +0300 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2023-09-20 10:03:27 -0400 |
commit | 35150b83d488c9ebfa3e2d5ab4e3af78dc60ee0c (patch) | |
tree | 00eb8c3c8e6dcf462b7b8887304a7cabb15deac0 /lib | |
parent | 951e23951734b958d43f3e726b201fa2c52c2c01 (diff) | |
download | rockbox-35150b83d488c9ebfa3e2d5ab4e3af78dc60ee0c.tar.gz rockbox-35150b83d488c9ebfa3e2d5ab4e3af78dc60ee0c.zip |
Codecs: mp4: Fix sbr detections for some files
Use logic from libfaad/mp4.c AudioSpecificConfig2 for sbr detection
Fixes FS#12856
Change-Id: I235aa27830aa99f1307b303347f7affe7deafbe3
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbcodec/metadata/mp4.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/rbcodec/metadata/mp4.c b/lib/rbcodec/metadata/mp4.c index 7686165a0d..1540e93738 100644 --- a/lib/rbcodec/metadata/mp4.c +++ b/lib/rbcodec/metadata/mp4.c | |||
@@ -213,6 +213,7 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) | |||
213 | { | 213 | { |
214 | unsigned char buf[8] = {0}; | 214 | unsigned char buf[8] = {0}; |
215 | bool sbr = false; | 215 | bool sbr = false; |
216 | bool sbr_signaled = false; | ||
216 | 217 | ||
217 | lseek(fd, 4, SEEK_CUR); /* Version and flags. */ | 218 | lseek(fd, 4, SEEK_CUR); /* Version and flags. */ |
218 | read(fd, buf, 1); /* Verify ES_DescrTag. */ | 219 | read(fd, buf, 1); /* Verify ES_DescrTag. */ |
@@ -282,6 +283,7 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) | |||
282 | * Object type - 5 bits | 283 | * Object type - 5 bits |
283 | * Frequency index - 4 bits | 284 | * Frequency index - 4 bits |
284 | * Channel configuration - 4 bits | 285 | * Channel configuration - 4 bits |
286 | * Also see libfaad/mp4.c AudioSpecificConfig2 (consider using it instead of manual parsing) | ||
285 | */ | 287 | */ |
286 | bits = get_long_be(buf); | 288 | bits = get_long_be(buf); |
287 | type = bits >> 27; /* Object type - 5 bits */ | 289 | type = bits >> 27; /* Object type - 5 bits */ |
@@ -326,6 +328,7 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) | |||
326 | if (type == 5) | 328 | if (type == 5) |
327 | { | 329 | { |
328 | sbr = bits >> 31; | 330 | sbr = bits >> 31; |
331 | sbr_signaled = true; | ||
329 | 332 | ||
330 | if (sbr) | 333 | if (sbr) |
331 | { | 334 | { |
@@ -353,13 +356,11 @@ static bool read_mp4_esds(int fd, struct mp3entry* id3, uint32_t* size) | |||
353 | } | 356 | } |
354 | } | 357 | } |
355 | 358 | ||
356 | if (!sbr && (id3->frequency <= 24000) && (length <= 2)) | 359 | if (!sbr && !sbr_signaled && id3->frequency <= 24000) |
357 | { | 360 | { |
358 | /* Double the frequency for low-frequency files without a "long" | 361 | /* As stated in libfaad/mp4.c AudioSpecificConfig2: |
359 | * DecSpecificConfig header. The file may or may not contain SBR, | 362 | * no SBR signalled, this could mean either implicit signalling or no SBR in this file |
360 | * but here we guess it does if the header is short. This can | 363 | * MPEG specification states: assume SBR on files with samplerate <= 24000 Hz |
361 | * fail on some files, but it's the best we can do, short of | ||
362 | * decoding (parts of) the file. | ||
363 | */ | 364 | */ |
364 | id3->frequency *= 2; | 365 | id3->frequency *= 2; |
365 | sbr = true; | 366 | sbr = true; |