[FFmpeg-cvslog] aacenc_tns: add moving average filter for LTP

Rostislav Pehlivanov git at videolan.org
Sat Oct 17 12:10:54 CEST 2015


ffmpeg | branch: master | Rostislav Pehlivanov <atomnuker at gmail.com> | Sat Oct 17 10:50:41 2015 +0100| [8d18d28918dffd9dd0da11699e16330375065176] | committer: Rostislav Pehlivanov

aacenc_tns: add moving average filter for LTP

The decoder does this so I guess we better do that as well.
There's barely any difference between the autoregressive and
the moving average filters looking at spectrals though.

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

 libavcodec/aacenc_tns.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/libavcodec/aacenc_tns.c b/libavcodec/aacenc_tns.c
index 815b4e3..3d5bfd7 100644
--- a/libavcodec/aacenc_tns.c
+++ b/libavcodec/aacenc_tns.c
@@ -91,7 +91,7 @@ void ff_aac_apply_tns(AACEncContext *s, SingleChannelElement *sce)
     IndividualChannelStream *ics = &sce->ics;
     int w, filt, m, i, top, order, bottom, start, end, size, inc;
     const int mmm = FFMIN(ics->tns_max_bands, ics->max_sfb);
-    float lpc[TNS_MAX_ORDER];
+    float lpc[TNS_MAX_ORDER], tmp[TNS_MAX_ORDER+1];
 
     for (w = 0; w < ics->num_windows; w++) {
         bottom = ics->num_swb;
@@ -117,10 +117,21 @@ void ff_aac_apply_tns(AACEncContext *s, SingleChannelElement *sce)
             }
             start += w * 128;
 
-            // ar filter
-            for (m = 0; m < size; m++, start += inc)
-                for (i = 1; i <= FFMIN(m, order); i++)
-                    sce->coeffs[start] += lpc[i-1]*sce->pcoeffs[start - i*inc];
+            if (!s->options.ltp) {     // ar filter
+                for (m = 0; m < size; m++, start += inc) {
+                    for (i = 1; i <= FFMIN(m, order); i++) {
+                        sce->coeffs[start] += lpc[i-1]*sce->pcoeffs[start - i*inc];
+                    }
+                }
+            } else {                   // ma filter
+                for (m = 0; m < size; m++, start += inc) {
+                    tmp[0] = sce->pcoeffs[start];
+                    for (i = 1; i <= FFMIN(m, order); i++)
+                        sce->coeffs[start] += lpc[i-1]*tmp[i];
+                    for (i = order; i > 0; i--)
+                        tmp[i] = tmp[i - 1];
+                }
+            }
         }
     }
 }



More information about the ffmpeg-cvslog mailing list