]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/roqaudioenc.c
Restructure dummy frame allocation.
[ffmpeg] / libavcodec / roqaudioenc.c
index d638f9d94b4c65fb902625556d90bf0c4d132fc1..acb1b5f5a6aee4726cb29f97abdf1bc3a3f824e1 100644 (file)
 
 
 #define MAX_DPCM (127*127)
-static unsigned char dpcmValues[MAX_DPCM];
 
 
 typedef struct
 {
     short lastSample[2];
-} ROQDPCMContext_t;
+} ROQDPCMContext;
 
-static av_cold void roq_dpcm_table_init(void)
+static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
 {
-    int i;
-
-    /* Create a table of quick DPCM values */
-    for (i=0; i<MAX_DPCM; i++) {
-        int s= ff_sqrt(i);
-        int mid= s*s + s;
-        dpcmValues[i]= s + (i>mid);
-    }
-}
-
-static int roq_dpcm_encode_init(AVCodecContext *avctx)
-{
-    ROQDPCMContext_t *context = avctx->priv_data;
+    ROQDPCMContext *context = avctx->priv_data;
 
     if (avctx->channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n");
@@ -66,8 +53,6 @@ static int roq_dpcm_encode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    roq_dpcm_table_init();
-
     avctx->frame_size = ROQ_FIRST_FRAME_SIZE;
 
     context->lastSample[0] = context->lastSample[1] = 0;
@@ -92,8 +77,10 @@ static unsigned char dpcm_predict(short *previous, short current)
 
     if (diff >= MAX_DPCM)
         result = 127;
-    else
-        result = dpcmValues[diff];
+    else {
+        result = ff_sqrt(diff);
+        result += diff > result*result+result;
+    }
 
     /* See if this overflows */
  retry:
@@ -123,7 +110,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx,
     short *in;
     unsigned char *out;
 
-    ROQDPCMContext_t *context = avctx->priv_data;
+    ROQDPCMContext *context = avctx->priv_data;
 
     stereo = (avctx->channels == 2);
 
@@ -169,10 +156,11 @@ AVCodec roq_dpcm_encoder = {
     "roq_dpcm",
     CODEC_TYPE_AUDIO,
     CODEC_ID_ROQ_DPCM,
-    sizeof(ROQDPCMContext_t),
+    sizeof(ROQDPCMContext),
     roq_dpcm_encode_init,
     roq_dpcm_encode_frame,
     roq_dpcm_encode_close,
     NULL,
-    .long_name = "id RoQ DPCM",
+    .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"),
 };