Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
flac
Commits
af9c773d
Commit
af9c773d
authored
May 19, 2003
by
Josh Coalson
Browse files
add Brady's better write_sane_extended()
parent
9f88dc25
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/flac/decode.c
View file @
af9c773d
...
...
@@ -632,27 +632,31 @@ FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 val)
}
FLAC__bool
write_sane_extended
(
FILE
*
f
,
unsigned
val
)
/* Write to 'f' a SANE extended representation of 'val'. Return false if
* the write succeeds; return true otherwise.
*
* SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits
* of exponent, and 64 bits of significand (mantissa). Unlike most IEEE-754
* representations, it does not imply a 1 above the MSB of the significand.
*
* Preconditions:
* val!=0U
*/
{
unsigned
i
,
exponent
;
unsigned
i
nt
shift
,
exponent
;
/* this reasonable limitation make the implementation simpler */
FLAC__ASSERT
(
val
<
0x80000000
);
FLAC__ASSERT
(
val
!=
0U
);
/* handling 0 would require a special case */
/* we'll use the denormalized form, with no implicit '1' (i bit == 0) */
for
(
i
=
val
,
exponent
=
0
;
i
;
i
>>=
1
,
exponent
++
)
for
(
shift
=
0U
;
(
val
>>
(
31
-
shift
))
==
0U
;
++
shift
)
;
if
(
!
write_big_endian_uint16
(
f
,
(
FLAC__uint16
)(
exponent
+
16383
)))
return
false
;
val
<<=
shift
;
exponent
=
63U
-
(
shift
+
32U
);
/* add 32 for unused second word */
for
(
i
=
32
;
i
;
i
--
)
{
if
(
val
&
0x40000000
)
break
;
val
<<=
1
;
}
if
(
!
write_big_endian_uint16
(
f
,
(
FLAC__uint16
)(
exponent
+
0x3FFF
)))
return
false
;
if
(
!
write_big_endian_uint32
(
f
,
val
))
return
false
;
if
(
!
write_big_endian_uint32
(
f
,
0
))
if
(
!
write_big_endian_uint32
(
f
,
0
))
/* unused second word */
return
false
;
return
true
;
...
...
src/test_streams/main.c
View file @
af9c773d
...
...
@@ -141,33 +141,36 @@ static FLAC__bool write_big_endian_int32(FILE *f, FLAC__int32 x)
#endif
static
FLAC__bool
write_sane_extended
(
FILE
*
f
,
unsigned
val
)
{
unsigned
i
,
exponent
;
/* this reasonable limitation make the implementation simpler */
FLAC__ASSERT
(
val
<
0x80000000
);
/* we'll use the denormalized form, with no implicit '1' (i bit == 0) */
for
(
i
=
val
,
exponent
=
0
;
i
;
i
>>=
1
,
exponent
++
)
/* Write to 'f' a SANE extended representation of 'val'. Return false if
* the write succeeds; return true otherwise.
*
* SANE extended is an 80-bit IEEE-754 representation with sign bit, 15 bits
* of exponent, and 64 bits of significand (mantissa). Unlike most IEEE-754
* representations, it does not imply a 1 above the MSB of the significand.
*
* Preconditions:
* val!=0U
*/
{
unsigned
int
shift
,
exponent
;
FLAC__ASSERT
(
val
!=
0U
);
/* handling 0 would require a special case */
for
(
shift
=
0U
;
(
val
>>
(
31
-
shift
))
==
0U
;
++
shift
)
;
if
(
!
write_big_endian_uint16
(
f
,
(
FLAC__uint16
)(
exponent
+
16383
)))
return
false
;
val
<<=
shift
;
exponent
=
63U
-
(
shift
+
32U
);
/* add 32 for unused second word */
for
(
i
=
32
;
i
;
i
--
)
{
if
(
val
&
0x40000000
)
break
;
val
<<=
1
;
}
if
(
!
write_big_endian_uint16
(
f
,
(
FLAC__uint16
)(
exponent
+
0x3FFF
)))
return
false
;
if
(
!
write_big_endian_uint32
(
f
,
val
))
return
false
;
if
(
!
write_big_endian_uint32
(
f
,
0
))
if
(
!
write_big_endian_uint32
(
f
,
0
))
/* unused second word */
return
false
;
return
true
;
}
/* a mono one-sample 16bps stream */
static
FLAC__bool
generate_01
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment