ref: 056bcd7aa532463f1fc3421fcd612360c0f35c8a
parent: e6c584d53be18a56d628409c77fee356d7401f85
author: menno <menno>
date: Fri Nov 7 16:04:14 EST 2003
speed update for float -> linear conversion
--- a/libfaad/common.h
+++ b/libfaad/common.h
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through [email protected].
**
-** $Id: common.h,v 1.36 2003/11/04 21:43:30 menno Exp $
+** $Id: common.h,v 1.37 2003/11/07 21:04:14 menno Exp $
**/
#ifndef __COMMON_H__
@@ -261,6 +261,22 @@
#define REAL_CONST(A) ((real_t)(A))
#define COEF_CONST(A) ((real_t)(A))
+
+ #ifdef _WIN32
+ #define HAS_LRINTF
+ __inline int lrintf(float f)
+ {
+ int i;
+ __asm
+ {
+ fld f
+ fistp i
+ }
+ return i;
+ }
+ #endif
+
+
#ifdef __ICL /* only Intel C compiler has fmath ??? */
#include <mathf.h>
@@ -274,6 +290,14 @@
#else
+#ifdef HAVE_LRINTF
+# define HAS_LRINTF
+# define _ISOC9X_SOURCE 1
+# define _ISOC99_SOURCE 1
+# define __USE_ISOC9X 1
+# define __USE_ISOC99 1
+#endif
+
#include <math.h>
#ifdef HAVE_SINF
@@ -301,6 +325,11 @@
#endif
+#endif
+
+#ifndef HAS_LRINTF
+/* standard cast */
+#define lrintf(f) ((int32_t)(f))
#endif
typedef real_t complex_t[2];
--- a/libfaad/lt_predict.c
+++ b/libfaad/lt_predict.c
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through [email protected].
**
-** $Id: lt_predict.c,v 1.16 2003/11/04 21:43:30 menno Exp $
+** $Id: lt_predict.c,v 1.17 2003/11/07 21:04:14 menno Exp $
**/
@@ -97,7 +97,7 @@
/* lt_pred_stat is a 16 bit int, multiplied with the fixed point real
this gives a real for x_est
*/
- x_est[i] = lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef];
+ x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef];
#endif
}
@@ -124,28 +124,43 @@
}
}
-static int16_t real_to_int16(real_t sig_in)
+#ifdef FIXED_POINT
+INLINE int16_t real_to_int16(real_t sig_in)
{
- int16_t sig_out = 0;
+ if (sig_in >= 0)
+ {
+ sig_in += (1 << (REAL_BITS-1));
+ if (sig_in > REAL_CONST(32767))
+ sig_in = 32767.0f;
+ } else {
+ sig_in += -(1 << (REAL_BITS-1));
+ if (sig_in < REAL_CONST(-32768))
+ sig_in = -32768.0f;
+ }
- if (sig_in > REAL_CONST(32767))
- sig_out = 32767;
- else if (sig_in < REAL_CONST(-32768))
- sig_out = -32768;
-#ifndef FIXED_POINT
- else if (sig_in > 0.0)
- sig_out = (int16_t)(sig_in + 0.5);
- else if (sig_in <= 0.0)
- sig_out = (int16_t)(sig_in - 0.5);
+ return (sig_in >> REAL_BITS);
+}
#else
- else if (sig_in > 0)
- sig_out = (int16_t)((sig_in + (1 << (REAL_BITS-1))) >> REAL_BITS);
- else if (sig_in <= 0)
- sig_out = (int16_t)((sig_in - (1 << (REAL_BITS-1))) >> REAL_BITS);
+INLINE int16_t real_to_int16(real_t sig_in)
+{
+ if (sig_in >= 0)
+ {
+#ifndef HAS_LRINTF
+ sig_in += 0.5f;
#endif
+ if (sig_in > REAL_CONST(32767))
+ sig_in = 32767.0f;
+ } else {
+#ifndef HAS_LRINTF
+ sig_in -= 0.5f;
+#endif
+ if (sig_in < REAL_CONST(-32768))
+ sig_in = -32768.0f;
+ }
- return sig_out;
+ return lrintf(sig_in);
}
+#endif
void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap,
uint16_t frame_len, uint8_t object_type)
--- a/libfaad/output.c
+++ b/libfaad/output.c
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through [email protected].
**
-** $Id: output.c,v 1.27 2003/11/06 15:43:59 menno Exp $
+** $Id: output.c,v 1.28 2003/11/07 21:04:14 menno Exp $
**/
#include "common.h"
@@ -38,6 +38,7 @@
#define DM_MUL ((real_t)1.0/((real_t)1.0+(real_t)sqrt(2.0)))
+
static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
uint8_t downMatrix, uint8_t *internal_channel)
{
@@ -82,19 +83,23 @@
real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
if (inp >= 0.0f)
{
+#ifndef HAS_LRINTF
inp += 0.5f;
+#endif
if (inp >= 32768.0f)
{
inp = 32767.0f;
}
} else {
+#ifndef HAS_LRINTF
inp += -0.5f;
+#endif
if (inp <= -32769.0f)
{
inp = -32768.0f;
}
}
- short_sample_buffer[(i*channels)+ch] = (int16_t)inp;
+ short_sample_buffer[(i*channels)+ch] = (int16_t)lrintf(inp);
}
break;
case FAAD_FMT_24BIT:
@@ -104,19 +109,23 @@
inp *= 256.0f;
if (inp >= 0.0f)
{
+#ifndef HAS_LRINTF
inp += 0.5f;
+#endif
if (inp >= 8388608.0f)
{
inp = 8388607.0f;
}
} else {
+#ifndef HAS_LRINTF
inp += -0.5f;
+#endif
if (inp <= -8388609.0f)
{
inp = -8388608.0f;
}
}
- int_sample_buffer[(i*channels)+ch] = (int32_t)inp;
+ int_sample_buffer[(i*channels)+ch] = lrintf(inp);
}
break;
case FAAD_FMT_32BIT:
@@ -126,19 +135,23 @@
inp *= 65536.0f;
if (inp >= 0.0f)
{
+#ifndef HAS_LRINTF
inp += 0.5f;
+#endif
if (inp >= 2147483648.0f)
{
inp = 2147483647.0f;
}
} else {
+#ifndef HAS_LRINTF
inp += -0.5f;
+#endif
if (inp <= -2147483649.0f)
{
inp = -2147483648.0f;
}
}
- int_sample_buffer[(i*channels)+ch] = (int32_t)inp;
+ int_sample_buffer[(i*channels)+ch] = lrintf(inp);
}
break;
case FAAD_FMT_FLOAT: