AubioOnsetDetector :: AubioOnsetDetector(){ buffersize = 1024; hopsize = 512; //aubio related setup o = new_aubio_onsetdetection(aubio_onset_complex, buffersize, 1);//initially in complex mode pv = (aubio_pvoc_t *)new_aubio_pvoc(buffersize, hopsize, 1); parms = new_aubio_peakpicker(threshold); vec = (fvec_t *)new_fvec(hopsize,1); threshold = 1; threshold2 = -70.; maximumDetectionValue = 10.0; resetValues(); thresholdRelativeToMedian = 1.1; cutoffForRepeatOnsetsMillis = 100; medianSpeed = 15; pos = 0; detectionTriggerRatio = 0.5f; detectionTriggerThreshold = 10; }
void AubioOnsetDetector :: initialise(){ //reinitialises our object o = new_aubio_onsetdetection(aubio_onset_complex, buffersize, 1);//initially in complex mode pv = (aubio_pvoc_t *)new_aubio_pvoc(buffersize, hopsize, 1); parms = new_aubio_peakpicker(threshold); vec = (fvec_t *)new_fvec(hopsize,1); pos = 0; fvec_write_sample(vec, 0.234, 0, pos); fftgrain = (cvec_t *)new_cvec(buffersize,1); onset = (fvec_t *)new_fvec(1,1); }
void aubio_init(int c) { channels = c; /* phase vocoder */ pv = new_aubio_pvoc(buffer_size, overlap_size, channels); ibuf = new_fvec(overlap_size, channels); fftgrain = new_cvec(buffer_size, channels); o = new_aubio_onsetdetection(type_onset, buffer_size, channels); parms = new_aubio_peakpicker(threshold); onset = new_fvec(1, channels); pos = 0; onset_n = 0; if (usedoubled) { o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels); onset2 = new_fvec(1 , channels); } }
int main() { /* allocate some memory */ uint_t win_s = 1024; /* window size */ fvec_t * in = new_fvec (win_s); /* input buffer */ fvec_t * out = new_fvec (1); /* input buffer */ aubio_peakpicker_t * o = new_aubio_peakpicker(); aubio_peakpicker_set_threshold (o, 0.3); aubio_peakpicker_do(o, in, out); aubio_peakpicker_do(o, in, out); aubio_peakpicker_do(o, in, out); aubio_peakpicker_do(o, in, out); del_aubio_peakpicker(o); del_fvec(in); return 0; }
/* Allocate memory for an onset detection */ aubio_onset_t * new_aubio_onset (const char_t * onset_mode, uint_t buf_size, uint_t hop_size, uint_t samplerate) { aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); /* check parameters are valid */ if ((sint_t)hop_size < 1) { AUBIO_ERR("onset: got hop_size %d, but can not be < 1\n", hop_size); goto beach; } else if ((sint_t)buf_size < 2) { AUBIO_ERR("onset: got buffer_size %d, but can not be < 2\n", buf_size); goto beach; } else if (buf_size < hop_size) { AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", buf_size, hop_size); goto beach; } else if ((sint_t)samplerate < 1) { AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate); goto beach; } /* store creation parameters */ o->samplerate = samplerate; o->hop_size = hop_size; /* allocate memory */ o->pv = new_aubio_pvoc(buf_size, o->hop_size); o->pp = new_aubio_peakpicker(); o->od = new_aubio_specdesc(onset_mode,buf_size); o->fftgrain = new_cvec(buf_size); o->desc = new_fvec(1); /* set some default parameter */ aubio_onset_set_threshold (o, 0.3); aubio_onset_set_delay(o, 4.3 * hop_size); aubio_onset_set_minioi_ms(o, 20.); aubio_onset_set_silence(o, -70.); /* initialize internal variables */ o->last_onset = 0; o->total_frames = 0; return o; beach: AUBIO_FREE(o); return NULL; }
/* Allocate memory for an onset detection */ aubio_onset_t * new_aubio_onset (const char_t * onset_mode, uint_t buf_size, uint_t hop_size, uint_t samplerate) { aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); /* check parameters are valid */ if ((sint_t)hop_size < 1) { AUBIO_ERR("onset: got hop_size %d, but can not be < 1\n", hop_size); goto beach; } else if ((sint_t)buf_size < 2) { AUBIO_ERR("onset: got buffer_size %d, but can not be < 2\n", buf_size); goto beach; } else if (buf_size < hop_size) { AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", hop_size, buf_size); goto beach; } else if ((sint_t)samplerate < 1) { AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate); goto beach; } /* store creation parameters */ o->samplerate = samplerate; o->hop_size = hop_size; /* allocate memory */ o->pv = new_aubio_pvoc(buf_size, o->hop_size); o->pp = new_aubio_peakpicker(); o->od = new_aubio_specdesc(onset_mode,buf_size); if (o->od == NULL) goto beach_specdesc; o->fftgrain = new_cvec(buf_size); o->desc = new_fvec(1); o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate); /* initialize internal variables */ aubio_onset_set_default_parameters (o, onset_mode); aubio_onset_reset(o); return o; beach_specdesc: del_aubio_peakpicker(o->pp); del_aubio_pvoc(o->pv); beach: AUBIO_FREE(o); return NULL; }
/* Allocate memory for an onset detection */ aubio_onset_t * new_aubio_onset (char_t * onset_mode, uint_t buf_size, uint_t hop_size, uint_t samplerate) { aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); /** set some default parameter */ o->samplerate = samplerate; o->hop_size = hop_size; o->last_onset = 0; o->threshold = 0.3; o->delay = 4.3 * hop_size; o->minioi = 5 * hop_size; o->silence = -70; o->total_frames = 0; o->pv = new_aubio_pvoc(buf_size, o->hop_size); o->pp = new_aubio_peakpicker(); aubio_peakpicker_set_threshold (o->pp, o->threshold); o->od = new_aubio_specdesc(onset_mode,buf_size); o->fftgrain = new_cvec(buf_size); o->desc = new_fvec(1); return o; }
/* Allocate memory for an tempo detection */ aubio_tempo_t * new_aubio_tempo (char_t * tempo_mode, uint_t buf_size, uint_t hop_size, uint_t samplerate) { aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t); char_t specdesc_func[20]; o->samplerate = samplerate; /* 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->total_frames = 0; o->last_beat = 0; o->delay = 0; o->hop_size = hop_size; o->dfframe = new_fvec(o->winlen); o->fftgrain = new_cvec(buf_size); o->out = new_fvec(o->step); o->pv = new_aubio_pvoc(buf_size, hop_size); o->pp = new_aubio_peakpicker(); aubio_peakpicker_set_threshold (o->pp, o->threshold); if ( strcmp(tempo_mode, "default") == 0 ) { strcpy(specdesc_func, "specflux"); } else { strcpy(specdesc_func, tempo_mode); } o->od = new_aubio_specdesc(specdesc_func,buf_size); o->of = new_fvec(1); o->bt = new_aubio_beattracking(o->winlen, o->hop_size, o->samplerate); o->onset = new_fvec(1); /*if (usedoubled) { o2 = new_aubio_specdesc(type_onset2,buffer_size); onset2 = new_fvec(1); }*/ return o; }
/* Allocate memory for an tempo detection */ aubio_tempo_t * new_aubio_tempo (aubio_onsetdetection_type type_onset, uint_t buf_size, uint_t hop_size, uint_t channels) { aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t); o->winlen = SQR(512)/hop_size; o->step = o->winlen/4; o->blockpos = 0; o->threshold = 0.3; o->silence = -90; o->blockpos = 0; o->dfframe = new_fvec(o->winlen,channels); o->fftgrain = new_cvec(buf_size, channels); o->out = new_fvec(o->step,channels); o->pv = new_aubio_pvoc(buf_size, hop_size, channels); o->pp = new_aubio_peakpicker(o->threshold); o->od = new_aubio_onsetdetection(type_onset,buf_size,channels); o->of = new_fvec(1, channels); o->bt = new_aubio_beattracking(o->winlen,channels); /*if (usedoubled) { o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels); onset2 = new_fvec(1 , channels); }*/ return o; }
void wav2midi_init(JNIEnv* env, jobject thiz) { LOGV("Aubio init"); JNIenv = env; counter = 0; const char * type_pitch_str; const char * type_onset_str; /* Read the member values from the Java Object that called sendSPAPacket() method */ jclass c = (*env)->GetObjectClass(env, thiz); jfieldID fid = (*env)->GetFieldID(env, c, "srcfilename", "Ljava/lang/String;"); jstring jaccess = (*env)->GetObjectField(env, thiz, fid); input_filename = (*env)->GetStringUTFChars(env, jaccess, 0); LOGD("Setting Input File: %s", input_filename); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "type_pitch", "Ljava/lang/String;"); jaccess = (*env)->GetObjectField(env, thiz, fid); type_pitch_str = (*env)->GetStringUTFChars(env, jaccess, 0); LOGD("Setting Aubio Pitch Algorithm: %s", type_pitch_str); set_pitch_type(type_pitch_str); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "type_onset", "Ljava/lang/String;"); jaccess = (*env)->GetObjectField(env, thiz, fid); type_onset_str = (*env)->GetStringUTFChars(env, jaccess, 0); LOGD("Setting Aubio Onset Algorithm: %s", type_onset_str); set_onset_type(type_onset_str); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "type_onset2", "Ljava/lang/String;"); jaccess = (*env)->GetObjectField(env, thiz, fid); type_onset_str = (*env)->GetStringUTFChars(env, jaccess, 0); LOGD("Setting Aubio Onset 2nd Algorithm: %s", type_onset_str); set_onset_type2(type_onset_str); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "samplerate", "I"); samplerate = (*env)->GetIntField(env, thiz, fid); LOGV("Setting Aubio SampleRate: %d", samplerate); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "buffer_size", "I"); buffer_size = (*env)->GetIntField(env, thiz, fid); LOGV("Setting Aubio buffer_size: %d", buffer_size); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "overlap_size", "I"); overlap_size = (*env)->GetIntField(env, thiz, fid); LOGV("Setting Aubio overlap_size: %d", overlap_size); /* c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "bitspersample", "I"); bitspersample = (*env)->GetIntField(env, thiz, fid); LOGV("PCM Bits per sample: %d", bitspersample); */ c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "channels", "I"); channels = (*env)->GetIntField(env, thiz, fid); LOGV("Setting Aubio Channels: %d", channels); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "threshold", "F"); if (fid != NULL) { threshold = (*env)->GetFloatField(env, thiz, fid); } LOGD("Setting Aubio threshold: %f", threshold); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "silence", "F"); if (fid != NULL) { silence = (*env)->GetFloatField(env, thiz, fid); } LOGD("Setting Aubio silence: %f", silence); c = (*env)->GetObjectClass(env, thiz); fid = (*env)->GetFieldID(env, c, "averaging", "F"); if (fid != NULL) { averaging = (*env)->GetFloatField(env, thiz, fid); } LOGD("Setting Aubio averaging: %f", averaging); debug("Read Java object Notes.\n"); Note = (*env)->FindClass(env, "com.atm.android.atm.midi.Note"); if (Note == NULL) { debug("Could not find Note class.\n"); return ; } midCtor = (*env)->GetMethodID(env, Note, "<init>", "(IIF)V"); debug("After init \n"); if (midCtor == NULL){ debug("Could not find Contructor method.\n"); return ; } notesArray = (*env)->NewObjectArray(env, 1000, Note, NULL); /* Sanity checks */ if (input_filename == NULL) { LOGV("Error: Need a file"); return; } debug("Opening input file: %s\n", input_filename); file = new_aubio_sndfile_ro(input_filename); debug("Opening input file finished: %s\n", input_filename); if (file == NULL) { outmsg("Could not open input file %s.\n", input_filename); debug("Could not open input file %s.\n", input_filename); exit(15); } verbose = 1; woodblock = new_fvec(buffer_size, 1); //Init Aubio with params if (verbose) aubio_sndfile_info(file); channels = aubio_sndfile_channels(file); samplerate = aubio_sndfile_samplerate(file); ibuf = new_fvec(overlap_size, channels); obuf = new_fvec(overlap_size, channels); fftgrain = new_cvec(buffer_size, channels); if (usepitch) { pitchdet = new_aubio_pitchdetection(buffer_size * 4, overlap_size, channels, samplerate, type_pitch, mode_pitch); aubio_pitchdetection_set_yinthresh(pitchdet, 0.7); if (median) { note_buffer = new_fvec(median, 1); note_buffer2 = new_fvec(median, 1); } } /* phase vocoder */ pv = new_aubio_pvoc(buffer_size, overlap_size, channels); /* onsets */ parms = new_aubio_peakpicker(threshold); o = new_aubio_onsetdetection(type_onset, buffer_size, channels); onset = new_fvec(1, channels); if (usedoubled) { o2 = new_aubio_onsetdetection(type_onset2, buffer_size, channels); onset2 = new_fvec(1, channels); } }