static void
aubioOnset_tilde_threshold (t_aubioOnset_tilde * x, t_float f)
{
    x->threshold = (f < 1e-5) ? 0.1 : (f > 10.) ? 10. : f;
    aubio_onset_set_threshold(x->o,f); 
    post ("aubioOnset~ threshold:\t%f", x->threshold);
}
示例#2
0
uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * onset_mode)
{
  uint_t ret = AUBIO_OK;
  /* set some default parameter */
  aubio_onset_set_threshold (o, 0.3);
  aubio_onset_set_delay (o, 4.3 * o->hop_size);
  aubio_onset_set_minioi_ms (o, 50.);
  aubio_onset_set_silence (o, -70.);
  // disable spectral whitening
  aubio_onset_set_awhitening (o, 0);
  // disable logarithmic magnitude
  aubio_onset_set_compression (o, 0.);

  /* method specific optimisations */
  if (strcmp (onset_mode, "energy") == 0) {
  } else if (strcmp (onset_mode, "hfc") == 0 || strcmp (onset_mode, "default") == 0) {
    aubio_onset_set_threshold (o, 0.058);
    aubio_onset_set_compression (o, 1.);
  } else if (strcmp (onset_mode, "complexdomain") == 0
             || strcmp (onset_mode, "complex") == 0) {
    aubio_onset_set_delay (o, 4.6 * o->hop_size);
    aubio_onset_set_threshold (o, 0.15);
    aubio_onset_set_awhitening(o, 1);
    aubio_onset_set_compression (o, 1.);
  } else if (strcmp (onset_mode, "phase") == 0) {
    o->apply_compression = 0;
    aubio_onset_set_awhitening (o, 0);
  } else if (strcmp (onset_mode, "wphase") == 0) {
    // use defaults for now
  } else if (strcmp (onset_mode, "mkl") == 0) {
    aubio_onset_set_threshold (o, 0.05);
    aubio_onset_set_awhitening(o, 1);
    aubio_onset_set_compression (o, 0.02);
  } else if (strcmp (onset_mode, "kl") == 0) {
    aubio_onset_set_threshold (o, 0.35);
    aubio_onset_set_awhitening(o, 1);
    aubio_onset_set_compression (o, 0.02);
  } else if (strcmp (onset_mode, "specflux") == 0) {
    aubio_onset_set_threshold (o, 0.18);
    aubio_onset_set_awhitening(o, 1);
    aubio_spectral_whitening_set_relax_time(o->spectral_whitening, 100);
    aubio_spectral_whitening_set_floor(o->spectral_whitening, 1.);
    aubio_onset_set_compression (o, 10.);
  } else if (strcmp (onset_mode, "specdiff") == 0) {
  } else if (strcmp (onset_mode, "old_default") == 0) {
    // used to reproduce results obtained with the previous version
    aubio_onset_set_threshold (o, 0.3);
    aubio_onset_set_minioi_ms (o, 20.);
    aubio_onset_set_compression (o, 0.);
  } else {
    AUBIO_WRN("onset: unknown spectral descriptor type %s, "
               "using default parameters.\n", onset_mode);
    ret = AUBIO_FAIL;
  }
  return ret;
}
示例#3
0
aubio_notes_t * new_aubio_notes (const char_t * method,
    uint_t buf_size, uint_t hop_size, uint_t samplerate) {
  aubio_notes_t *o = AUBIO_NEW(aubio_notes_t);

  const char_t * onset_method = "default";
  const char_t * pitch_method = "default";

  o->onset_buf_size = buf_size;
  o->pitch_buf_size = buf_size * 4;
  o->hop_size = hop_size;

  o->onset_threshold = 0.;
  o->pitch_tolerance = 0.;

  o->samplerate = samplerate;

  o->median = 6;

  o->isready = 0;

  o->onset = new_aubio_onset (onset_method, o->onset_buf_size, o->hop_size, o->samplerate);
  if (o->onset_threshold != 0.) aubio_onset_set_threshold (o->onset, o->onset_threshold);
  o->onset_output = new_fvec (1);

  o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate);
  if (o->pitch == NULL) goto fail;
  if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance);
  aubio_pitch_set_unit (o->pitch, "midi");
  o->pitch_output = new_fvec (1);

  if (strcmp(method, "default") != 0) {
    AUBIO_ERR("notes: unknown notes detection method \"%s\"\n", method);
    goto fail;
  }
  o->note_buffer = new_fvec(o->median);
  o->note_buffer2 = new_fvec(o->median);

  o->curnote = -1.;
  o->newnote = 0.;

  aubio_notes_set_silence(o, AUBIO_DEFAULT_NOTES_SILENCE);
  aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS);

  return o;

fail:
  del_aubio_notes(o);
  return NULL;
}
示例#4
0
void Note2midi::set_plugin(){
   o = new_aubio_onset (onset_method, PARAM_BUFFER_SIZE, PARAM_HOP_SIZE_ONSET, samplerate);
   if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
   onset = new_fvec (1);

   pitch = new_aubio_pitch (pitch_method, PARAM_BUFFER_SIZE * PARAM_PITCH_BUFF_TIMES, PARAM_HOP_SIZE_PITCH, samplerate);
   if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance);
   pitch_obuf = new_fvec (1);

   printf("%s\n", pitch_unit);

   if (median) {
      note_buffer = new_fvec (median);
      note_buffer2 = new_fvec (median);
  }
}
示例#5
0
文件: onset.c 项目: XunjunYin/aubio
/* 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;
}
示例#6
0
int main(int argc, char **argv) {
  frames_delay = 3;
  examples_common_init(argc,argv);

  o = new_aubio_onset (onset_mode, buffer_size, overlap_size, samplerate);
  if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
  onset = new_fvec (1);

  examples_common_process(aubio_process,process_print);

  del_aubio_onset (o);
  del_fvec (onset);

  examples_common_del();
  debug("End of program.\n");
  fflush(stderr);
  return 0;
}
static void aubioOnset_threshold (t_aubioOnset * x, t_float f)
{
    x->threshold = (f < 1e-5) ? 0.1 : (f > 0.999) ? 0.999 : f;
    aubio_onset_set_threshold(x->o,f);
    post ("aubioonsethfc~ threshold:\t%f", x->threshold);
}
void *aubioOnset_new(t_symbol *s, long argc, t_atom *argv)
{
    t_aubioOnset *x = (t_aubioOnset *)object_alloc(aubioOnset_class);
    t_atom *ap;
    int i, isPow2, argcount=0;
    //s=s;

    if (x) {
        dsp_setup((t_pxobject *)x, 1);	// MSP inlets: arg is # of inlets and is REQUIRED!
        // use 0 if you don't need inlets
        //outlet_new(x, "signal"); 		// signal outlet (note "signal" rather than NULL)

        x->onsetbang = bangout(x);

        x->sr = 44100.0;
        x->n = 64.0;

        x->threshold = 0.3;
        x->silence = -70;
        x->minioi = 4;
        x->bufsize = 1024;
        x->hopsize = 512;
        x->detectionFunction = "complex";

        // increment ap each time to get to the next atom
        for (i = 0, ap = argv; i < argc; i++, ap++)
        {
            switch (atom_gettype(ap)) {
            case A_LONG:
                if (atom_getlong(ap)<0)
                {
                    post("%ld: silence threshold %ld",i+1,atom_getlong(ap));
                    x->silence = (atom_getlong(ap) < -120) ? -120 : (atom_getlong(ap) > 0) ? 0 : atom_getlong(ap);
                }
                else
                {
                    if (argcount == 0) {
                        post("%ld: bufsize %ld",i+1,atom_getlong(ap));
                        x->bufsize = atom_getlong(ap);
                        argcount = argcount + 1;
                    }
                    else {
                        post("%ld: hopsize %ld",i+1,atom_getlong(ap));
                        x->hopsize = atom_getlong(ap);
                    }
                }
                break;
            case A_FLOAT:
                post("%ld: threshold %.2f",i+1,atom_getfloat(ap));
                x->threshold = (atom_getfloat(ap) < 1e-5) ? 0.1 : (atom_getfloat(ap) > 0.999) ? 0.999 : atom_getfloat(ap);
                break;
            case A_SYM:
                post("%ld: onset detection function %s",i+1, atom_getsym(ap)->s_name);
                x->detectionFunction = atom_getsym(ap)->s_name;
                break;
            default:
                post("%ld: unknown atom type (%ld)", i+1, atom_gettype(ap));
                break;
            }
        }

        isPow2 = (int)x->bufsize && !( ((int)x->bufsize-1) & (int)x->bufsize );
        if(!isPow2)
        {
            error("requested buffer size is not a power of 2. default value of 1024 used instead");
            x->bufsize = 1024;
        }
        isPow2 = (int)x->hopsize && !( ((int)x->hopsize-1) & (int)x->hopsize );
        if(!isPow2)
        {
            error("requested hop size is not a power of 2. default value of 1024 used instead");
            x->hopsize = x->bufsize / 4;
        }


        if (strcmp(x->detectionFunction,"hfc") == 0) x->o=new_aubio_onset(aubio_onset_hfc,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"energy") == 0) x->o=new_aubio_onset(aubio_onset_energy,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"phase") == 0) x->o=new_aubio_onset(aubio_onset_phase,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"complex") == 0) x->o=new_aubio_onset(aubio_onset_complex,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"specdiff") == 0) x->o=new_aubio_onset(aubio_onset_specdiff,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"kl") == 0) x->o=new_aubio_onset(aubio_onset_kl,x->bufsize, x->hopsize, 1);
        else if (strcmp(x->detectionFunction,"mkl") == 0) x->o=new_aubio_onset(aubio_onset_mkl,x->bufsize, x->hopsize, 1);
        else x->o=new_aubio_onset(aubio_onset_complex,x->bufsize, x->hopsize, 1);


        x->in = (fvec_t *) new_fvec (x->hopsize, 1);
        x->out = (fvec_t *) new_fvec (1, 1);

        aubio_onset_set_threshold(x->o,x->threshold);
        aubio_onset_set_silence(x->o,x->silence);
        aubio_onset_set_minioi(x->o,x->minioi);

        post("aubioOnset~: version 0.3");

    }
    return (x);
}
示例#9
0
void Note2midi::run(LV2_Handle instance, uint32_t SampleCount)
{
    Note2midi *plugin = (Note2midi *) instance;

    unsigned int new_onset_method = (unsigned int)(*plugin->_onset_method);
    unsigned int new_pitch_method = (unsigned int)(*plugin->_pitch_method);
    char_t* on_meth;
    char_t* pi_meth;

    silence_threshold = *(plugin->_silence_threshold);

    aubio_onset_set_threshold(plugin->o, *plugin->_onset_threshold);
    aubio_pitch_set_tolerance(plugin->pitch, *plugin->_pitch_method);

    if(0 <= new_onset_method && 16 >= new_onset_method &&
        new_onset_method != plugin->current_onset_method){ 
        
        del_aubio_onset(plugin->o);

        switch(new_onset_method){
            case ONSET_METHOD_ENERGY:
            on_meth = "energy";
            break;
            case ONSET_METHOD_SPECDIFF:
            on_meth = "specdiff";
            break;
            case ONSET_METHOD_HFC:
            on_meth = "hfc";
            break;
            case ONSET_METHOD_COMPLEXDOMAIN:
            on_meth = "complexdomain";
            break;
            case ONSET_METHOD_COMPLEX:
            on_meth = "complex";
            break;
            case ONSET_METHOD_PHASE:
            on_meth = "phase";
            break;
            case ONSET_METHOD_MKL:
            on_meth = "mkl";
            break;
            case ONSET_METHOD_KL:
            on_meth = "kl";
            break;
            case ONSET_METHOD_SPECFLUX:
            on_meth = "specflux";
            break;
            case ONSET_METHOD_CENTROID:
            on_meth = "centroid";
            break;
            case ONSET_METHOD_SPREAD:
            on_meth = "spread";
            break;
            case ONSET_METHOD_SKEWNESS:
            on_meth = "skewness";
            break;
            case ONSET_METHOD_KURTOSIS:
            on_meth = "kurtosis";
            break;
            case ONSET_METHOD_SLOPE:
            on_meth = "slope";
            break;
            case ONSET_METHOD_DECREASE:
            on_meth = "decrease";
            break;
            case ONSET_METHOD_ROLLOFF:
            on_meth = "rolloff";
            break;
            default:
            on_meth = "default";
            break;
        }


        plugin->o = new_aubio_onset (on_meth, PARAM_BUFFER_SIZE, PARAM_HOP_SIZE_ONSET, plugin->samplerate);
        
        plugin->current_onset_method = new_onset_method;
    }

    if(0 <= new_pitch_method && 6 >= new_pitch_method &&
        new_pitch_method != plugin->current_pitch_method){
        del_aubio_pitch(plugin->pitch);

        switch(new_pitch_method){
            case PITCH_METHOD_MCOMB:
            pi_meth = "mcomb";
            break;
            case PITCH_METHOD_YINFFT:
            pi_meth = "yinfft";
            break;
            case PITCH_METHOD_YIN:
            pi_meth = "yin";
            break;
            case PITCH_METHOD_SCHMITT:
            pi_meth = "schmitt";
            break;
            case PITCH_METHOD_FCOMB:
            pi_meth = "fcomb";
            break;
            case PITCH_METHOD_SPECACF:
            pi_meth = "specacf";
            break;
            default:
            pi_meth = "default";
            break;
        }


        plugin->pitch = new_aubio_pitch (pi_meth, PARAM_BUFFER_SIZE * PARAM_PITCH_BUFF_TIMES, PARAM_HOP_SIZE_PITCH, plugin->samplerate);
     
        // aubio_pitch_set_unit (plugin->pitch, plugin->pitch_unit);

        plugin->current_pitch_method = new_pitch_method;
    }

    out_capacity = plugin->out->atom.size;

    plugin->out->atom.type = plugin->atom_sequence;
    lv2_atom_sequence_clear(plugin->out);

    plugin->ibuf->data = (smpl_t *) plugin->in;

    counter++;

    if(counter++ >= PARAM_BUFFER_SIZE)
        counter = 0;

    plugin->process_block();
}
static void *
aubioOnset_tilde_new (t_symbol *s, long argc, t_atom *argv)
{
    t_atom *ap;
    int i, isPow2, argcount=0;
    t_aubioOnset_tilde *x =
    (t_aubioOnset_tilde *) pd_new (aubioOnset_tilde_class);
    
    
    x->threshold = 0.3;
    x->silence = -70;
    x->minioi = 4;
    x->bufsize = 1024;
    x->hopsize = 512;
    x->detectionFunction = "complex";
    
    for (i = 0, ap = argv; i < argc; i++, ap++) 
    {
        if (atom_getintarg(i, argc, argv))
        {
            if (atom_getint(ap)<0)
            {
                post("%ld: silence threshold %ld",i+1,atom_getint(ap));
                x->silence = (atom_getint(ap) < -120) ? -120 : (atom_getint(ap) > 0) ? 0 : atom_getint(ap);
            }
            else 
            {
                if (argcount == 0) {
                    post("%ld: bufsize %ld",i+1,atom_getint(ap));
                    x->bufsize = atom_getint(ap);
                    argcount = argcount + 1;       
                }
                else {
                    post("%ld: hopsize %ld",i+1,atom_getint(ap));
                    x->hopsize = atom_getint(ap);
                }
            }

        }
        else if (atom_getfloatarg(i, argc, argv))
        {
            post("%ld: threshold %.2f",i+1,atom_getfloat(ap));
            x->threshold = (atom_getfloat(ap) < 1e-5) ? 0.1 : (atom_getfloat(ap) > 0.999) ? 0.999 : atom_getfloat(ap);
        }
        else if (atom_getsymbolarg(i, argc, argv))
        {
            post("%ld: onset detection function %s",i+1, atom_getsymbol(ap)->s_name);
            x->detectionFunction = atom_getsymbol(ap)->s_name;
        }
        else post("%ld: unknown argument type", i+1);
    }

    isPow2 = (int)x->bufsize && !( ((int)x->bufsize-1) & (int)x->bufsize );            
    if(!isPow2)
    {
        error("requested buffer size is not a power of 2. default value of 1024 used instead");
        x->bufsize = 1024;
    }
    isPow2 = (int)x->hopsize && !( ((int)x->hopsize-1) & (int)x->hopsize );            
    if(!isPow2)
    {
        error("requested hop size is not a power of 2. default value of 256 used instead");
        x->hopsize = x->bufsize / 4;
    }
    
    
    if (strcmp(x->detectionFunction,"hfc") == 0) x->o=new_aubio_onset(aubio_onset_hfc,x->bufsize, x->hopsize, 1);
    else if (strcmp(x->detectionFunction,"energy") == 0) x->o=new_aubio_onset(aubio_onset_energy,x->bufsize, x->hopsize, 1);
    else if (strcmp(x->detectionFunction,"phase") == 0) x->o=new_aubio_onset(aubio_onset_phase,x->bufsize, x->hopsize, 1);
    else if (strcmp(x->detectionFunction,"complex") == 0) x->o=new_aubio_onset(aubio_onset_complex,x->bufsize, x->hopsize, 1);
    else if (strcmp(x->detectionFunction,"specdiff") == 0) x->o=new_aubio_onset(aubio_onset_specdiff,x->bufsize, x->hopsize, 1);
    else if (strcmp(x->detectionFunction,"kl") == 0) x->o=new_aubio_onset(aubio_onset_kl,x->bufsize, x->hopsize, 1);
    else if (strcmp(x->detectionFunction,"mkl") == 0) x->o=new_aubio_onset(aubio_onset_mkl,x->bufsize, x->hopsize, 1);
    else x->o=new_aubio_onset(aubio_onset_complex,x->bufsize, x->hopsize, 1);    
    
 
    x->in = (fvec_t *) new_fvec (x->hopsize, 1);
    x->out = (fvec_t *) new_fvec (1, 1);
    
    x->onsetbang = outlet_new (&x->x_obj, &s_bang);
    post (aubioOnset_version);    
     
    aubio_onset_set_threshold(x->o,x->threshold); 
    aubio_onset_set_silence(x->o,x->silence);  
    aubio_onset_set_minioi(x->o,x->minioi);  
    
    return (void *) x;
}