Index: examples/aubiotrack.c
===================================================================
--- examples/aubiotrack.c	(revision b78805a67bc32ed91a6da4e02647755dbbdf6338)
+++ examples/aubiotrack.c	(revision 2cdae8125fac1e0d46450b8c910a60fb8f335f41)
@@ -81,6 +81,6 @@
       istactus = 0;
       i=0;
-      for (i = 1; i <= btoutput[0]; i++ ) { 
-              if (pos2 == btoutput[i] && btoutput[i] != 0.) {
+      for (i = 1; i < btoutput[0]; i++ ) { 
+              if (pos2 == btoutput[i]) {
                       //printf("pos2: %d\n", pos2);
                       /* test for silence */
@@ -113,6 +113,6 @@
         if (output_filename == NULL) {
                 if (istactus)
-                        outmsg("%d\t%f",pos2,(frames)*overlap_size/(float)samplerate); 
-                if (isonset)
+                        outmsg("%f\n",(frames)*overlap_size/(float)samplerate); 
+                if (isonset && verbose)
                         outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
         }
Index: src/beattracking.c
===================================================================
--- src/beattracking.c	(revision b78805a67bc32ed91a6da4e02647755dbbdf6338)
+++ src/beattracking.c	(revision 2cdae8125fac1e0d46450b8c910a60fb8f335f41)
@@ -30,7 +30,8 @@
 uint_t fvec_gettimesig(smpl_t * acf, uint_t acflen, uint_t gp);
 void aubio_beattracking_checkstate(aubio_beattracking_t * bt);
+smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp);
 
 /* could move to struct */
-uint_t gp=0, bp = 0, rp1 = 0, rp2 = 0;
+uint_t gp=0, bp = 0, rp1 = 0, rp2 = 0, bp2 = 0;
 smpl_t g_mu =0.;
 smpl_t g_var = 3.901;
@@ -45,4 +46,13 @@
 //number of harmonics in shift invariant comb filterbank
 uint_t numelem   = 4;
+smpl_t myperiod = 0.;
+
+
+// FIXME
+uint_t maxnumelem = 4;
+uint_t len = 512;
+smpl_t inds[4]; //vector for max index outputs for each harmonic
+smpl_t local_acf[512]; //vector to store harmonics of filterbank of acf
+
 
 struct _aubio_beattracking_t {
@@ -160,7 +170,8 @@
         for (i=0; i < bt->acfout->length; i++)
                 acfout[i] = 0.;
+
         for(i=1;i<laglen-1;i++){ 
-                for (a=1;a<=numelem;a++){
-                        for(b=(1-a);b<a;b++){
+                for (a=1; a<=numelem; a++){
+                        for(b=(1-a); b<a; b++){
                                 acfout[i] += acf[a*(i+1)+b-1] 
                                         * 1./(2.*a-1.)*rwv[i];
@@ -174,4 +185,10 @@
         rp = (maxindex==127) ? 43 : maxindex; //rayparam
 
+        // get float period
+        myperiod = fvec_getperiod(acf,timesig,rp);
+	//AUBIO_DBG("\nrp =  %d myperiod = %f\n",rp,myperiod);
+	//AUBIO_DBG("accurate tempo is %f bpm\n",5168./myperiod);
+	
+
         /* activate biased filterbank */
         aubio_beattracking_checkstate(bt);
@@ -192,5 +209,4 @@
         }
 
-
         /* find Rayleigh period */
         maxindex = vec_max_elem(bt->phout);
@@ -209,5 +225,5 @@
         beat =  bp - phase;
         /* start counting the beats */
-        if(beat)
+        if(beat >= 0)
         {
                 output->data[0][i] = (smpl_t)beat;
@@ -245,4 +261,62 @@
         return (three_energy > four_energy) ? 3 : 4;
 }
+
+smpl_t fvec_getperiod(smpl_t * acf, uint_t timesig, uint_t rp){
+      	/*function to make a more accurate beat period measurement.*/
+
+	smpl_t period = 0.;
+	smpl_t maxval = 0.;
+	
+
+
+	int a,b;
+	uint_t i,j;	
+	uint_t acfmi = rp; //acfout max index
+	uint_t maxind = 0;
+
+	if(!timesig)
+		numelem = 4;
+	else
+		numelem = timesig;
+
+	for (i=0;i<numelem;i++) // initialize
+	inds[i] = 0.;
+
+	for (i=0;i<len;i++) // initialize
+	local_acf[i] = 0.;
+	
+	// get appropriate acf elements from acf and store in local_acf
+	for (a=1;a<=4;a++){
+	     	for(b=(1-a);b<a;b++){		
+               		local_acf[a*(acfmi)+b-1] = acf[a*(acfmi)+b-1];		               	           	      
+               	            }
+			}
+
+	for(i=0;i<numelem;i++){
+
+		maxindex = 0;
+		maxval = 0.0;
+	
+		for (j=0;j<(acfmi*(i+1)+(i)); j++){
+			if(local_acf[j]>maxval){
+				maxval = local_acf[j];
+				maxind = j;
+				}
+				local_acf[maxind] = 0.;
+		}
+		//printf("\n\n");
+		//AUBIO_DBG("\n maxind is  %d\n",maxind);
+		inds[i] = maxind;
+
+	}
+
+	for (i=0;i<numelem;i++){
+		period += inds[i]/(i+1.);}
+
+	period = period/numelem;
+
+	return (period);
+}
+
 
 void aubio_beattracking_checkstate(aubio_beattracking_t * bt) {
@@ -273,4 +347,8 @@
                 }
                 gp = vec_max_elem(bt->acfout);
+                /*
+	        while(gp<32) gp =gp*2;
+	        while(gp>64) gp = gp/2;
+                */
         } else {
                 //still only using general model
@@ -339,13 +417,19 @@
         }
 
-
         /* do some further checks on the final bp value */
+
         /* if tempo is > 206 bpm, half it */
         while (bp < 25) {
+                AUBIO_DBG("warning, halving the tempo from %f\n", 5168./bp);
                 bp = bp*2;
-                AUBIO_DBG("warning, halving the tempo to %f\n", 5168./bp);
         }
         
-        AUBIO_DBG("tempo:\t%3.5f bpm | time signature: %d \n", 5168./bp, timesig);
-
-}
+        AUBIO_DBG("tempo:\t%3.5f bpm | ", 5168./bp);
+
+        /* smoothing */
+        //bp = (uint_t) (0.8 * (smpl_t)bp + 0.2 * (smpl_t)bp2);
+        //AUBIO_DBG("tempo:\t%3.5f bpm smoothed | bp2 %d | bp %d | ", 5168./bp, bp2, bp);
+        //bp2 = bp;
+        AUBIO_DBG("time signature: %d \n", timesig);
+
+}
