Lines Matching refs:mp

53 InitMP3(PMPSTR mp)
59 if (mp) {
60 memset(mp, 0, sizeof(MPSTR));
62 mp->framesize = 0;
63 mp->num_frames = 0;
64 mp->enc_delay = -1;
65 mp->enc_padding = -1;
66 mp->vbr_header = 0;
67 mp->header_parsed = 0;
68 mp->side_parsed = 0;
69 mp->data_parsed = 0;
70 mp->free_format = 0;
71 mp->old_free_format = 0;
72 mp->ssize = 0;
73 mp->dsize = 0;
74 mp->fsizeold = -1;
75 mp->bsize = 0;
76 mp->head = mp->tail = NULL;
77 mp->fr.single = -1;
78 mp->bsnum = 0;
79 mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
80 mp->bitindex = 0;
81 mp->synth_bo = 1;
82 mp->sync_bitstream = 1;
84 mp->report_dbg = &lame_report_def;
85 mp->report_err = &lame_report_def;
86 mp->report_msg = &lame_report_def;
94 ExitMP3(PMPSTR mp)
96 if (mp) {
99 b = mp->tail;
110 addbuf(PMPSTR mp, unsigned char *buf, int size)
116 lame_report_fnc(mp->report_err, "hip: addbuf() Out of memory!\n");
127 nbuf->prev = mp->head;
130 if (!mp->tail) {
131 mp->tail = nbuf;
134 mp->head->next = nbuf;
137 mp->head = nbuf;
138 mp->bsize += size;
144 remove_buf(PMPSTR mp)
146 struct buf *buf = mp->tail;
148 mp->tail = buf->next;
149 if (mp->tail)
150 mp->tail->prev = NULL;
152 mp->tail = mp->head = NULL;
161 read_buf_byte(PMPSTR mp)
168 pos = mp->tail->pos;
169 while (pos >= mp->tail->size) {
170 remove_buf(mp);
171 if (!mp->tail) {
172 lame_report_fnc(mp->report_err, "hip: Fatal error! tried to read past mp buffer\n");
175 pos = mp->tail->pos;
178 b = mp->tail->pnt[pos];
179 mp->bsize--;
180 mp->tail->pos++;
189 read_head(PMPSTR mp)
193 head = read_buf_byte(mp);
195 head |= read_buf_byte(mp);
197 head |= read_buf_byte(mp);
199 head |= read_buf_byte(mp);
201 mp->header = head;
208 copy_mp(PMPSTR mp, int size, unsigned char *ptr)
212 while (len < size && mp->tail) {
214 int blen = mp->tail->size - mp->tail->pos;
221 memcpy(ptr + len, mp->tail->pnt + mp->tail->pos, (size_t) nlen);
223 mp->tail->pos += nlen;
224 mp->bsize -= nlen;
225 if (mp->tail->pos == mp->tail->size) {
226 remove_buf(mp);
235 traverse mp data structure without changing it
247 check_vbr_header(PMPSTR mp, int bytes)
250 struct buf *buf = mp->tail;
278 mp->vbr_header = GetVbrTag(&pTagData, xing);
279 if (mp->vbr_header) {
280 mp->num_frames = pTagData.frames;
281 mp->enc_delay = pTagData.enc_delay;
282 mp->enc_padding = pTagData.enc_padding;
284 /* lame_report_fnc(mp->report_msg,"hip: delays: %i %i \n",mp->enc_delay,mp->enc_padding); */
285 /* lame_report_fnc(mp->report_msg,"hip: Xing VBR header dectected. MP3 file has %i frames\n", pTagData.frames); */
298 sync_buffer(PMPSTR mp, int free_match)
300 /* traverse mp structure without modifying pointers, looking
304 * return number of bytes in mp, before the header
309 struct buf *buf = mp->tail;
314 for (i = 0; i < mp->bsize; i++) {
332 struct frame *fr = &mp->fr;
378 decode_reset(PMPSTR mp)
381 remove_buf(mp);
383 /* mp->fsizeold = mp->framesize; */
384 mp->fsizeold = -1;
385 mp->old_free_format = mp->free_format;
386 mp->framesize = 0;
387 mp->header_parsed = 0;
388 mp->side_parsed = 0;
389 mp->data_parsed = 0;
390 mp->sync_bitstream = 1; /* TODO check if this is right */
392 InitMP3(mp); /* Less error prone to just to reinitialise. */
397 audiodata_precedesframes(PMPSTR mp)
399 if (mp->fr.lay == 3)
400 return layer3_audiodata_precedesframes(mp);
406 decodeMP3_clipchoice(PMPSTR mp, unsigned char *in, int isize, char *out, int *done,
412 if (in && isize && addbuf(mp, in, isize) == NULL)
416 if (!mp->header_parsed) {
418 if (mp->fsizeold == -1 || mp->sync_bitstream) {
420 mp->sync_bitstream = 0;
424 bytes = sync_buffer(mp, 0);
427 if (mp->bsize >= bytes + XING_HEADER_SIZE) {
429 vbrbytes = check_vbr_header(mp, bytes);
434 lame_report_fnc(mp->report_dbg, "hip: not enough data to look for Xing header\n");
439 if (mp->vbr_header) {
441 if (bytes + vbrbytes > mp->bsize) {
442 /* lame_report_fnc(mp->report_err,"hip: not enough data to parse entire Xing header\n"); */
450 lame_report_fnc(mp->report_dbg, "hip: found xing header, skipping %i bytes\n", vbrbytes + bytes);
453 read_buf_byte(mp);
462 bytes = sync_buffer(mp, 1);
467 /* lame_report_fnc(mp->report_err,"hip: need more bytes %d\n", bytes); */
478 if (mp->fsizeold != -1) {
479 lame_report_fnc(mp->report_err, "hip: bitstream problem, resyncing skipping %d bytes...\n", bytes);
481 mp->old_free_format = 0;
484 mp->sync_bitstream = 1;
487 size = (int) (mp->wordpointer - (mp->bsspace[mp->bsnum] + 512));
491 lame_report_fnc(mp->report_err, "hip: wordpointer trashed. size=%i (%i) bytes=%i \n",
494 mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
503 read_buf_byte(mp);
506 copy_mp(mp, bytes, mp->wordpointer);
507 mp->fsizeold += bytes;
510 read_head(mp);
511 if (!decode_header(mp, &mp->fr, mp->header))
513 mp->header_parsed = 1;
514 mp->framesize = mp->fr.framesize;
515 mp->free_format = (mp->framesize == 0);
517 if (mp->fr.lsf)
518 mp->ssize = (mp->fr.stereo == 1) ? 9 : 17;
520 mp->ssize = (mp->fr.stereo == 1) ? 17 : 32;
521 if (mp->fr.error_protection)
522 mp->ssize += 2;
524 mp->bsnum = 1 - mp->bsnum; /* toggle buffer */
525 mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
526 mp->bitindex = 0;
529 if (mp->fsizeold == -1) {
531 lame_report_fnc(mp->report_dbg, "hip: not parsing the rest of the data of the first header\n");
538 if (!mp->side_parsed) {
541 if (mp->fr.lay == 3) {
542 if (mp->bsize < mp->ssize)
545 copy_mp(mp, mp->ssize, mp->wordpointer);
547 if (mp->fr.error_protection)
548 getbits(mp, 16);
549 bits = decode_layer3_sideinfo(mp);
556 mp->dsize = (bits + 7) / 8;
558 if (!mp->free_format) {
560 int framesize = mp->fr.framesize - mp->ssize;
561 if (mp->dsize > framesize) {
562 lame_report_fnc(mp->report_err,
564 mp->dsize - framesize);
565 mp->dsize = framesize;
569 lame_report_fnc(mp->report_dbg,
571 bits, mp->dsize);
575 /* mp->dsize= mp->framesize - mp->ssize; */
582 if (mp->fr.framesize > mp->bsize)
586 mp->dsize = mp->fr.framesize;
587 mp->ssize = 0;
590 mp->side_parsed = 1;
595 if (!mp->data_parsed) {
596 if (mp->dsize > mp->bsize) {
600 copy_mp(mp, mp->dsize, mp->wordpointer);
604 /*do_layer3(&mp->fr,(unsigned char *) out,done); */
605 switch (mp->fr.lay) {
607 if (mp->fr.error_protection)
608 getbits(mp, 16);
610 if (decode_layer1_frame(mp, (unsigned char *) out, done) < 0)
615 if (mp->fr.error_protection)
616 getbits(mp, 16);
618 decode_layer2_frame(mp, (unsigned char *) out, done);
622 decode_layer3_frame(mp, (unsigned char *) out, done, synth_1to1_mono_ptr, synth_1to1_ptr);
625 lame_report_fnc(mp->report_err, "hip: invalid layer %d\n", mp->fr.lay);
628 mp->wordpointer = mp->bsspace[mp->bsnum] + 512 + mp->ssize + mp->dsize;
630 mp->data_parsed = 1;
637 * mp->framesize */
638 if (mp->free_format) {
639 if (mp->old_free_format) {
641 mp->framesize = mp->fsizeold_nopadding + (mp->fr.padding);
644 bytes = sync_buffer(mp, 1);
647 mp->framesize = bytes + mp->ssize + mp->dsize;
648 mp->fsizeold_nopadding = mp->framesize - mp->fr.padding;
650 lame_report_fnc(mp->report_dbg,"hip: freeformat bitstream: estimated bitrate=%ikbs \n",
651 8*(4+mp->framesize)*freqs[mp->fr.sampling_frequency]/
652 (1000*576*(2-mp->fr.lsf)));
658 bytes = mp->framesize - (mp->ssize + mp->dsize);
659 if (bytes > mp->bsize) {
668 read_buf_byte(mp);
670 mp->framesize--;
673 copy_mp(mp, bytes, mp->wordpointer);
674 mp->wordpointer += bytes;
676 size = (int) (mp->wordpointer - (mp->bsspace[mp->bsnum] + 512));
678 lame_report_fnc(mp->report_err, "hip: fatal error. MAXFRAMESIZE not large enough.\n");
684 mp->fsizeold = mp->framesize;
685 mp->old_free_format = mp->free_format;
686 mp->framesize = 0;
687 mp->header_parsed = 0;
688 mp->side_parsed = 0;
689 mp->data_parsed = 0;
695 decodeMP3(PMPSTR mp, unsigned char *in, int isize, char *out, int osize, int *done)
698 lame_report_fnc(mp->report_err, "hip: Insufficient memory for decoding buffer %d\n", osize);
703 return decodeMP3_clipchoice(mp, in, isize, out, done, synth_1to1_mono, synth_1to1);
707 decodeMP3_unclipped(PMPSTR mp, unsigned char *in, int isize, char *out, int osize, int *done)
711 lame_report_fnc(mp->report_err, "hip: out space too small for unclipped mode\n");
716 return decodeMP3_clipchoice(mp, in, isize, out, done, synth_1to1_mono_unclipped,