Commit 918cd225 authored by Justin Ruggles's avatar Justin Ruggles
Browse files

Simplify fix15().

Turn it into 2 macros, and use av_clip_int16() and lrintf().
This matches the int16 to float sample conversion in audioconvert.c.
The regression test output is different due to lrintf() rounding.

Originally committed as revision 25956 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 228315bb
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "ac3.h" #include "ac3.h"
#include "audioconvert.h" #include "audioconvert.h"
#define SCALE_FLOAT(a, bits) lrintf((a) * (float)(1 << (bits)))
typedef struct AC3EncodeContext { typedef struct AC3EncodeContext {
PutBitContext pb; ///< bitstream writer context PutBitContext pb; ///< bitstream writer context
...@@ -86,16 +88,7 @@ static int16_t xsin1[128]; ...@@ -86,16 +88,7 @@ static int16_t xsin1[128];
/* new exponents are sent if their Norm 1 exceed this number */ /* new exponents are sent if their Norm 1 exceed this number */
#define EXP_DIFF_THRESHOLD 1000 #define EXP_DIFF_THRESHOLD 1000
static inline int16_t fix15(float a) #define FIX15(a) av_clip_int16(SCALE_FLOAT(a, 15))
{
int v;
v = (int)(a * (float)(1 << 15));
if (v < -32767)
v = -32767;
else if (v > 32767)
v = 32767;
return v;
}
typedef struct IComplex { typedef struct IComplex {
int16_t re,im; int16_t re,im;
...@@ -110,8 +103,8 @@ static av_cold void fft_init(int ln) ...@@ -110,8 +103,8 @@ static av_cold void fft_init(int ln)
for(i=0;i<(n/2);i++) { for(i=0;i<(n/2);i++) {
alpha = 2 * M_PI * (float)i / (float)n; alpha = 2 * M_PI * (float)i / (float)n;
costab[i] = fix15(cos(alpha)); costab[i] = FIX15(cos(alpha));
sintab[i] = fix15(sin(alpha)); sintab[i] = FIX15(sin(alpha));
} }
} }
...@@ -126,8 +119,8 @@ static av_cold void mdct_init(int nbits) ...@@ -126,8 +119,8 @@ static av_cold void mdct_init(int nbits)
for(i=0;i<n4;i++) { for(i=0;i<n4;i++) {
alpha = 2 * M_PI * (i + 1.0 / 8.0) / n; alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;
xcos1[i] = fix15(-cos(alpha)); xcos1[i] = FIX15(-cos(alpha));
xsin1[i] = fix15(-sin(alpha)); xsin1[i] = FIX15(-sin(alpha));
} }
} }
......
081bfd5e683b13cccf1b07c43c1c5005 *./tests/data/acodec/ac3.rm 464093173530736050e338caf152044c *./tests/data/acodec/ac3.rm
98751 ./tests/data/acodec/ac3.rm 98751 ./tests/data/acodec/ac3.rm
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment