Beispiel #1
0
/*
 * play a frame read by read_frame();
 * (re)initialize audio if necessary.
 */
static void decode_frame(APEG_LAYER *layer, struct frame *fr, struct mpstr *mp)
{
	int clip;

	/* do the decoding */
	switch(fr->lay)
	{
		case 1:
			clip = do_layer1(mp, fr, layer);
			break;
		case 2:
			clip = do_layer2(mp, fr, layer);
			break;
		case 3:
			clip = do_layer3(mp, fr, layer);
			break;
		default:
			// Shouldn't get here...
			clip = 1;
			mp->return_later = FALSE;
	}

	if(clip < 0)
		apeg_error_jump("Error decoding audio frame");
}
Beispiel #2
0
int MPGLIB_DecodeFrame(PMPSTR mp, const unsigned char* in, void* out)
{
    int done;
    
    /* First decode header */
    mp->header =
        (((unsigned long)in[0]) << 24) |
        (((unsigned long)in[1]) << 16) |
        (((unsigned long)in[2]) <<  8) |
        (((unsigned long)in[3]));
    decode_header(&mp->fr, mp->header);
    mp->framesize = mp->fr.framesize;

    mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
    mp->bsnum = (mp->bsnum + 1) & 0x1;
    mp->bitindex = 0;

    memcpy(mp->wordpointer, in+4, mp->framesize);

    done = 0;
    if(mp->fr.error_protection)
        getbits(mp, 16);
    switch(mp->fr.lay) {
      case 1:
        do_layer1(mp,(unsigned char *) out, &done);
        break;
      case 2:
        do_layer2(mp,(unsigned char *) out, &done);
        break;
      case 3:
        do_layer3(mp,(unsigned char *) out, &done, synth_1to1_mono, synth_1to1);
        break;
    }
    
    mp->fsizeold = mp->framesize;
    mp->framesize = 0;
    
    if (done) {
        return MP3_OK;
    } else {
        return MP3_INVALID_BITS;
    }
}
Beispiel #3
0
int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
		int osize,int *done)
{
	int len;

	gmp = mp;

	if(osize < 4608) {
//		fprintf(stderr,"To less out space\n");
		return MP3_ERR;
	}

	if(in) {
		if(addbuf(mp,in,isize) == NULL) {
			return MP3_ERR;
		}
	}

	/* First decode header */
	if(mp->framesize == 0) {
		if(mp->bsize < 4) {
			return MP3_NEED_MORE;
		}
		read_head(mp);
		decode_header(&mp->fr,mp->header);
		mp->framesize = mp->fr.framesize;
	}

	if(mp->fr.framesize > mp->bsize)
		return MP3_NEED_MORE;

	wordpointer = mp->bsspace[mp->bsnum] + 512;
	mp->bsnum = (mp->bsnum + 1) & 0x1;
	bitindex = 0;

	len = 0;
	while(len < mp->framesize) {
		int nlen;
		int blen = mp->tail->size - mp->tail->pos;
		if( (mp->framesize - len) <= blen) {
                  nlen = mp->framesize-len;
		}
		else {
                  nlen = blen;
                }
		memcpy(wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
                len += nlen;
                mp->tail->pos += nlen;
		mp->bsize -= nlen;
                if(mp->tail->pos == mp->tail->size) {
                   remove_buf(mp);
                }
	}

	*done = 0;
	if(mp->fr.error_protection)
           getbits(16);
        switch(mp->fr.lay) {
          case 1:
	    do_layer1(&mp->fr,(unsigned char *) out,done);
            break;
          case 2:
	    do_layer2(&mp->fr,(unsigned char *) out,done);
            break;
          case 3:
	    do_layer3(&mp->fr,(unsigned char *) out,done);
            break;
        }

	mp->fsizeold = mp->framesize;
	mp->framesize = 0;

	return MP3_OK;
}