summaryrefslogtreecommitdiff
path: root/src/libfaad/common.c
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2002-12-16 18:59:50 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2002-12-16 18:59:50 +0000
commit94ef6649dd5f4e95337af00dcede2337ea7cfb49 (patch)
tree07d679ce92b4e4517815abc42394480eebf44904 /src/libfaad/common.c
parent48f4c5809db11a6df4a5e7285d5e60a2ed924e2a (diff)
downloadxine-lib-94ef6649dd5f4e95337af00dcede2337ea7cfb49.tar.gz
xine-lib-94ef6649dd5f4e95337af00dcede2337ea7cfb49.tar.bz2
updated libfaad
CVS patchset: 3560 CVS date: 2002/12/16 18:59:50
Diffstat (limited to 'src/libfaad/common.c')
-rw-r--r--src/libfaad/common.c132
1 files changed, 130 insertions, 2 deletions
diff --git a/src/libfaad/common.c b/src/libfaad/common.c
index 394366d17..c68f438ff 100644
--- a/src/libfaad/common.c
+++ b/src/libfaad/common.c
@@ -16,17 +16,145 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: common.c,v 1.1 2002/07/14 23:43:01 miguelfreitas Exp $
+** $Id: common.c,v 1.2 2002/12/16 18:59:56 miguelfreitas Exp $
**/
/* just some common functions that could be used anywhere */
#include "common.h"
+#include "structs.h"
-#define LOG2 0.30102999566398
+#include "syntax.h"
+
+/* Returns the sample rate index based on the samplerate */
+uint8_t get_sr_index(uint32_t samplerate)
+{
+ if (92017 <= samplerate) return 0;
+ if (75132 <= samplerate) return 1;
+ if (55426 <= samplerate) return 2;
+ if (46009 <= samplerate) return 3;
+ if (37566 <= samplerate) return 4;
+ if (27713 <= samplerate) return 5;
+ if (23004 <= samplerate) return 6;
+ if (18783 <= samplerate) return 7;
+ if (13856 <= samplerate) return 8;
+ if (11502 <= samplerate) return 9;
+ if (9391 <= samplerate) return 10;
+
+ return 11;
+}
+
+/* Returns 0 if an object type is decodable, otherwise returns -1 */
+int8_t can_decode_ot(uint8_t object_type)
+{
+ switch (object_type)
+ {
+ case LC:
+ return 0;
+ case MAIN:
+#ifdef MAIN_DEC
+ return 0;
+#else
+ return -1;
+#endif
+ case SSR:
+#ifdef SSR_DEC
+ return 0;
+#else
+ return -1;
+#endif
+ case LTP:
+#ifdef LTP_DEC
+ return 0;
+#else
+ return -1;
+#endif
+
+ /* ER object types */
+#ifdef ERROR_RESILIENCE
+ case ER_LC:
+#ifdef DRM
+ case DRM_ER_LC:
+#endif
+ return 0;
+ case ER_LTP:
+#ifdef LTP_DEC
+ return 0;
+#else
+ return -1;
+#endif
+ case LD:
+#ifdef LD_DEC
+ return 0;
+#else
+ return -1;
+#endif
+#endif
+ }
+
+ return -1;
+}
+
+static const uint8_t Parity [256] = { // parity
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
+ 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
+};
+static uint32_t __r1 = 1;
+static uint32_t __r2 = 1;
+
+
+/*
+ * This is a simple random number generator with good quality for audio purposes.
+ * It consists of two polycounters with opposite rotation direction and different
+ * periods. The periods are coprime, so the total period is the product of both.
+ *
+ * -------------------------------------------------------------------------------------------------
+ * +-> |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0|
+ * | -------------------------------------------------------------------------------------------------
+ * | | | | | | |
+ * | +--+--+--+-XOR-+--------+
+ * | |
+ * +--------------------------------------------------------------------------------------+
+ *
+ * -------------------------------------------------------------------------------------------------
+ * |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| <-+
+ * ------------------------------------------------------------------------------------------------- |
+ * | | | | |
+ * +--+----XOR----+--+ |
+ * | |
+ * +----------------------------------------------------------------------------------------+
+ *
+ *
+ * The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481,
+ * which gives a period of 18.410.713.077.675.721.215. The result is the
+ * XORed values of both generators.
+ */
+uint32_t random_int(void)
+{
+ uint32_t t1, t2, t3, t4;
+
+ t3 = t1 = __r1; t4 = t2 = __r2; // Parity calculation is done via table lookup, this is also available
+ t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable
+ t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations.
+ t1 <<= 31; t2 = Parity [t2];
+
+ return (__r1 = (t3 >> 1) | t1 ) ^ (__r2 = (t4 + t4) | t2 );
+}
+
+#if 0
+
+#define LOG2 0.30102999566398
uint32_t int_log2(uint32_t val)
{
return (uint32_t)(log((real_t)val)/LOG2 + 0.5);
}
+#endif
+