[FFmpeg-soc] [soc]: r3714 - in eac3: checkout.sh ffmpeg.patch grng.c grng.h

jbr subversion at mplayerhq.hu
Sat Sep 6 21:02:25 CEST 2008


Author: jbr
Date: Sat Sep  6 21:02:25 2008
New Revision: 3714

Log:
add a Gaussian PRNG to use for spectral extension processing

Added:
   eac3/grng.c
   eac3/grng.h
Modified:
   eac3/checkout.sh
   eac3/ffmpeg.patch

Modified: eac3/checkout.sh
==============================================================================
--- eac3/checkout.sh	(original)
+++ eac3/checkout.sh	Sat Sep  6 21:02:25 2008
@@ -1,16 +1,25 @@
-FILES="eac3dec.c ac3dec.c"
+LAVC_FILES="eac3dec.c ac3dec.c"
+LAVU_FILES="grng.c grng.h"
 
 echo "checking out ffmpeg svn"
-for i in $FILES ac3dec.h ac3dec_data.c ac3dec_data.h; do
+for i in $LAVC_FILES ac3dec.h ac3dec_data.c ac3dec_data.h; do
     rm -f ffmpeg/libavcodec/$i
 done
+for i in $LAVU_FILES Makefile; do
+    rm -f ffmpeg/libavutil/$i
+done
 svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg -r 15141
 echo "patching ffmpeg"
 cd ffmpeg
 patch -p0 <../ffmpeg.patch
 echo "copying the E-AC-3 files to ffmpeg/libavcodec"
-for i in $FILES; do
+for i in $LAVC_FILES; do
     rm -f libavcodec/$i
     ln -s ../../$i libavcodec/$i
 done
+echo "copying the GRNG files to ffmpeg/libavutil"
+for i in $LAVU_FILES; do
+    rm -f libavutil/$i
+    ln -s ../../$i libavutil/$i
+done
 echo "Done, now just do a regular configure and make to build."

Modified: eac3/ffmpeg.patch
==============================================================================
--- eac3/ffmpeg.patch	(original)
+++ eac3/ffmpeg.patch	Sat Sep  6 21:02:25 2008
@@ -1,3 +1,24 @@
+Index: libavutil/Makefile
+===================================================================
+--- libavutil/Makefile	(revision 15141)
++++ libavutil/Makefile	(working copy)
+@@ -8,6 +8,7 @@
+        crc.o \
+        des.o \
+        fifo.o \
++       grng.o \
+        intfloat_readwrite.o \
+        lfg.o \
+        lls.o \
+@@ -41,7 +42,7 @@
+           rational.h \
+           sha1.h
+ 
+-TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 pca random sha1 softfloat tree)
++TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des grng lls md5 pca random sha1 softfloat tree)
+ 
+ include $(SUBDIR)../subdir.mak
+ 
 Index: libavcodec/ac3dec.h
 ===================================================================
 --- libavcodec/ac3dec.h	(revision 15141)

Added: eac3/grng.c
==============================================================================
--- (empty file)
+++ eac3/grng.c	Sat Sep  6 21:02:25 2008
@@ -0,0 +1,106 @@
+/*
+ * Gaussian PRNG using the Marsaglia polar method
+ * Copyright (c) 2008 Justin Ruggles
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <math.h>
+#include "grng.h"
+
+int av_grng_get(AVGRNG *c)
+{
+    float w, x1, y1, x2, y2;
+
+    /* return 2nd value from previous run */
+    if (c->remaining) {
+        c->remaining = 0;
+        return c->y2;
+    }
+
+    /* generate a uniformly distributed random point which falls within the
+       unit circle */
+    do {
+        x1 = (int)av_lfg_get(&c->state) / (float)0x80000000;
+        y1 = (int)av_lfg_get(&c->state) / (float)0x80000000;
+        w = x1 * x1 + y1 * y1;
+    } while (w >= 1.0);
+
+    /* scale the point using the inverse gaussian probability function */
+    w = sqrtf((-2.0f * logf(w)) / w);
+    x2 = x1 * w;
+    y2 = y1 * w;
+
+    /* convert to signed 4.28-bit fixed-point.
+       save 'y' value in state. return 'x' value. */
+    c->y2 = lrintf(y2 * 0x8000000);
+    c->remaining = 1;
+    return lrintf(x2 * 0x8000000);
+}
+
+void av_grng_init(AVGRNG *c, unsigned int seed)
+{
+    av_lfg_init(&c->state, seed);
+    c->remaining = 0;
+}
+
+#ifdef TEST
+#include "log.h"
+#include "common.h"
+
+#define TEST_COUNT 10000
+
+int main(void)
+{
+    int x=0;
+    int i, j;
+    AVGRNG state;
+    float mean, stddev;
+    float data[TEST_COUNT]={0,};
+
+    av_grng_init(&state, 0xDEADBEEF);
+
+    for (j = 0; j < TEST_COUNT; j++) {
+        START_TIMER
+        for (i = 0; i < 624; i++) {
+            x+=av_grng_get(&state);
+        }
+        STOP_TIMER("624 calls of av_pgrng_get");
+    }
+    av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
+
+    for (j = 0; j < 16; j++) {
+        mean = 0;
+        for(i=0; i<TEST_COUNT; i++) {
+            data[i] = (float)av_grng_get(&state);
+            mean += data[i];
+        }
+        mean /= TEST_COUNT;
+        stddev = 0;
+        for(i=0; i<TEST_COUNT; i++) {
+            float diff = data[i] - mean;
+            stddev += (diff * diff);
+        }
+        stddev /= TEST_COUNT;
+        stddev = sqrtf(stddev);
+        av_log(NULL, AV_LOG_ERROR, "mean:%+f  stddev:%f\n", mean / 0x8000000,
+               stddev / 0x8000000);
+    }
+
+    return 0;
+}
+#endif

Added: eac3/grng.h
==============================================================================
--- (empty file)
+++ eac3/grng.h	Sat Sep  6 21:02:25 2008
@@ -0,0 +1,42 @@
+/*
+ * Gaussian PRNG using the Marsaglia polar method
+ * Copyright (c) 2008 Justin Ruggles
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_GRNG_H
+#define AVUTIL_GRNG_H
+
+#include "lfg.h"
+
+typedef struct {
+    AVLFG state;
+    int remaining;
+    int y2;
+} AVGRNG;
+
+/**
+ * Generates a random number, where the sequence has a standard normal
+ * distribution (zero mean, unity standard deviation).
+ * @return the next random number as a signed 4.28-bit fixed-point integer
+ */
+int av_grng_get(AVGRNG *c);
+
+void av_grng_init(AVGRNG *c, unsigned int seed);
+
+#endif /* AVUTIL_GRNG_H */



More information about the FFmpeg-soc mailing list