[FFmpeg-cvslog] r20584 - in trunk/libavcodec: lsp.c lsp.h twinvq.c

vitor subversion
Sun Nov 22 23:25:59 CET 2009


Author: vitor
Date: Sun Nov 22 23:25:58 2009
New Revision: 20584

Log:
Make sorting function used in TwinVQ a shared function

Modified:
   trunk/libavcodec/lsp.c
   trunk/libavcodec/lsp.h
   trunk/libavcodec/twinvq.c

Modified: trunk/libavcodec/lsp.c
==============================================================================
--- trunk/libavcodec/lsp.c	Sun Nov 22 22:08:46 2009	(r20583)
+++ trunk/libavcodec/lsp.c	Sun Nov 22 23:25:58 2009	(r20584)
@@ -173,3 +173,12 @@ void ff_acelp_lspd2lpc(const double *lsp
         lpc2[-lp_half_order] = 0.5*(paf-qaf);
     }
 }
+
+void ff_sort_nearly_sorted_floats(float *vals, int len)
+{
+    int i,j;
+
+    for (i = 0; i < len - 1; i++)
+        for (j = i; j >= 0 && vals[j] > vals[j+1]; j--)
+            FFSWAP(float, vals[j], vals[j+1]);
+}

Modified: trunk/libavcodec/lsp.h
==============================================================================
--- trunk/libavcodec/lsp.h	Sun Nov 22 22:08:46 2009	(r20583)
+++ trunk/libavcodec/lsp.h	Sun Nov 22 23:25:58 2009	(r20584)
@@ -97,4 +97,11 @@ void ff_acelp_lp_decode(int16_t* lp_1st,
  */
 void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order);
 
+/**
+ * Sort values in ascending order.
+ *
+ * @note O(n) if data already sorted, O(n^2) - otherwise
+ */
+void ff_sort_nearly_sorted_floats(float *vals, int len);
+
 #endif /* AVCODEC_LSP_H */

Modified: trunk/libavcodec/twinvq.c
==============================================================================
--- trunk/libavcodec/twinvq.c	Sun Nov 22 22:08:46 2009	(r20583)
+++ trunk/libavcodec/twinvq.c	Sun Nov 22 23:25:58 2009	(r20584)
@@ -536,17 +536,6 @@ static void rearrange_lsp(int order, flo
         }
 }
 
-static void bubblesort(float *lsp, int lp_order)
-{
-    int i,j;
-
-    /* sort lsp in ascending order. float bubble agorithm,
-       O(n) if data already sorted, O(n^2) - otherwise */
-    for (i = 0; i < lp_order - 1; i++)
-        for (j = i; j >= 0 && lsp[j] > lsp[j+1]; j--)
-            FFSWAP(float, lsp[j], lsp[j+1]);
-}
-
 static void decode_lsp(TwinContext *tctx, int lpc_idx1, uint8_t *lpc_idx2,
                        int lpc_hist_idx, float *lsp, float *hist)
 {
@@ -583,7 +572,7 @@ static void decode_lsp(TwinContext *tctx
 
     rearrange_lsp(mtab->n_lsp, lsp, 0.0001);
     rearrange_lsp(mtab->n_lsp, lsp, 0.000095);
-    bubblesort(lsp, mtab->n_lsp);
+    ff_sort_nearly_sorted_floats(lsp, mtab->n_lsp);
 }
 
 static void dec_lpc_spectrum_inv(TwinContext *tctx, float *lsp,



More information about the ffmpeg-cvslog mailing list