History

mp3: skip initial xing/info frame [bug #239]

If a stream starts with a xing/info frame, this should be skipped. Otherwise a frame's worth of silence will be inserted at the start of the output.

Mans Rullgard committed 6 years ago

Commit a0905951 parent bb389341 file · +25 −5Browse files

Unified · Split

src/mp3.c+25−5
@@ -363,6 +363,24 @@ static int sox_mp3_inputtag(sox_format_t * ft) · 362 unmodified lines
363363 return rc;
364364 }
365365
366+static sox_bool sox_mp3_vbrtag(sox_format_t *ft)
367+{
368+ priv_t *p = ft->priv;
369+ struct mad_bitptr *anc = &p->Stream.anc_ptr;
370+
371+ if (p->Frame.header.layer != MAD_LAYER_III)
372+ return sox_false;
373+
374+ if (p->Stream.anc_bitlen < 32)
375+ return sox_false;
376+
377+ if (!memcmp(anc->byte, "Xing", 4) ||
378+ !memcmp(anc->byte, "Info", 4))
379+ return sox_true;
380+
381+ return sox_false;
382+}
383+
366384 static int startread(sox_format_t * ft)
367385 {
368386 priv_t *p = (priv_t *) ft->priv;
@@ -457,18 +475,20 @@ static int startread(sox_format_t * ft) · 88 unmodified lines
457475 return SOX_EOF;
458476 }
459477
460− p->FrameCount=1;
461−
462− p->mad_timer_add(&p->Timer,p->Frame.header.duration);
463− p->mad_synth_frame(&p->Synth,&p->Frame);
464478 ft->signal.precision = MP3_MAD_PRECISION;
465− ft->signal.rate=p->Synth.pcm.samplerate;
479+ ft->signal.rate=p->Frame.header.samplerate;
466480 if (ignore_length)
467481 ft->signal.length = SOX_UNSPEC;
468482 else {
469483 ft->signal.length *= ft->signal.channels; /* Keep separate from line above! */
470484 }
471485
486+ if (!sox_mp3_vbrtag(ft))
487+ p->Stream.next_frame = p->Stream.this_frame;
488+
489+ p->mad_frame_init(&p->Frame);
490+ sox_mp3_input(ft);
491+
472492 p->cursamp = 0;
473493
474494 return SOX_SUCCESS;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t