summaryrefslogtreecommitdiff
path: root/src/libfaad/common.c
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2003-12-30 02:00:10 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2003-12-30 02:00:10 +0000
commitf260c2ac3661143bfdfbcc4c7a3574acdd831894 (patch)
tree644ed0104c63c64b7346681ca5e212a81876458c /src/libfaad/common.c
parent33f6c0d77b5dfafcbafd09fc05d700fb66c9cb47 (diff)
downloadxine-lib-f260c2ac3661143bfdfbcc4c7a3574acdd831894.tar.gz
xine-lib-f260c2ac3661143bfdfbcc4c7a3574acdd831894.tar.bz2
- update to libfaad 2.0 rc3
- some fixes to xine_decoder.c CVS patchset: 5959 CVS date: 2003/12/30 02:00:10
Diffstat (limited to 'src/libfaad/common.c')
-rw-r--r--src/libfaad/common.c178
1 files changed, 161 insertions, 17 deletions
diff --git a/src/libfaad/common.c b/src/libfaad/common.c
index 028886ba5..3df232482 100644
--- a/src/libfaad/common.c
+++ b/src/libfaad/common.c
@@ -1,6 +1,6 @@
/*
-** FAAD - Freeware Advanced Audio Decoder
-** Copyright (C) 2002 M. Bakker
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@@ -16,7 +16,13 @@
** 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.3 2003/08/25 21:51:40 f1rmb Exp $
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+**
+** $Id: common.c,v 1.4 2003/12/30 02:00:10 miguelfreitas Exp $
**/
/* just some common functions that could be used anywhere */
@@ -24,11 +30,73 @@
#include "common.h"
#include "structs.h"
+#include <stdlib.h>
#include "syntax.h"
-#include "dither.h"
+
+#ifdef USE_SSE
+__declspec(naked) static int32_t __fastcall test_cpuid()
+{
+ __asm
+ {
+ pushf
+ pop eax
+ mov ecx,eax
+ xor eax,(1<<21)
+ push eax
+ popf
+ pushf
+ pop eax
+ push ecx
+ popf
+ cmp eax,ecx
+ mov eax,0
+ setne al
+ ret
+ }
+}
+
+__declspec(naked) static void __fastcall run_cpuid(int32_t param, int32_t out[4])
+{
+ __asm
+ {
+ pushad
+ push edx
+ mov eax,ecx
+ cpuid
+ pop edi
+ mov [edi+0],eax
+ mov [edi+4],ebx
+ mov [edi+8],ecx
+ mov [edi+12],edx
+ popad
+ ret
+ }
+}
+
+uint8_t cpu_has_sse()
+{
+ int32_t features[4];
+
+ if (test_cpuid())
+ {
+ run_cpuid(1, features);
+ }
+
+ /* check for SSE */
+ if (features[3] & 0x02000000)
+ return 1;
+
+ return 0;
+}
+#else
+uint8_t cpu_has_sse()
+{
+ return 0;
+}
+#endif
/* Returns the sample rate index based on the samplerate */
-uint8_t get_sr_index(uint32_t samplerate)
+uint8_t get_sr_index(const uint32_t samplerate)
{
if (92017 <= samplerate) return 0;
if (75132 <= samplerate) return 1;
@@ -41,12 +109,78 @@ uint8_t get_sr_index(uint32_t samplerate)
if (13856 <= samplerate) return 8;
if (11502 <= samplerate) return 9;
if (9391 <= samplerate) return 10;
+ if (16428320 <= samplerate) return 11;
return 11;
}
+/* Returns the sample rate based on the sample rate index */
+uint32_t get_sample_rate(const uint8_t sr_index)
+{
+ static const uint32_t sample_rates[] =
+ {
+ 96000, 88200, 64000, 48000, 44100, 32000,
+ 24000, 22050, 16000, 12000, 11025, 8000
+ };
+
+ if (sr_index < 12)
+ return sample_rates[sr_index];
+
+ return 0;
+}
+
+uint8_t max_pred_sfb(const uint8_t sr_index)
+{
+ static const uint8_t pred_sfb_max[] =
+ {
+ 33, 33, 38, 40, 40, 40, 41, 41, 37, 37, 37, 34
+ };
+
+
+ if (sr_index < 12)
+ return pred_sfb_max[sr_index];
+
+ return 0;
+}
+
+uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
+ const uint8_t is_short)
+{
+ /* entry for each sampling rate
+ * 1 Main/LC long window
+ * 2 Main/LC short window
+ * 3 SSR long window
+ * 4 SSR short window
+ */
+ static const uint8_t tns_sbf_max[][4] =
+ {
+ {31, 9, 28, 7}, /* 96000 */
+ {31, 9, 28, 7}, /* 88200 */
+ {34, 10, 27, 7}, /* 64000 */
+ {40, 14, 26, 6}, /* 48000 */
+ {42, 14, 26, 6}, /* 44100 */
+ {51, 14, 26, 6}, /* 32000 */
+ {46, 14, 29, 7}, /* 24000 */
+ {46, 14, 29, 7}, /* 22050 */
+ {42, 14, 23, 8}, /* 16000 */
+ {42, 14, 23, 8}, /* 12000 */
+ {42, 14, 23, 8}, /* 11025 */
+ {39, 14, 19, 7}, /* 8000 */
+ {39, 14, 19, 7}, /* 7350 */
+ {0,0,0,0},
+ {0,0,0,0},
+ {0,0,0,0}
+ };
+ uint8_t i = 0;
+
+ if (is_short) i++;
+ if (object_type == SSR) i += 2;
+
+ return tns_sbf_max[sr_index][i];
+}
+
/* Returns 0 if an object type is decodable, otherwise returns -1 */
-int8_t can_decode_ot(uint8_t object_type)
+int8_t can_decode_ot(const uint8_t object_type)
{
switch (object_type)
{
@@ -96,6 +230,26 @@ int8_t can_decode_ot(uint8_t object_type)
return -1;
}
+/* common malloc function */
+void *faad_malloc(int32_t size)
+{
+#ifdef _WIN32
+ return _aligned_malloc(size, 16);
+#else
+ return malloc(size);
+#endif
+}
+
+/* common free function */
+void faad_free(void *b)
+{
+#ifdef _WIN32
+ _aligned_free(b);
+#else
+ free(b);
+#endif
+}
+
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,
@@ -139,6 +293,7 @@ static uint32_t __r2 = 1;
*/
uint32_t random_int(void)
{
+ static const uint32_t rnd_seed = 16428320;
uint32_t t1, t2, t3, t4;
t3 = t1 = __r1; t4 = t2 = __r2; // Parity calculation is done via table lookup, this is also available
@@ -148,14 +303,3 @@ uint32_t random_int(void)
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
-