[FFmpeg-cvslog] aacdec: template scalefactor dequantization separately

Lynne git at videolan.org
Tue Apr 23 09:58:27 EEST 2024


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Wed Mar 13 21:53:49 2024 +0100| [a6295586f5040ce5ce838ff2ae11a5ba9b41d855] | committer: Lynne

aacdec: template scalefactor dequantization separately

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a6295586f5040ce5ce838ff2ae11a5ba9b41d855
---

 libavcodec/aac/Makefile              |  6 ++-
 libavcodec/aac/aacdec.c              |  5 ++
 libavcodec/aac/aacdec_dsp_template.c | 93 ++++++++++++++++++++++++++++++++++++
 libavcodec/aac/aacdec_fixed.c        | 34 +++++++++++++
 libavcodec/aac/aacdec_float.c        | 34 +++++++++++++
 libavcodec/aacdec_template.c         | 56 +---------------------
 6 files changed, 171 insertions(+), 57 deletions(-)

diff --git a/libavcodec/aac/Makefile b/libavcodec/aac/Makefile
index 29e0ef0a2c..c3e525d373 100644
--- a/libavcodec/aac/Makefile
+++ b/libavcodec/aac/Makefile
@@ -1,5 +1,7 @@
 clean::
 		$(RM) $(CLEANSUFFIXES:%=libavcodec/aac/%)
 
-OBJS-$(CONFIG_AAC_DECODER)          +=  aac/aacdec.o aac/aacdec_tab.o
-OBJS-$(CONFIG_AAC_FIXED_DECODER)    +=  aac/aacdec.o aac/aacdec_tab.o
+OBJS-$(CONFIG_AAC_DECODER)          +=  aac/aacdec.o aac/aacdec_tab.o \
+                                        aac/aacdec_float.o
+OBJS-$(CONFIG_AAC_FIXED_DECODER)    +=  aac/aacdec.o aac/aacdec_tab.o \
+                                        aac/aacdec_fixed.o
diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c
index 358fe598e5..00353bddc7 100644
--- a/libavcodec/aac/aacdec.c
+++ b/libavcodec/aac/aacdec.c
@@ -45,6 +45,9 @@
 #include "libavutil/tx.h"
 #include "libavutil/version.h"
 
+extern const AACDecDSP aac_dsp;
+extern const AACDecDSP aac_dsp_fixed;
+
 av_cold int ff_aac_decode_close(AVCodecContext *avctx)
 {
     AACDecContext *ac = avctx->priv_data;
@@ -115,6 +118,8 @@ av_cold int ff_aac_decode_init_common(AVCodecContext *avctx)
     if (ret < 0)
         return ret;
 
+    ac->dsp = is_fixed ? aac_dsp_fixed : aac_dsp;
+
     return 0;
 }
 
diff --git a/libavcodec/aac/aacdec_dsp_template.c b/libavcodec/aac/aacdec_dsp_template.c
new file mode 100644
index 0000000000..9a43cb71e0
--- /dev/null
+++ b/libavcodec/aac/aacdec_dsp_template.c
@@ -0,0 +1,93 @@
+/*
+ * AAC decoder
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ * Copyright (c) 2008-2013 Alex Converse <alex.converse at gmail.com>
+ *
+ * AAC LATM decoder
+ * Copyright (c) 2008-2010 Paul Kendall <paul at kcbbs.gen.nz>
+ * Copyright (c) 2010      Janne Grunau <janne-libav at jannau.net>
+ *
+ * AAC decoder fixed-point implementation
+ * Copyright (c) 2013
+ *      MIPS Technologies, Inc., California.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/aacdec.h"
+#include "libavcodec/aac_defines.h"
+
+#include "libavcodec/aactab.h"
+
+/**
+ * Convert integer scalefactors to the decoder's native expected
+ * scalefactor values.
+ */
+static void AAC_RENAME(dequant_scalefactors)(SingleChannelElement *sce)
+{
+    IndividualChannelStream *ics = &sce->ics;
+    const enum BandType *band_type = sce->band_type;
+    const int *band_type_run_end = sce->band_type_run_end;
+    const int *sfo = sce->sfo;
+    INTFLOAT *sf = sce->AAC_RENAME(sf);
+
+    int g, i, idx = 0;
+    for (g = 0; g < ics->num_window_groups; g++) {
+        for (i = 0; i < ics->max_sfb;) {
+            int run_end = band_type_run_end[idx];
+            switch (band_type[idx]) {
+            case ZERO_BT:
+                for (; i < run_end; i++, idx++)
+                    sf[idx] = FIXR(0.);
+                break;
+            case INTENSITY_BT: /* fallthrough */
+            case INTENSITY_BT2:
+                for (; i < run_end; i++, idx++) {
+#if USE_FIXED
+                    sf[idx] = 100 - sfo[idx];
+#else
+                    sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] + POW_SF2_ZERO];
+#endif /* USE_FIXED */
+                }
+                break;
+            case NOISE_BT:
+                for (; i < run_end; i++, idx++) {
+#if USE_FIXED
+                    sf[idx] = -(100 + sfo[idx]);
+#else
+                    sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
+#endif /* USE_FIXED */
+                }
+                break;
+            default:
+                for (; i < run_end; i++, idx++) {
+#if USE_FIXED
+                    sf[idx] = -sfo[idx];
+#else
+                    sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] - 100 + POW_SF2_ZERO];
+#endif /* USE_FIXED */
+                }
+                break;
+            }
+        }
+    }
+}
+
+const AACDecDSP AAC_RENAME(aac_dsp) = {
+    .dequant_scalefactors = &AAC_RENAME(dequant_scalefactors),
+};
diff --git a/libavcodec/aac/aacdec_fixed.c b/libavcodec/aac/aacdec_fixed.c
new file mode 100644
index 0000000000..1b41a43a46
--- /dev/null
+++ b/libavcodec/aac/aacdec_fixed.c
@@ -0,0 +1,34 @@
+/*
+ * AAC decoder
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ * Copyright (c) 2008-2013 Alex Converse <alex.converse at gmail.com>
+ *
+ * AAC LATM decoder
+ * Copyright (c) 2008-2010 Paul Kendall <paul at kcbbs.gen.nz>
+ * Copyright (c) 2010      Janne Grunau <janne-libav at jannau.net>
+ *
+ * AAC decoder fixed-point implementation
+ * Copyright (c) 2013
+ *      MIPS Technologies, Inc., California.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define USE_FIXED 1
+
+#include "aacdec_dsp_template.c"
diff --git a/libavcodec/aac/aacdec_float.c b/libavcodec/aac/aacdec_float.c
new file mode 100644
index 0000000000..a40c1c1f03
--- /dev/null
+++ b/libavcodec/aac/aacdec_float.c
@@ -0,0 +1,34 @@
+/*
+ * AAC decoder
+ * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
+ * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
+ * Copyright (c) 2008-2013 Alex Converse <alex.converse at gmail.com>
+ *
+ * AAC LATM decoder
+ * Copyright (c) 2008-2010 Paul Kendall <paul at kcbbs.gen.nz>
+ * Copyright (c) 2010      Janne Grunau <janne-libav at jannau.net>
+ *
+ * AAC decoder fixed-point implementation
+ * Copyright (c) 2013
+ *      MIPS Technologies, Inc., California.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define USE_FIXED 0
+
+#include "aacdec_dsp_template.c"
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 70a9c0c014..c2962a7ca2 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1512,60 +1512,6 @@ static int decode_scalefactors(AACDecContext *ac, int sfo[120],
     return 0;
 }
 
-/**
- * Convert integer scalefactors to the decoder's native expected
- * scalefactor values.
- */
-static void dequant_scalefactors(SingleChannelElement *sce)
-{
-    IndividualChannelStream *ics = &sce->ics;
-    const enum BandType *band_type = sce->band_type;
-    const int *band_type_run_end = sce->band_type_run_end;
-    const int *sfo = sce->sfo;
-    INTFLOAT *sf = sce->AAC_RENAME(sf);
-
-    int g, i, idx = 0;
-    for (g = 0; g < ics->num_window_groups; g++) {
-        for (i = 0; i < ics->max_sfb;) {
-            int run_end = band_type_run_end[idx];
-            switch (band_type[idx]) {
-            case ZERO_BT:
-                for (; i < run_end; i++, idx++)
-                    sf[idx] = FIXR(0.);
-                break;
-            case INTENSITY_BT: /* fallthrough */
-            case INTENSITY_BT2:
-                for (; i < run_end; i++, idx++) {
-#if USE_FIXED
-                    sf[idx] = 100 - sfo[idx];
-#else
-                    sf[idx] = ff_aac_pow2sf_tab[-sfo[idx] + POW_SF2_ZERO];
-#endif /* USE_FIXED */
-                }
-                break;
-            case NOISE_BT:
-                for (; i < run_end; i++, idx++) {
-#if USE_FIXED
-                    sf[idx] = -(100 + sfo[idx]);
-#else
-                    sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] + POW_SF2_ZERO];
-#endif /* USE_FIXED */
-                }
-                break;
-            default:
-                for (; i < run_end; i++, idx++) {
-#if USE_FIXED
-                    sf[idx] = -sfo[idx];
-#else
-                    sf[idx] = -ff_aac_pow2sf_tab[sfo[idx] - 100 + POW_SF2_ZERO];
-#endif /* USE_FIXED */
-                }
-                break;
-            }
-        }
-    }
-}
-
 /**
  * Decode pulse data; reference: table 4.7.
  */
@@ -2061,7 +2007,7 @@ static int decode_ics(AACDecContext *ac, SingleChannelElement *sce,
                                    sce->band_type, sce->band_type_run_end)) < 0)
         goto fail;
 
-    dequant_scalefactors(sce);
+    ac->dsp.dequant_scalefactors(sce);
 
     pulse_present = 0;
     if (!scale_flag) {



More information about the ffmpeg-cvslog mailing list