summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Zander <thomas.e.zander@googlemail.com>2016-01-03 19:13:52 +0100
committerErik de Castro Lopo <erikd@mega-nerd.com>2016-01-04 13:22:34 +1100
commit93c3a3897e287760092553fdd4ec6674a5537e8c (patch)
tree61f08031f5b08ba3ec839659c4b1fd9f098a1f07
parenta3224c0434ce2c11f37bbeb4bb44a343771a6f7f (diff)
downloadflac-93c3a3897e287760092553fdd4ec6674a5537e8c.tar.gz
Cleanup FLAC__bitmath_silog2()
- Retire 32bit variant of silog2(), since only the _wide variant is used - Rename FLAC__bitmath_silog2_wide() to FLAC__bitmath_silog2() - Replace existing implementation by shorter, clearer implementation using optimised routines from bitmath.h - Update Copyright string to 2016 in changed files Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com> Closes: https://github.com/xiph/flac/pull/6
-rw-r--r--src/libFLAC/bitmath.c54
-rw-r--r--src/libFLAC/include/private/bitmath.h9
-rw-r--r--src/libFLAC/lpc.c10
3 files changed, 16 insertions, 57 deletions
diff --git a/src/libFLAC/bitmath.c b/src/libFLAC/bitmath.c
index 5b58ca99..b3d797d3 100644
--- a/src/libFLAC/bitmath.c
+++ b/src/libFLAC/bitmath.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * Copyright (C) 2011-2016 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -60,50 +60,14 @@
* silog2( 9) = 5
* silog2( 10) = 5
*/
-unsigned FLAC__bitmath_silog2(int v)
+unsigned FLAC__bitmath_silog2(FLAC__int64 v)
{
- while(1) {
- if(v == 0) {
- return 0;
- }
- else if(v > 0) {
- unsigned l = 0;
- while(v) {
- l++;
- v >>= 1;
- }
- return l+1;
- }
- else if(v == -1) {
- return 2;
- }
- else {
- v++;
- v = -v;
- }
- }
-}
+ if(v == 0)
+ return 0;
-unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
-{
- while(1) {
- if(v == 0) {
- return 0;
- }
- else if(v > 0) {
- unsigned l = 0;
- while(v) {
- l++;
- v >>= 1;
- }
- return l+1;
- }
- else if(v == -1) {
- return 2;
- }
- else {
- v++;
- v = -v;
- }
- }
+ if(v == -1)
+ return 2;
+
+ v = (v < 0) ? (-(v+1)) : v;
+ return FLAC__bitmath_ilog2_wide(v)+2;
}
diff --git a/src/libFLAC/include/private/bitmath.h b/src/libFLAC/include/private/bitmath.h
index bdd154a9..9c75f85b 100644
--- a/src/libFLAC/include/private/bitmath.h
+++ b/src/libFLAC/include/private/bitmath.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * Copyright (C) 2011-2016 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -169,9 +169,6 @@ static inline unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
#endif
}
-
-#ifdef FLAC__INTEGER_ONLY_LIBRARY /* Unused otherwise */
-
static inline unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
{
FLAC__ASSERT(v > 0);
@@ -207,9 +204,7 @@ static inline unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
}
#endif
}
-#endif
-unsigned FLAC__bitmath_silog2(int v);
-unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
+unsigned FLAC__bitmath_silog2(FLAC__int64 v);
#endif
diff --git a/src/libFLAC/lpc.c b/src/libFLAC/lpc.c
index e5900ef0..dc946d47 100644
--- a/src/libFLAC/lpc.c
+++ b/src/libFLAC/lpc.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2014 Xiph.Org Foundation
+ * Copyright (C) 2011-2016 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -545,11 +545,11 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 * f
history = data;
for(j = 0; j < order; j++)
sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
- if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
+ if(FLAC__bitmath_silog2(sum >> lp_quantization) > 32) {
fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%" PRId64 "\n", i, (sum >> lp_quantization));
break;
}
- if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
+ if(FLAC__bitmath_silog2((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%" PRId64 ", residual=%" PRId64 "\n", i, *data, (int64_t)(sum >> lp_quantization), ((FLAC__int64)(*data) - (sum >> lp_quantization)));
break;
}
@@ -1062,11 +1062,11 @@ void FLAC__lpc_restore_signal_wide(const FLAC__int32 * flac_restrict residual, u
history = data;
for(j = 0; j < order; j++)
sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
- if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
+ if(FLAC__bitmath_silog2(sum >> lp_quantization) > 32) {
fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%" PRId64 "\n", i, (sum >> lp_quantization));
break;
}
- if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
+ if(FLAC__bitmath_silog2((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%" PRId64 ", data=%" PRId64 "\n", i, *r, (sum >> lp_quantization), ((FLAC__int64)(*r) + (sum >> lp_quantization)));
break;
}