cff531af |
1 | /* |
2 | * PicoDrive |
3 | * (C) notaz, 2010 |
4 | * |
5 | * This work is licensed under the terms of MAME license. |
6 | * See COPYING file in the top-level directory. |
7 | */ |
7c18e34a |
8 | #include "mp3.h" |
9 | |
10 | int mp3_find_sync_word(const unsigned char *buf, int size) |
11 | { |
12 | const unsigned char *p, *pe; |
13 | |
14 | /* find byte-aligned syncword - need 12 (MPEG 1,2) or 11 (MPEG 2.5) matching bits */ |
15 | for (p = buf, pe = buf + size - 3; p <= pe; p++) |
16 | { |
17 | int pn; |
18 | if (p[0] != 0xff) |
19 | continue; |
20 | pn = p[1]; |
21 | if ((pn & 0xf8) != 0xf8 || // currently must be MPEG1 |
22 | (pn & 6) == 0) { // invalid layer |
23 | p++; continue; |
24 | } |
25 | pn = p[2]; |
26 | if ((pn & 0xf0) < 0x20 || (pn & 0xf0) == 0xf0 || // bitrates |
27 | (pn & 0x0c) != 0) { // not 44kHz |
28 | continue; |
29 | } |
30 | |
31 | return p - buf; |
32 | } |
33 | |
34 | return -1; |
35 | } |
36 | |