]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/nellymoserdec.c
cosmetics: Fix typos in ADPCM codec long names.
[ffmpeg] / libavcodec / nellymoserdec.c
index fc57f2d61ffbb5cc6dab9ca924364a8ca28493c0..876a44f02275889fb0937495e35a9ee847313b10 100644 (file)
@@ -30,8 +30,9 @@
  * The 3 alphanumeric copyright notices are md5summed they are from the original
  * implementors. The original code is available from http://code.google.com/p/nelly2pcm/
  */
+
+#include "libavutil/random.h"
 #include "avcodec.h"
-#include "random.h"
 #include "dsputil.h"
 
 #define ALT_BITSTREAM_READER_LE
@@ -96,7 +97,7 @@ typedef struct NellyMoserDecodeContext {
     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,13 +115,14 @@ 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) {
-        audio[bot] = ( a_in[bot]*sine_window[bot]+state[bot]*sine_window[top])/s->scale_bias + s->add_bias;
+        audio[bot] = a_in [bot]*sine_window[bot]
+                    +state[bot]*sine_window[top] + s->add_bias;
 
         bot++;
         top--;
@@ -130,10 +132,10 @@ static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *
 
 static int sum_bits(short *buf, short shift, short off)
 {
-    int b, i = 0, ret = 0;
+    int i, ret = 0;
 
     for (i = 0; i < NELLY_FILL_LEN; i++) {
-        b = buf[i]-off;
+        int b = buf[i]-off;
         b = ((b>>(shift-1))+1)>>1;
         ret += av_clip(b, 0, NELLY_BIT_CAP);
     }
@@ -263,7 +265,9 @@ static void get_sample_bits(const float *buf, int *bits)
     }
 }
 
-void nelly_decode_block(NellyMoserDecodeContext *s, const unsigned char block[NELLY_BLOCK_LEN], float audio[NELLY_SAMPLES])
+static void nelly_decode_block(NellyMoserDecodeContext *s,
+                               const unsigned char block[NELLY_BLOCK_LEN],
+                               float audio[NELLY_SAMPLES])
 {
     int i,j;
     float buf[NELLY_FILL_LEN], pows[NELLY_FILL_LEN];
@@ -279,7 +283,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;
@@ -298,11 +302,11 @@ void nelly_decode_block(NellyMoserDecodeContext *s, const unsigned char block[NE
         for (j = 0; j < NELLY_FILL_LEN; j++) {
             if (bits[j] <= 0) {
                 aptr[j] = M_SQRT1_2*pows[j];
-                if (!(av_random(&s->random_state) & 1))
+                if (av_random(&s->random_state) & 1)
                     aptr[j] *= -1.0;
             } else {
                 v = get_bits(&s->gb, bits[j]);
-                aptr[j] = -dequantization_table[(1<<bits[j])-1+v]*pows[j];
+                aptr[j] = dequantization_table[(1<<bits[j])-1+v]*pows[j];
             }
         }
         memset(&aptr[NELLY_FILL_LEN], 0,
@@ -328,10 +332,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 */
@@ -394,5 +398,6 @@ AVCodec nellymoser_decoder = {
     NULL,
     decode_end,
     decode_tag,
+    .long_name = "Nellymoser Asao",
 };