diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2006-02-02 18:21:19 +0300 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2006-02-02 18:21:19 +0300 |
commit | f11288dab4c5c7b65b824c1c4e3ff3e9f642b040 (patch) | |
tree | 2b5e8470867ebe028f03527f45fee41fb2fcf9da /libavutil | |
parent | 93d3e278cd095f4a9d44513b91ce0785b2b159a2 (diff) |
AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
Originally committed as revision 4924 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/intfloat_readwrite.c | 43 | ||||
-rw-r--r-- | libavutil/intfloat_readwrite.h | 8 |
2 files changed, 51 insertions, 0 deletions
diff --git a/libavutil/intfloat_readwrite.c b/libavutil/intfloat_readwrite.c index 0d27cb8f39..6450de1024 100644 --- a/libavutil/intfloat_readwrite.c +++ b/libavutil/intfloat_readwrite.c @@ -38,6 +38,23 @@ float av_int2flt(int32_t v){ return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); } +double av_ext2dbl(const AVExtFloat ext){ + uint64_t m = 0; + int e, i; + + for (i = 0; i < 8; i++) + m |= (uint64_t)ext.mantissa[i]<<(56-(i<<3)); + e = (((int)ext.exponent[0]&0x7f)<<8) | ext.exponent[1]; + if (e == 0x7fff && m) + return 0.0/0.0; + e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx) + * mantissa bit is written as opposed to the + * single and double precision formats */ + if (ext.exponent[0]&0x80) + return ldexp(-m, e); + return ldexp(m, e); +} + int64_t av_dbl2int(double d){ int e; if ( !d) return 0; @@ -53,3 +70,29 @@ int32_t av_flt2int(float d){ d= frexp(d, &e); return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); } + +AVExtFloat av_dbl2ext(double d){ + struct AVExtFloat ext; + int e, i; double f; uint64_t m; + + f = fabs(frexp(d, &e)); + if (f >= 0.5 && f < 1) { + e += 16382; + ext.exponent[0] = e>>8; + ext.exponent[1] = e; + m = (uint64_t)ldexp(f, 64); + for (i=0; i < 8; i++) + ext.mantissa[i] = m>>(56-(i<<3)); + } else if (f == 0.0) { + memset (&ext, 0, 10); + } else { + ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff; + memset (&ext.mantissa, 0, 8); + if (f != 1/0.0) + ext.mantissa[0] = ~0; + } + if (d < 0) + ext.exponent[0] |= 0x80; + return ext; +} + diff --git a/libavutil/intfloat_readwrite.h b/libavutil/intfloat_readwrite.h index 22f40bb665..33e4c636c7 100644 --- a/libavutil/intfloat_readwrite.h +++ b/libavutil/intfloat_readwrite.h @@ -3,9 +3,17 @@ #include "common.h" +/* IEEE 80 bits extended float */ +typedef struct AVExtFloat { + uint8_t exponent[2]; + uint8_t mantissa[8]; +} AVExtFloat; + double av_int2dbl(int64_t v); float av_int2flt(int32_t v); +double av_ext2dbl(const AVExtFloat ext); int64_t av_dbl2int(double d); int32_t av_flt2int(float d); +AVExtFloat av_dbl2ext(double d); #endif /* INTFLOAT_READWRITE_H */ |