Ticket #1533: mplayerfloatvorbis-v1.diff
| File mplayerfloatvorbis-v1.diff, 5.0 KB (added by , 17 years ago) |
|---|
-
libavcodec/vorbis_dec.c
153 153 float *channel_residues; 154 154 float *channel_floors; 155 155 float *saved; 156 uint_fast32_t add_bias; // for float->int conversion157 uint_fast32_t exp_bias;158 156 } vorbis_context; 159 157 160 158 /* Helper functions */ … … 861 859 av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n"); 862 860 return 3; 863 861 } 864 // output format int16865 if (vc->blocksize[1]/2 * vc->audio_channels * 2>862 // output format float 863 if (vc->blocksize[1]/2 * vc->audio_channels * sizeof(float) > 866 864 AVCODEC_MAX_AUDIO_FRAME_SIZE) { 867 865 av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes " 868 866 "output packets too large.\n"); … … 881 879 vc->saved = av_mallocz((vc->blocksize[1]/4)*vc->audio_channels * sizeof(float)); 882 880 vc->previous_window=0; 883 881 884 ff_mdct_init(&vc->mdct[0], bl0, 1, vc->exp_bias ? -(1<<15) :-1.0);885 ff_mdct_init(&vc->mdct[1], bl1, 1, vc->exp_bias ? -(1<<15) :-1.0);882 ff_mdct_init(&vc->mdct[0], bl0, 1, -1.0); 883 ff_mdct_init(&vc->mdct[1], bl1, 1, -1.0); 886 884 887 885 AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", 888 886 vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); … … 911 909 vc->avccontext = avccontext; 912 910 dsputil_init(&vc->dsp, avccontext); 913 911 914 if(vc->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {915 vc->add_bias = 385;916 vc->exp_bias = 0;917 } else {918 vc->add_bias = 0;919 vc->exp_bias = 15<<23;920 }921 922 912 if (!headers_len) { 923 913 av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); 924 914 return -1; … … 957 947 avccontext->channels = vc->audio_channels; 958 948 avccontext->sample_rate = vc->audio_samplerate; 959 949 avccontext->frame_size = FFMIN(vc->blocksize[0], vc->blocksize[1])>>2; 960 avccontext->sample_fmt = SAMPLE_FMT_ S16;950 avccontext->sample_fmt = SAMPLE_FMT_FLT; 961 951 962 952 return 0 ; 963 953 } … … 1391 1381 } 1392 1382 } 1393 1383 1394 static void copy_normalize(float *dst, float *src, int len, int exp_bias, float add_bias)1395 {1396 int i;1397 if(exp_bias) {1398 memcpy(dst, src, len * sizeof(float));1399 } else {1400 for(i=0; i<len; i++)1401 dst[i] = src[i] + add_bias;1402 }1403 }1404 1405 1384 // Decode the audio packet using the functions above 1406 1385 1407 1386 static int vorbis_parse_audio_packet(vorbis_context *vc) { … … 1420 1399 uint_fast8_t res_chan[vc->audio_channels]; 1421 1400 uint_fast8_t res_num=0; 1422 1401 int_fast16_t retlen=0; 1423 float fadd_bias = vc->add_bias;1424 1402 1425 1403 if (get_bits1(gb)) { 1426 1404 av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); … … 1525 1503 const float *win=vc->win[blockflag&previous_window]; 1526 1504 1527 1505 if(blockflag == previous_window) { 1528 vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, blocksize/4);1506 vc->dsp.vector_fmul_window(ret, saved, buf, win, 0.0f, blocksize/4); 1529 1507 } else if(blockflag > previous_window) { 1530 vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, bs0/4);1531 copy_normalize(ret+bs0/2, buf+bs0/4, (bs1-bs0)/4, vc->exp_bias, fadd_bias);1508 vc->dsp.vector_fmul_window(ret, saved, buf, win, 0.0f, bs0/4); 1509 memcpy(ret+bs0/2, buf+bs0/4, (bs1-bs0)/4*sizeof(float)); 1532 1510 } else { 1533 copy_normalize(ret, saved, (bs1-bs0)/4, vc->exp_bias, fadd_bias);1534 vc->dsp.vector_fmul_window(ret+(bs1-bs0)/4, saved+(bs1-bs0)/4, buf, win, fadd_bias, bs0/4);1511 memcpy(ret, saved, (bs1-bs0)/4*sizeof(float)); 1512 vc->dsp.vector_fmul_window(ret+(bs1-bs0)/4, saved+(bs1-bs0)/4, buf, win, 0.0f, bs0/4); 1535 1513 } 1536 1514 memcpy(saved, buf+blocksize/4, blocksize/4*sizeof(float)); 1537 1515 } … … 1550 1528 int buf_size = avpkt->size; 1551 1529 vorbis_context *vc = avccontext->priv_data ; 1552 1530 GetBitContext *gb = &(vc->gb); 1553 const float *channel_ptrs[vc->audio_channels]; 1554 int i; 1531 int i,ch; 1555 1532 1556 1533 int_fast16_t len; 1557 1534 … … 1578 1555 1579 1556 AV_DEBUG("parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb)/8, get_bits_count(gb)%8, len); 1580 1557 1581 for(i=0; i<vc->audio_channels; i++) 1582 channel_ptrs[i] = vc->channel_floors+i*len; 1583 vc->dsp.float_to_int16_interleave(data, channel_ptrs, len, vc->audio_channels); 1584 *data_size=len*2*vc->audio_channels; 1558 /* interleave */ 1559 for (i=0; i < len; i++) { 1560 for (ch=0; ch < vc->audio_channels; ch++) { 1561 ((float *)data)[i * vc->audio_channels + ch] = (vc->channel_floors + ch*len)[i]; 1562 } 1563 } 1585 1564 1565 *data_size=len*sizeof(float)*vc->audio_channels; 1566 1586 1567 return buf_size ; 1587 1568 } 1588 1569
