]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/nellymoserdec.c
Add supported_samplerates field to AVCodec
[ffmpeg] / libavcodec / nellymoserdec.c
index 204910d2c197b4c6ca169bcf2bf1954cb1927afe..470465d9d285a22ca195d5aba129c608ee3e296b 100644 (file)
@@ -92,11 +92,11 @@ static const int16_t nelly_delta_table[32] = {
 typedef struct NellyMoserDecodeContext {
     AVCodecContext* avctx;
     DECLARE_ALIGNED_16(float,float_buf[NELLY_SAMPLES]);
-    float           state[64];
+    float           state[128];
     AVRandomState   random_state;
     GetBitContext   gb;
     int             add_bias;
-    int             scale_bias;
+    float           scale_bias;
     DSPContext      dsp;
     MDCTContext     imdct_ctx;
     DECLARE_ALIGNED_16(float,imdct_tmp[NELLY_BUF_LEN]);
@@ -114,19 +114,19 @@ static inline int signed_shift(int i, int shift) {
 
 static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *audio, float *a_in)
 {
-    int bot, top, top2;
+    int bot, top;
 
     bot = 0;
     top = NELLY_BUF_LEN-1;
 
-    while (bot < NELLY_BUF_LEN/2) {
-        audio[bot] =  (- a_in[bot]*sine_window[bot]-state[bot]*sine_window[top])/s->scale_bias + s->add_bias;
-        audio[top] =  (-state[bot]*sine_window[bot]- a_in[top]*sine_window[top])/s->scale_bias + s->add_bias;
-        state[bot] = a_in[bot + NELLY_BUF_LEN];
+    while (bot < NELLY_BUF_LEN) {
+        audio[bot] = a_in [bot]*sine_window[bot]
+                    +state[bot]*sine_window[top] + s->add_bias;
 
         bot++;
         top--;
     }
+    memcpy(state, a_in + NELLY_BUF_LEN, sizeof(float)*NELLY_BUF_LEN);
 }
 
 static int sum_bits(short *buf, short shift, short off)
@@ -280,7 +280,7 @@ void nelly_decode_block(NellyMoserDecodeContext *s, const unsigned char block[NE
     for (i=0 ; i<NELLY_BANDS ; i++) {
         if (i > 0)
             val += nelly_delta_table[get_bits(&s->gb, 5)];
-        pval = pow(2, val/2048);
+        pval = -pow(2, val/2048) * s->scale_bias;
         for (j = 0; j < nelly_band_sizes_table[i]; j++) {
             *bptr++ = val;
             *pptr++ = pval;
@@ -329,10 +329,10 @@ static av_cold int decode_init(AVCodecContext * avctx) {
 
     if(s->dsp.float_to_int16 == ff_float_to_int16_c) {
         s->add_bias = 385;
-        s->scale_bias = 8*32768;
+        s->scale_bias = 1.0/(8*32768);
     } else {
         s->add_bias = 0;
-        s->scale_bias = 1*8;
+        s->scale_bias = 1.0/(1*8);
     }
 
     /* Generate overlap window */