diff mbox series

[FFmpeg-devel,1/2] avcodec/hcadec: fix decoding of hfr channels

Message ID 20200617214507.44381-1-summertriangle.dev@gmail.com
State Accepted
Commit bc2dcae897da64349d690b9e2f951a63b97309fd
Headers show
Series [FFmpeg-devel,1/2] avcodec/hcadec: fix decoding of hfr channels | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

t June 17, 2020, 9:45 p.m. UTC
I suspect this was originally broken by b7e5c8f , but even
then, it only worked because it read out of bounds from
intensity_ratio_table.

Signed-off-by: t <summertriangle.dev@gmail.com>
---
 libavcodec/hca_data.h | 14 ++++++++------
 libavcodec/hcadec.c   |  3 ++-
 2 files changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/hca_data.h b/libavcodec/hca_data.h
index 80b4a794dc..7093221c2a 100644
--- a/libavcodec/hca_data.h
+++ b/libavcodec/hca_data.h
@@ -86,18 +86,18 @@  static const float intensity_ratio_table[] =
 {
     2.0, 1.85714, 1.71429, 1.57143, 1.42857, 1.28571, 1.14286, 1.0,
     0.857143, 0.714286, 0.571429, 0.428571, 0.285714, 0.142857, 0.0, 0.0,
-    0, 1.87066e-08, 2.49253e-08, 3.32113e-08, 4.42518e-08, 5.89626e-08, 7.85637e-08, 1.04681e-07,
+};
+
+static const float scale_conversion_table[] =
+{
+    0, 0, 1.87066e-08, 2.49253e-08, 3.32113e-08, 4.42518e-08, 5.89626e-08, 7.85637e-08, 1.04681e-07,
     1.3948e-07, 1.85848e-07, 2.4763e-07, 3.2995e-07, 4.39636e-07, 5.85785e-07, 7.80519e-07, 1.03999e-06,
     1.38572e-06, 1.84637e-06, 2.46017e-06, 3.27801e-06, 4.36772e-06, 5.8197e-06, 7.75435e-06, 1.03321e-05,
     1.37669e-05, 1.83435e-05, 2.44414e-05, 3.25665e-05, 4.33927e-05, 5.78179e-05, 7.70384e-05, 0.000102648,
     0.000136772, 0.00018224, 0.000242822, 0.000323544, 0.000431101, 0.000574413, 0.000765366, 0.0010198,
     0.00135881, 0.00181053, 0.0024124, 0.00321437, 0.00428293, 0.00570671, 0.00760381, 0.0101316,
     0.0134996, 0.0179873, 0.0239669, 0.0319343, 0.0425503, 0.0566954, 0.0755428, 0.100656,
-    0.134117, 0.178702, 0.238108, 0.317263, 0.422731, 0.563261, 0.750507, 0.0,
-};
-
-static const float scale_conversion_table[] =
-{
+    0.134117, 0.178702, 0.238108, 0.317263, 0.422731, 0.563261, 0.750507,
     1.0, 1.33243, 1.77538, 2.36557, 3.15196, 4.19978, 5.59592, 7.45618,
     9.93486, 13.2375, 17.6381, 23.5016, 31.3143, 41.7242, 55.5947, 74.0762,
     98.7015, 131.513, 175.232, 233.485, 311.103, 414.524, 552.326, 735.937,
@@ -108,6 +108,8 @@  static const float scale_conversion_table[] =
     9.55285e+06, 1.27285e+07, 1.69599e+07, 2.25979e+07, 3.01102e+07, 4.01198e+07, 5.3457e+07, 0,
 };
 
+static const int scale_conv_bias = 64;
+
 static const float dequantizer_scaling_table[] =
 {
     1.58838e-07, 2.11641e-07, 2.81998e-07, 3.75743e-07, 5.00652e-07, 6.67085e-07, 8.88846e-07, 1.18433e-06,
diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c
index 5fa87319d2..a890e75a13 100644
--- a/libavcodec/hcadec.c
+++ b/libavcodec/hcadec.c
@@ -287,7 +287,8 @@  static void reconstruct_hfr(HCAContext *s, ChannelContext *ch,
 
     for (int i = 0, k = start_band, l = start_band - 1; i < hfr_group_count; i++){
         for (int j = 0; j < bands_per_hfr_group && k < total_band_count && l >= 0; j++, k++, l--){
-            ch->imdct_in[k] = scale_conversion_table[ (ch->hfr_scale[i] - ch->scale_factors[l]) & 63 ] * ch->imdct_in[l];
+            ch->imdct_in[k] = scale_conversion_table[ scale_conv_bias +
+                av_clip_intp2(ch->hfr_scale[i] - ch->scale_factors[l], 6) ] * ch->imdct_in[l];
         }
     }