static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { unsigned int i; /*channels*/ unsigned int j; /*frames*/ for (j=0;j<(unsigned)nframes;j++) { if(usejack) { /* write input to datanew */ fvec_write_sample(ibuf, input[0][j], pos); /* put synthnew in output */ output[0][j] = fvec_read_sample(obuf, pos); } /*time for fft*/ if (pos == overlap_size-1) { /* block loop */ aubio_onset_do (o, ibuf, onset); if ( fvec_read_sample(onset, 0) ) { fvec_copy (woodblock, obuf); } else { fvec_zeros (obuf); } /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } pos++; } return 1; }
int main (void) { uint_t length = 10; uint_t i; fvec_t * vec = new_fvec (length); fvec_t * other_vec = new_fvec (length); assert (vec); assert (other_vec); // vec->length matches requested size assert(vec->length == length); // all elements are initialized to `0.` for ( i = 0; i < vec->length; i++ ) { assert(vec->data[i] == 0.); } // all elements can be set to `1.` fvec_ones(vec); assert_fvec_all_equal(vec, 1.); // all elements can be set to `0.` fvec_zeros(vec); assert_fvec_all_equal(vec, 0.); // each element can be accessed directly for ( i = 0; i < vec->length; i++ ) { vec->data[i] = i; assert(vec->data[i] == i); } fvec_print(vec); fvec_set_sample(vec, 3, 2); assert(fvec_get_sample(vec, 2) == 3); assert(fvec_get_data(vec) == vec->data); // wrong parameters assert(new_fvec(-1) == NULL); // copy to an identical size works fvec_copy(vec, other_vec); del_fvec(other_vec); // copy to a different size fail other_vec = new_fvec(length + 1); fvec_copy(vec, other_vec); del_fvec(other_vec); // copy to a different size fail other_vec = new_fvec(length - 1); fvec_copy(vec, other_vec); // now destroys the vector if (vec) del_fvec(vec); if (other_vec) del_fvec(other_vec); return 0; }
void aubio_beattracking_do (aubio_beattracking_t * bt, const fvec_t * dfframe, fvec_t * output) { uint_t i, k; uint_t step = bt->step; uint_t laglen = bt->rwv->length; uint_t winlen = bt->dfwv->length; uint_t maxindex = 0; //number of harmonics in shift invariant comb filterbank uint_t numelem = 4; smpl_t phase; // beat alignment (step - lastbeat) smpl_t beat; // beat position smpl_t bp; // beat period uint_t a, b; // used to build shift invariant comb filterbank uint_t kmax; // number of elements used to find beat phase /* copy dfframe, apply detection function weighting, and revert */ fvec_copy (dfframe, bt->dfrev); fvec_weight (bt->dfrev, bt->dfwv); fvec_rev (bt->dfrev); /* compute autocorrelation function */ aubio_autocorr (dfframe, bt->acf); /* if timesig is unknown, use metrically unbiased version of filterbank */ if (!bt->timesig) { numelem = 4; } else { numelem = bt->timesig; } /* first and last output values are left intentionally as zero */ fvec_zeros (bt->acfout); /* compute shift invariant comb filterbank */ for (i = 1; i < laglen - 1; i++) { for (a = 1; a <= numelem; a++) { for (b = 1; b < 2 * a; b++) { bt->acfout->data[i] += bt->acf->data[i * a + b - 1] * 1. / (2. * a - 1.); } } } /* apply Rayleigh weight */ fvec_weight (bt->acfout, bt->rwv); /* find non-zero Rayleigh period */ maxindex = fvec_max_elem (bt->acfout); if (maxindex > 0 && maxindex < bt->acfout->length - 1) { bt->rp = fvec_quadratic_peak_pos (bt->acfout, maxindex); } else { bt->rp = bt->rayparam; } /* activate biased filterbank */ aubio_beattracking_checkstate (bt); #if 0 // debug metronome mode bt->bp = 36.9142; #endif bp = bt->bp; /* end of biased filterbank */ if (bp == 0) { fvec_zeros(output); return; } /* deliberate integer operation, could be set to 3 max eventually */ kmax = FLOOR (winlen / bp); /* initialize output */ fvec_zeros (bt->phout); for (i = 0; i < bp; i++) { for (k = 0; k < kmax; k++) { bt->phout->data[i] += bt->dfrev->data[i + (uint_t) ROUND (bp * k)]; } } fvec_weight (bt->phout, bt->phwv); /* find Rayleigh period */ maxindex = fvec_max_elem (bt->phout); if (maxindex >= winlen - 1) { #if AUBIO_BEAT_WARNINGS AUBIO_WRN ("no idea what this groove's phase is\n"); #endif /* AUBIO_BEAT_WARNINGS */ phase = step - bt->lastbeat; } else { phase = fvec_quadratic_peak_pos (bt->phout, maxindex); } /* take back one frame delay */ phase += 1.; #if 0 // debug metronome mode phase = step - bt->lastbeat; #endif /* reset output */ fvec_zeros (output); i = 1; beat = bp - phase; // AUBIO_DBG ("bp: %f, phase: %f, lastbeat: %f, step: %d, winlen: %d\n", // bp, phase, bt->lastbeat, step, winlen); /* the next beat will be earlier than 60% of the tempo period skip this one */ if ( ( step - bt->lastbeat - phase ) < -0.40 * bp ) { #if AUBIO_BEAT_WARNINGS AUBIO_WRN ("back off-beat error, skipping this beat\n"); #endif /* AUBIO_BEAT_WARNINGS */ beat += bp; } /* start counting the beats */ while (beat + bp < 0) { beat += bp; } if (beat >= 0) { //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat); output->data[i] = beat; i++; } while (beat + bp <= step) { beat += bp; //AUBIO_DBG ("beat: %d, %f, %f\n", i, bp, beat); output->data[i] = beat; i++; } bt->lastbeat = beat; /* store the number of beats in this frame as the first element */ output->data[0] = i; }
void aubio_filter_do_outplace (aubio_filter_t * f, fvec_t * in, fvec_t * out) { fvec_copy (in, out); aubio_filter_do (f, out); }
static smpl_t aubio_notes_get_latest_note (aubio_notes_t *o) { fvec_copy(o->note_buffer, o->note_buffer2); return fvec_median (o->note_buffer2) / AUBIO_DEFAULT_CENT_PRECISION; }