[FFmpeg-devel] [PATCH] NellyMoser audio decoder v2

Loïc Minier lool
Thu Sep 13 17:49:28 CEST 2007


On Thu, Sep 13, 2007, Michael Niedermayer wrote:
> > > > +void nelly_util_floats2shorts(float audio[256], short shorts[256])
> > > duplicate of the respective code in dsputil
> >  Hmm replacing nelly_util_floats2shorts() with ff_float_to_int16_c()
> >  ended in some garbage.
> read the fine manual (
>  /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767]
>      * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */
>     void (*float_to_int16)(int16_t *dst, const float *src, int len);
> )
> it clearly says [384.0,386.0] -> [-32768,32767] for C

 I tried replacing:
    nelly_util_floats2shorts(s->float_buf, data);

 with:
    dsputil_init(&s->dsp, avctx);
    if (s->dsp.float_to_int16 == ff_float_to_int16_c) {
        s->add_bias = 385.0f;
        s->div_bias = 32767.0f;
    } else {
        s->add_bias = 0.0f;
        s->div_bias = 1.0f;
    }
 [...]
    for (i=0; i<NELLY_SAMPLE_SIZE; i++) {
        s->float_buf[i] /= s->div_bias;
        s->float_buf[i] += s->add_bias;
    }
    s->dsp.float_to_int16(data, s->float_buf, NELLY_SAMPLE_SIZE);

 but this distorted some samples; I guess there are small rounding
 errors in the float calculations and the bias should really be used in
 the decoder instead of applying them post decoding on the raw values
 for this to work, so I'm postponing this to after the understanding of
 the fft code (unless you see another reason why the above would be
 incorrect).

-- 
Lo?c Minier




More information about the ffmpeg-devel mailing list