annotate intfloat_readwrite.c @ 104:5111e87117b7 libavutil

Align the input buffer in ffplay, introduce a public macro for aligned declarations Update the avcodec_decode_audio and the float_to_int16 descriptions accordingly
author lu_zero
date Thu, 31 Aug 2006 19:14:00 +0000
parents 79e95d74ce85
children d76a36742464
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
1 /*
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
2 * portable IEEE float/double read/write functions
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
3 *
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
4 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
5 *
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
10 *
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
14 * Lesser General Public License for more details.
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
15 *
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
15
af59e84e283d Update licensing information: The FSF changed postal address.
diego
parents: 12
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
19 */
12
ce8f9f4390c3 COSMETICS: Remove all trailing whitespace.
diego
parents: 2
diff changeset
20
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
21 /**
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
22 * @file intfloat_readwrite.c
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
23 * Portable IEEE float/double read/write functions.
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
24 */
12
ce8f9f4390c3 COSMETICS: Remove all trailing whitespace.
diego
parents: 2
diff changeset
25
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
26 #include "common.h"
23
f70fdc881a24 add missing #includes
mru
parents: 15
diff changeset
27 #include "intfloat_readwrite.h"
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
28
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
29 double av_int2dbl(int64_t v){
92
79e95d74ce85 use C99 standard constant, thanks to Foxy Shadis
bcoudurier
parents: 54
diff changeset
30 if(v+v > 0xFFEULL<<52)
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
31 return 0.0/0.0;
2
89cdb3b541e2 kill a bunch of compiler warnings
mru
parents: 0
diff changeset
32 return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
33 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
34
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
35 float av_int2flt(int32_t v){
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
36 if(v+v > 0xFF000000U)
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
37 return 0.0/0.0;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
38 return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
39 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
40
24
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
41 double av_ext2dbl(const AVExtFloat ext){
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
42 uint64_t m = 0;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
43 int e, i;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
44
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
45 for (i = 0; i < 8; i++)
54
4d0fe18e5ce3 simplify
michael
parents: 24
diff changeset
46 m = (m<<8) + ext.mantissa[i];
24
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
47 e = (((int)ext.exponent[0]&0x7f)<<8) | ext.exponent[1];
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
48 if (e == 0x7fff && m)
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
49 return 0.0/0.0;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
50 e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx)
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
51 * mantissa bit is written as opposed to the
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
52 * single and double precision formats */
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
53 if (ext.exponent[0]&0x80)
54
4d0fe18e5ce3 simplify
michael
parents: 24
diff changeset
54 m= -m;
24
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
55 return ldexp(m, e);
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
56 }
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
57
0
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
58 int64_t av_dbl2int(double d){
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
59 int e;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
60 if ( !d) return 0;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
61 else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d);
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
62 d= frexp(d, &e);
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
63 return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53));
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
64 }
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
65
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
66 int32_t av_flt2int(float d){
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
67 int e;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
68 if ( !d) return 0;
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
69 else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d);
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
70 d= frexp(d, &e);
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
71 return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24));
ee8f44bb7c4d libavutil: Utility code from libavcodec moved to a separate library.
al
parents:
diff changeset
72 }
24
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
73
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
74 AVExtFloat av_dbl2ext(double d){
54
4d0fe18e5ce3 simplify
michael
parents: 24
diff changeset
75 struct AVExtFloat ext= {{0}};
24
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
76 int e, i; double f; uint64_t m;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
77
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
78 f = fabs(frexp(d, &e));
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
79 if (f >= 0.5 && f < 1) {
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
80 e += 16382;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
81 ext.exponent[0] = e>>8;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
82 ext.exponent[1] = e;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
83 m = (uint64_t)ldexp(f, 64);
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
84 for (i=0; i < 8; i++)
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
85 ext.mantissa[i] = m>>(56-(i<<3));
54
4d0fe18e5ce3 simplify
michael
parents: 24
diff changeset
86 } else if (f != 0.0) {
24
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
87 ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
88 if (f != 1/0.0)
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
89 ext.mantissa[0] = ~0;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
90 }
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
91 if (d < 0)
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
92 ext.exponent[0] |= 0x80;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
93 return ext;
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
94 }
2b3573111ff0 AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents: 23
diff changeset
95