void aubio_wavetable_do ( aubio_wavetable_t * s, fvec_t * input, fvec_t * output) { uint_t i; if (s->playing) { smpl_t pos = s->last_pos; for (i = 0; i < output->length; i++) { smpl_t inc = aubio_parameter_get_next_value( s->freq ); inc *= (smpl_t)(s->wavetable_length) / (smpl_t) (s->samplerate); pos += inc; while (pos > s->wavetable_length) { pos -= s->wavetable_length; } output->data[i] = aubio_parameter_get_next_value ( s->amp ); output->data[i] *= interp_2(s->wavetable, pos); } s->last_pos = pos; } else { for (i = 0; i < output->length; i++) { aubio_parameter_get_next_value ( s->freq ); aubio_parameter_get_next_value ( s->amp ); } fvec_zeros (output); } // add input to output if needed if (input && input != output) { for (i = 0; i < output->length; i++) { output->data[i] += input->data[i]; } } }
void aubio_hist_dyn_notnull (aubio_hist_t *s, fvec_t *input) { uint_t i; sint_t tmp = 0; smpl_t ilow = fvec_min(input); smpl_t ihig = fvec_max(input); smpl_t step = (ihig-ilow)/(smpl_t)(s->nelems); /* readapt */ aubio_scale_set_limits (s->scaler, ilow, ihig, 0, s->nelems); /* recalculate centers */ s->cent->data[0] = ilow + 0.5f * step; for (i=1; i < s->nelems; i++) s->cent->data[i] = s->cent->data[0] + i * step; /* scale */ aubio_scale_do(s->scaler, input); /* reset data */ fvec_zeros(s->hist); /* run accum */ for (i=0; i < input->length; i++) { if (input->data[i] != 0) { tmp = (sint_t)FLOOR(input->data[i]); if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) s->hist->data[tmp] += 1; } } }
void aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out) { uint_t j, k; /* compute filterbank */ aubio_filterbank_do (mf->fb, in, mf->in_dct); /* compute log10 */ fvec_log10 (mf->in_dct); /* raise power */ //fvec_pow (mf->in_dct, 3.); /* zeros output */ fvec_zeros(out); /* compute discrete cosine transform */ for (j = 0; j < mf->n_filters; j++) { for (k = 0; k < mf->n_coefs; k++) { out->data[k] += mf->in_dct->data[j] * mf->dct_coeffs->data[j][k]; } } return; }
static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 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_pitch_do (o, ibuf, pitch); if (fvec_read_sample(pitch, 0)) { for (pos = 0; pos < overlap_size; pos++){ // TODO, play sine at this freq } } else { fvec_zeros (obuf); } /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } pos++; } return 1; }
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; }
void process_block(fvec_t * ibuf, fvec_t *obuf) { aubio_tempo_do (tempo, ibuf, tempo_out); is_beat = fvec_get_sample (tempo_out, 0); //smpl_t bpm = aubio_tempo_get_bpm(tempo); //uint_t last_beat = aubio_tempo_get_last(tempo); aubio_pitch_do (pitch, ibuf, pitch_out); smpl_t freq = fvec_get_sample(pitch_out, 0); if (silence_threshold != -90.) is_silence = aubio_silence_detection(ibuf, silence_threshold); fvec_zeros (obuf); if ( is_beat && !is_silence ) { samples_per_beat = total_frames - my_last_beat; my_last_beat = total_frames; aubio_wavetable_play ( wavetable ); } else { aubio_wavetable_stop ( wavetable ); } if (mix_input) aubio_wavetable_do (wavetable, ibuf, obuf); else aubio_wavetable_do (wavetable, obuf, obuf); rgb_music_iterate(my_last_beat, samples_per_beat, total_frames, freq); total_frames += hop_size; }
void process_block (fvec_t *ibuf, fvec_t *obuf) { fvec_zeros(obuf); //compute mag spectrum aubio_pvoc_do (pv, ibuf, fftgrain); //compute mfccs aubio_mfcc_do(mfcc, fftgrain, mfcc_out); }
void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * notes) { smpl_t new_pitch, curlevel; fvec_zeros(notes); aubio_onset_do(o->onset, input, o->onset_output); aubio_pitch_do (o->pitch, input, o->pitch_output); new_pitch = o->pitch_output->data[0]; if(o->median){ note_append(o->note_buffer, new_pitch); } /* curlevel is negatif or 1 if silence */ curlevel = aubio_level_detection(input, o->silence_threshold); if (o->onset_output->data[0] != 0) { /* test for silence */ if (curlevel == 1.) { if (o->median) o->isready = 0; /* send note off */ //send_noteon(o->curnote,0); //notes->data[0] = o->curnote; //notes->data[1] = 0.; notes->data[2] = o->curnote; } else { if (o->median) { o->isready = 1; } else { /* kill old note */ //send_noteon(o->curnote,0, o->samplerate); notes->data[2] = o->curnote; /* get and send new one */ //send_noteon(new_pitch,127+(int)floor(curlevel), o->samplerate); notes->data[0] = new_pitch; notes->data[1] = 127 + (int)floor(curlevel); o->curnote = new_pitch; } } } else { if (o->median) { if (o->isready > 0) o->isready++; if (o->isready == o->median) { /* kill old note */ //send_noteon(curnote,0); notes->data[2] = o->curnote; o->newnote = aubio_notes_get_latest_note(o); o->curnote = o->newnote; /* get and send new one */ if (o->curnote>45){ //send_noteon(curnote,127+(int)floor(curlevel)); notes->data[0] = o->curnote; notes->data[1] = 127 + (int) floor(curlevel); } } } // if median } }
void process_block(fvec_t * ibuf, fvec_t * obuf) { fvec_zeros(obuf); aubio_pitch_do (o, ibuf, pitch); smpl_t freq = fvec_read_sample(pitch, 0); aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) ); aubio_wavetable_set_freq ( wavetable, freq ); if (mix_input) aubio_wavetable_do (wavetable, ibuf, obuf); else aubio_wavetable_do (wavetable, obuf, obuf); }
void aubio_hist_do_notnull (aubio_hist_t *s, fvec_t *input) { uint_t j; sint_t tmp = 0; aubio_scale_do(s->scaler, input); /* reset data */ fvec_zeros(s->hist); /* run accum */ for (j=0; j < input->length; j++) { if (input->data[j] != 0) { tmp = (sint_t)FLOOR(input->data[j]); if ((tmp >= 0) && (tmp < (sint_t)s->nelems)) s->hist->data[tmp] += 1; } } }
void process_block(fvec_t * ibuf, fvec_t *obuf) { aubio_tempo_do (tempo, ibuf, tempo_out); is_beat = fvec_get_sample (tempo_out, 0); if (silence_threshold != -90.) is_silence = aubio_silence_detection(ibuf, silence_threshold); fvec_zeros (obuf); if ( is_beat && !is_silence ) { aubio_wavetable_play ( wavetable ); } else { aubio_wavetable_stop ( wavetable ); } if (mix_input) aubio_wavetable_do (wavetable, ibuf, obuf); else aubio_wavetable_do (wavetable, obuf, obuf); }
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_checkstate (aubio_beattracking_t * bt) { uint_t i, j, a, b; uint_t flagconst = 0; sint_t counter = bt->counter; uint_t flagstep = bt->flagstep; smpl_t gp = bt->gp; smpl_t bp = bt->bp; smpl_t rp = bt->rp; smpl_t rp1 = bt->rp1; smpl_t rp2 = bt->rp2; uint_t laglen = bt->rwv->length; uint_t acflen = bt->acf->length; uint_t step = bt->step; fvec_t *acf = bt->acf; fvec_t *acfout = bt->acfout; if (gp) { // compute shift invariant comb filterbank fvec_zeros (acfout); for (i = 1; i < laglen - 1; i++) { for (a = 1; a <= bt->timesig; a++) { for (b = 1; b < 2 * a; b++) { acfout->data[i] += acf->data[i * a + b - 1]; } } } // since gp is set, gwv has been computed in previous checkstate fvec_weight (acfout, bt->gwv); gp = fvec_quadratic_peak_pos (acfout, fvec_max_elem (acfout)); } else { //still only using general model gp = 0; } //now look for step change - i.e. a difference between gp and rp that // is greater than 2*constthresh - always true in first case, since gp = 0 if (counter == 0) { if (ABS (gp - rp) > 2. * bt->g_var) { flagstep = 1; // have observed step change. counter = 3; // setup 3 frame counter } else { flagstep = 0; } } //i.e. 3rd frame after flagstep initially set if (counter == 1 && flagstep == 1) { //check for consistency between previous beatperiod values if (ABS (2 * rp - rp1 - rp2) < bt->g_var) { //if true, can activate context dependent model flagconst = 1; counter = 0; // reset counter and flagstep } else { //if not consistent, then don't flag consistency! flagconst = 0; counter = 2; // let it look next time } } else if (counter > 0) { //if counter doesn't = 1, counter = counter - 1; } rp2 = rp1; rp1 = rp; if (flagconst) { /* first run of new hypothesis */ gp = rp; bt->timesig = fvec_gettimesig (acf, acflen, gp); for (j = 0; j < laglen; j++) bt->gwv->data[j] = EXP (-.5 * SQR ((smpl_t) (j + 1. - gp)) / SQR (bt->g_var)); flagconst = 0; bp = gp; /* flat phase weighting */ fvec_ones (bt->phwv); } else if (bt->timesig) { /* context dependant model */ bp = gp; /* gaussian phase weighting */ if (step > bt->lastbeat) { for (j = 0; j < 2 * laglen; j++) { bt->phwv->data[j] = EXP (-.5 * SQR ((smpl_t) (1. + j - step + bt->lastbeat)) / (bp / 8.)); } } else { //AUBIO_DBG("NOT using phase weighting as step is %d and lastbeat %d \n", // step,bt->lastbeat); fvec_ones (bt->phwv); } } else { /* initial state */ bp = rp; /* flat phase weighting */ fvec_ones (bt->phwv); } /* do some further checks on the final bp value */ /* if tempo is > 206 bpm, half it */ while (0 < bp && bp < 25) { #if AUBIO_BEAT_WARNINGS AUBIO_WRN ("doubling from %f (%f bpm) to %f (%f bpm)\n", bp, 60.*44100./512./bp, bp/2., 60.*44100./512./bp/2. ); //AUBIO_DBG("warning, halving the tempo from %f\n", 60.*samplerate/hopsize/bp); #endif /* AUBIO_BEAT_WARNINGS */ bp = bp * 2; } //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", bt->timesig); bt->counter = counter; bt->flagstep = flagstep; bt->gp = gp; bt->bp = bp; bt->rp1 = rp1; bt->rp2 = rp2; }
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; }