summaryrefslogtreecommitdiff
path: root/libavcodec/aacenc_tns.c
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2015-10-17 10:55:19 +0100
committerRostislav Pehlivanov <atomnuker@gmail.com>2015-10-17 11:10:26 +0100
commitf3ad901a32c95239f302f173b866b82fb1f6cdf9 (patch)
treeccff480f9773d11ef88bb24ac053be561133901d /libavcodec/aacenc_tns.c
parent8d18d28918dffd9dd0da11699e16330375065176 (diff)
aacenc_tns: disable coefficient compression by default
Too much effort and work has been spent on such a simple function. It simply refuses to work as the specifications say, the transformation is NOT lossless and creates some crackling and distortions. Therefore disable it by default and add a couple of warnings to scare people away from touching it or wasting their time the way I did.
Diffstat (limited to 'libavcodec/aacenc_tns.c')
-rw-r--r--libavcodec/aacenc_tns.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/libavcodec/aacenc_tns.c b/libavcodec/aacenc_tns.c
index 3d5bfd7e1c..62cf7a06a1 100644
--- a/libavcodec/aacenc_tns.c
+++ b/libavcodec/aacenc_tns.c
@@ -31,27 +31,31 @@
#include "aacenc_utils.h"
#include "aacenc_quantization.h"
-/*
- * Shifts the values as well if compression is possible.
- */
+/* Define this to save a bit, be warned decoders can't deal with it
+ * so it is not lossless despite what the specifications say */
+// #define TNS_ENABLE_COEF_COMPRESSION
+
static inline int compress_coeffs(int *coef, int order, int c_bits)
{
- int i, res = 0;
+ int i;
const int low_idx = c_bits ? 4 : 2;
const int shift_val = c_bits ? 8 : 4;
const int high_idx = c_bits ? 11 : 5;
+#ifndef TNS_ENABLE_COEF_COMPRESSION
+ return 0;
+#endif /* TNS_ENABLE_COEF_COMPRESSION */
+ for (i = 0; i < order; i++)
+ if (coef[i] >= low_idx && coef[i] <= high_idx)
+ return 0;
for (i = 0; i < order; i++)
- if (coef[i] < low_idx || coef[i] > high_idx)
- res++;
- if (res == order)
- for (i = 0; i < order; i++)
- coef[i] -= (coef[i] > high_idx) ? shift_val : 0;
- return res == order;
+ coef[i] -= (coef[i] > high_idx) ? shift_val : 0;
+ return 1;
}
/**
* Encode TNS data.
- * Coefficient compression saves a single bit per coefficient.
+ * Coefficient compression is simply not lossless as it should be
+ * on any decoder tested and as such is not active.
*/
void ff_aac_encode_tns_info(AACEncContext *s, SingleChannelElement *sce)
{