Index: pjproject/trunk/pjlib/include/pj/config_site_sample.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/config_site_sample.h	(revision 1970)
+++ pjproject/trunk/pjlib/include/pj/config_site_sample.h	(revision 1971)
@@ -27,5 +27,5 @@
 #   undef PJMEDIA_RESAMPLE_IMP
 #   define PJMEDIA_RESAMPLE_IMP		PJMEDIA_RESAMPLE_LIBRESAMPLE
-#   define PJMEDIA_WSOLA_IMP		PJMEDIA_WSOLA_IMP_NULL
+#   define PJMEDIA_WSOLA_IMP		PJMEDIA_WSOLA_IMP_WSOLA_LITE
 #endif
 
@@ -51,5 +51,5 @@
 #   define PJMEDIA_RESAMPLE_IMP		PJMEDIA_RESAMPLE_NONE
 #   define PJMEDIA_HAS_SPEEX_AEC	0
-#   define PJMEDIA_WSOLA_IMP		PJMEDIA_WSOLA_IMP_NULL
+#   define PJMEDIA_WSOLA_IMP		PJMEDIA_WSOLA_IMP_WSOLA_LITE
 
     /* Disable all codecs but G.711 and GSM, for now */
Index: pjproject/trunk/pjmedia/include/pjmedia/config.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/config.h	(revision 1970)
+++ pjproject/trunk/pjmedia/include/pjmedia/config.h	(revision 1971)
@@ -129,4 +129,10 @@
 #define PJMEDIA_WSOLA_IMP_WSOLA		    1
 
+/**
+ * This denotes implementation of WSOLA algorithm with faster waveform 
+ * similarity calculation. This implementation provides fair quality of 
+ * the result with the main advantage of low processing power requirement.
+ */
+#define PJMEDIA_WSOLA_IMP_WSOLA_LITE	    2
 
 /**
Index: pjproject/trunk/pjmedia/src/pjmedia/wsola.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/wsola.c	(revision 1970)
+++ pjproject/trunk/pjmedia/src/pjmedia/wsola.c	(revision 1971)
@@ -29,6 +29,7 @@
 #define THIS_FILE   "wsola.c"
 
-
-#if PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA) || \
+    (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA_LITE)
+
 /*
  * WSOLA implementation using WSOLA
@@ -114,4 +115,70 @@
 };
 
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA_LITE)
+
+/* In this implementation, waveform similarity comparison is done by calculating
+ * the difference of total level between template frame and the target buffer 
+ * for each template_cnt samples. The smallest difference value assumed to be 
+ * the most similar block. This seems to be naive, however some tests show
+ * acceptable results and the processing speed is amazing.
+ *
+ * diff level = (template[1]+..+template[n]) - (target[1]+..+target[n])
+ */
+static short *find_pitch(short *frm, short *beg, short *end, 
+			 unsigned template_cnt, int first)
+{
+    short *sr, *best=beg;
+    int best_corr = 0x7FFFFFFF;
+    int frm_sum = 0;
+    unsigned i;
+
+    for (i = 0; i<template_cnt; ++i)
+	frm_sum += frm[i];
+
+    for (sr=beg; sr!=end; ++sr) {
+	int corr = frm_sum;
+	int abs_corr = 0;
+
+	/* Do calculation on 8 samples at once */
+	for (i = 0; i<template_cnt; i+=8) {
+	    corr -= (int)sr[i+0] +
+		    (int)sr[i+1] +
+		    (int)sr[i+2] +
+		    (int)sr[i+3] +
+		    (int)sr[i+4] +
+		    (int)sr[i+5] +
+		    (int)sr[i+6] +
+		    (int)sr[i+7];
+	}
+
+	/* Reverse back i if template_cnt is not multiplication of 8,
+	 * the remaining samples will be processed below.
+	 */
+	if (i != template_cnt)
+	    i -= 8;
+
+	for (; i<template_cnt; ++i)
+	    corr -= (int)sr[i];
+
+	abs_corr = corr > 0? corr : -corr;
+
+	if (first) {
+	    if (abs_corr < best_corr) {
+		best_corr = abs_corr;
+		best = sr;
+	    }
+	} else {
+	    if (abs_corr <= best_corr) {
+		best_corr = abs_corr;
+		best = sr;
+	    }
+	}
+    }
+
+    /*TRACE_((THIS_FILE, "found pitch at %u", best-beg));*/
+    return best;
+}
+
+#endif
 
 #if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT!=0
@@ -121,4 +188,6 @@
 #include <math.h>
 
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA)
+
 static short *find_pitch(short *frm, short *beg, short *end, 
 			 unsigned template_cnt, int first)
@@ -131,4 +200,5 @@
 	unsigned i;
 
+	/* Do calculation on 8 samples at once */
 	for (i=0; i<template_cnt; i += 8) {
 	    corr += ((float)frm[i+0]) * ((float)sr[i+0]) + 
@@ -141,4 +211,11 @@
 		    ((float)frm[i+7]) * ((float)sr[i+7]);
 	}
+
+	/* Reverse back i if template_cnt is not multiplication of 8,
+	 * the remaining samples will be processed below.
+	 */
+	if (i != template_cnt)
+	    i -= 8;
+
 	for (; i<template_cnt; ++i) {
 	    corr += ((float)frm[i]) * ((float)sr[i]);
@@ -162,4 +239,6 @@
 }
 
+#endif
+
 static void overlapp_add(short dst[], unsigned count,
 			 short l[], short r[],
@@ -204,4 +283,6 @@
 enum { WINDOW_MAX_VAL = (1 << WINDOW_BITS)-1 };
 
+#if (PJMEDIA_WSOLA_IMP==PJMEDIA_WSOLA_IMP_WSOLA)
+
 static short *find_pitch(short *frm, short *beg, short *end, 
 			 unsigned template_cnt, int first)
@@ -215,4 +296,5 @@
 	unsigned i;
 
+	/* Do calculation on 8 samples at once */
 	for (i=0; i<template_cnt; i+=8) {
 	    corr += ((int)frm[i+0]) * ((int)sr[i+0]) + 
@@ -225,4 +307,11 @@
 		    ((int)frm[i+7]) * ((int)sr[i+7]);
 	}
+
+	/* Reverse back i if template_cnt is not multiplication of 8,
+	 * the remaining samples will be processed below.
+	 */
+	if (i != template_cnt)
+	    i -= 8;
+
 	for (; i<template_cnt; ++i) {
 	    corr += ((int)frm[i]) * ((int)sr[i]);
@@ -246,4 +335,7 @@
 }
 
+#endif
+
+
 static void overlapp_add(short dst[], unsigned count,
 			 short l[], short r[],
@@ -360,4 +452,11 @@
 	wsola->template_size = wsola->samples_per_frame;
 
+    /* Make sure minimal template size is 8, this is required by waveform 
+     * similarity calculation (find_pitch()). Moreover, smaller template size
+     * will reduce accuracy.
+     */
+    if (wsola->template_size < 8)
+	wsola->template_size = 8;
+
     wsola->buf = (short*)pj_pool_calloc(pool, wsola->buf_cnt, 
 					sizeof(short));
@@ -470,14 +569,18 @@
 	unsigned dist;
 
-	if (count <= (del_cnt << 1)) {
+	if ((count - del_cnt) <= frmsz) {
+	//if (count <= (del_cnt << 1)) {
 	    TRACE_((THIS_FILE, "Not enough samples to compress!"));
 	    return samples_del;
 	}
 
-	start = buf + (frmsz >> 1);
+	//start = buf + (frmsz >> 1);
+	start = buf + del_cnt - samples_del;
 	end = start + frmsz;
 
 	if (end + frmsz > buf + count)
 	    end = buf+count-frmsz;
+
+	pj_assert(start < end);
 
 	start = find_pitch(buf, start, end, wsola->template_size, 0);
@@ -818,5 +921,4 @@
 }
 
-
 #endif	/* #if PJMEDIA_WSOLA_IMP.. */
 
