Index: src/tempo/beattracking.c
===================================================================
--- src/tempo/beattracking.c	(revision 18f14f96f086304b5047922062199f6a66562ed6)
+++ src/tempo/beattracking.c	(revision 77db4251fcafaa50893011c4325d269699dd9d11)
@@ -32,4 +32,6 @@
 struct _aubio_beattracking_t
 {
+  uint_t hop_size;       /** length of one tempo detection function sample, in audio samples */
+  uint_t samplerate;     /** samplerate of the original signal */
   fvec_t *rwv;           /** rayleigh weighting for beat period in general model */
   fvec_t *dfwv;          /** exponential weighting for beat alignment in general model */
@@ -55,12 +57,13 @@
 
 aubio_beattracking_t *
-new_aubio_beattracking (uint_t winlen)
+new_aubio_beattracking (uint_t winlen, uint_t hop_size, uint_t samplerate)
 {
 
   aubio_beattracking_t *p = AUBIO_NEW (aubio_beattracking_t);
   uint_t i = 0;
-  /* parameter for rayleigh weight vector - sets preferred tempo to
-   * 120bpm [43] */
-  smpl_t rayparam = 48. / 512. * winlen;
+  p->hop_size = hop_size;
+  p->samplerate = samplerate;
+  /* default value for rayleigh weighting - sets preferred tempo to 120bpm */
+  smpl_t rayparam = 60. * samplerate / 120. / hop_size;
   smpl_t dfwvnorm = EXP ((LOG (2.0) / rayparam) * (winlen + 2));
   /* length over which beat period is found [128] */
@@ -415,6 +418,6 @@
 aubio_beattracking_get_bpm (aubio_beattracking_t * bt)
 {
-  if (bt->bp != 0 && bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) {
-    return 5168. / fvec_quadratic_peak_pos (bt->acfout, bt->bp);
+  if (bt->bp != 0) {
+    return 60. * bt->samplerate/ bt->bp / bt->hop_size;
   } else {
     return 0.;
Index: src/tempo/beattracking.h
===================================================================
--- src/tempo/beattracking.h	(revision 18f14f96f086304b5047922062199f6a66562ed6)
+++ src/tempo/beattracking.h	(revision 77db4251fcafaa50893011c4325d269699dd9d11)
@@ -52,5 +52,6 @@
 
 */
-aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size);
+aubio_beattracking_t * new_aubio_beattracking(uint_t winlen, uint_t hop_size,
+    uint_t samplerate);
 
 /** track the beat 
Index: src/tempo/tempo.c
===================================================================
--- src/tempo/tempo.c	(revision 18f14f96f086304b5047922062199f6a66562ed6)
+++ src/tempo/tempo.c	(revision 77db4251fcafaa50893011c4325d269699dd9d11)
@@ -142,10 +142,10 @@
   aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
   o->samplerate = samplerate;
-  o->winlen = SQR(512)/hop_size;
+  /* length of observations, worth about 6 seconds */
+  o->winlen = aubio_next_power_of_two(5.8 * samplerate / hop_size);
   o->step = o->winlen/4;
   o->blockpos = 0;
   o->threshold = 0.3;
   o->silence = -90.;
-  o->blockpos = 0;
   o->total_frames = 0;
   o->last_beat = 0;
@@ -160,5 +160,5 @@
   o->od       = new_aubio_specdesc(onset_mode,buf_size);
   o->of       = new_fvec(1);
-  o->bt       = new_aubio_beattracking(o->winlen);
+  o->bt       = new_aubio_beattracking(o->winlen, o->hop_size, o->samplerate);
   o->onset    = new_fvec(1);
   /*if (usedoubled)    {
Index: tests/src/tempo/test-beattracking.c
===================================================================
--- tests/src/tempo/test-beattracking.c	(revision 18f14f96f086304b5047922062199f6a66562ed6)
+++ tests/src/tempo/test-beattracking.c	(revision 77db4251fcafaa50893011c4325d269699dd9d11)
@@ -12,5 +12,5 @@
 
   // create beattracking object
-  aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
+  aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s, 256, 44100);
 
   smpl_t bpm, confidence;
Index: tests/src/tempo/test-tempo.c
===================================================================
--- tests/src/tempo/test-tempo.c	(revision 18f14f96f086304b5047922062199f6a66562ed6)
+++ tests/src/tempo/test-tempo.c	(revision 77db4251fcafaa50893011c4325d269699dd9d11)
@@ -9,13 +9,14 @@
     PRINT_ERR("not enough arguments\n");
     PRINT_MSG("read a wave file as a mono vector\n");
-    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
+    PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n", argv[0]);
     return err;
   }
   uint_t samplerate = 0;
-  uint_t win_s = 1024; // window size
-  uint_t hop_size = win_s / 4;
+  if ( argc >= 3 ) samplerate = atoi(argv[2]);
+  uint_t win_size = 1024; // window size
+  if ( argc >= 4 ) win_size = atoi(argv[3]);
+  uint_t hop_size = win_size / 4;
+  if ( argc >= 5 ) hop_size = atoi(argv[4]);
   uint_t n_frames = 0, read = 0;
-  if ( argc == 3 ) samplerate = atoi(argv[2]);
-  if ( argc == 4 ) hop_size = atoi(argv[3]);
 
   char_t *source_path = argv[1];
@@ -30,5 +31,5 @@
 
   // create tempo object
-  aubio_tempo_t * o = new_aubio_tempo("default", win_s, hop_size, samplerate);
+  aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate);
 
   do {
