MCPcopy Create free account
hub / github.com/zhuker/lamejs / sync_buffer

Method sync_buffer

src/main/java/mpg/Interface.java:276–351  ·  view source on GitHub ↗
(mpstr_tag mp, boolean free_match)

Source from the content-addressed store, hash-verified

274 }
275
276 int
277 sync_buffer(mpstr_tag mp, boolean free_match)
278 {
279 /* traverse mp structure without modifying pointers, looking
280 * for a frame valid header.
281 * if free_format, valid header must also have the same
282 * samplerate.
283 * return number of bytes in mp, before the header
284 * return -1 if header is not found
285 */
286 int b[] = { 0, 0, 0, 0 };
287 int i, pos;
288 boolean h;
289 buf buf = mp.tail;
290 if (null==buf)
291 return -1;
292
293 pos = buf.pos;
294 for (i = 0; i < mp.bsize; i++) {
295 /* get 4 bytes */
296
297 b[0] = b[1];
298 b[1] = b[2];
299 b[2] = b[3];
300 while (pos >= buf.size) {
301 buf = buf.next;
302 pos = buf.pos;
303 }
304 b[3] = buf.pnt[pos] & 0xff;
305 ++pos;
306
307 if (i >= 3) {
308 Frame fr = mp.fr;
309 long head;
310
311 head = b[0];
312 head <<= 8;
313 head |= b[1];
314 head <<= 8;
315 head |= b[2];
316 head <<= 8;
317 head |= b[3];
318 h = common.head_check(head, fr.lay);
319
320 if (h && free_match) {
321 /* just to be even more thorough, match the sample rate */
322 int mode, stereo, sampling_frequency, lsf;
323 boolean mpeg25;
324
325 if ((head & (1 << 20))!=0) {
326 lsf = (head & (1 << 19)) !=0 ? 0x0 : 0x1;
327 mpeg25 = false;
328 }
329 else {
330 lsf = 1;
331 mpeg25 = true;
332 }
333

Callers 1

decodeMP3_clipchoiceMethod · 0.95

Calls 1

head_checkMethod · 0.80

Tested by

no test coverage detected