Ticket #1533: mplayerfloatvorbis-v1.diff

File mplayerfloatvorbis-v1.diff, 5.0 KB (added by hhaamu@…, 17 years ago)

patch

  • libavcodec/vorbis_dec.c

     
    153153    float *channel_residues;
    154154    float *channel_floors;
    155155    float *saved;
    156     uint_fast32_t add_bias; // for float->int conversion
    157     uint_fast32_t exp_bias;
    158156} vorbis_context;
    159157
    160158/* Helper functions */
     
    861859        av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
    862860        return 3;
    863861    }
    864     // output format int16
    865     if (vc->blocksize[1]/2 * vc->audio_channels * 2 >
     862    // output format float
     863    if (vc->blocksize[1]/2 * vc->audio_channels * sizeof(float) >
    866864                                             AVCODEC_MAX_AUDIO_FRAME_SIZE) {
    867865        av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes "
    868866               "output packets too large.\n");
     
    881879    vc->saved           = av_mallocz((vc->blocksize[1]/4)*vc->audio_channels * sizeof(float));
    882880    vc->previous_window=0;
    883881
    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);
    886884
    887885    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 ",
    888886            vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
     
    911909    vc->avccontext = avccontext;
    912910    dsputil_init(&vc->dsp, avccontext);
    913911
    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 
    922912    if (!headers_len) {
    923913        av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
    924914        return -1;
     
    957947    avccontext->channels = vc->audio_channels;
    958948    avccontext->sample_rate = vc->audio_samplerate;
    959949    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;
    961951
    962952    return 0 ;
    963953}
     
    13911381    }
    13921382}
    13931383
    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 
    14051384// Decode the audio packet using the functions above
    14061385
    14071386static int vorbis_parse_audio_packet(vorbis_context *vc) {
     
    14201399    uint_fast8_t res_chan[vc->audio_channels];
    14211400    uint_fast8_t res_num=0;
    14221401    int_fast16_t retlen=0;
    1423     float fadd_bias = vc->add_bias;
    14241402
    14251403    if (get_bits1(gb)) {
    14261404        av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
     
    15251503        const float *win=vc->win[blockflag&previous_window];
    15261504
    15271505        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);
    15291507        } 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));
    15321510        } 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);
    15351513        }
    15361514        memcpy(saved, buf+blocksize/4, blocksize/4*sizeof(float));
    15371515    }
     
    15501528    int buf_size = avpkt->size;
    15511529    vorbis_context *vc = avccontext->priv_data ;
    15521530    GetBitContext *gb = &(vc->gb);
    1553     const float *channel_ptrs[vc->audio_channels];
    1554     int i;
     1531    int i,ch;
    15551532
    15561533    int_fast16_t len;
    15571534
     
    15781555
    15791556    AV_DEBUG("parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb)/8, get_bits_count(gb)%8, len);
    15801557
    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    }
    15851564
     1565    *data_size=len*sizeof(float)*vc->audio_channels;
     1566
    15861567    return buf_size ;
    15871568}
    15881569