static void
aubioOnset_tilde_minioi (t_aubioOnset_tilde * x, t_float m)
{
    x->minioi = (m < 4) ? 4 : (int)m;
    aubio_onset_set_minioi(x->o,x->minioi); 
    post ("aubioOnset~ minioi:\t%d", x->minioi);
}
Beispiel #2
0
uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) {
  return aubio_onset_set_minioi (o, minioi * o->samplerate);
}
static void aubioOnset_minioi (t_aubioOnset * x, int m)
{
    x->minioi = (m < 4) ? 4 : (int)m;
    aubio_onset_set_minioi(x->o,x->minioi);
    post ("aubioonsethfc~ minioi:\t%d", x->minioi);
}
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);
}
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;
}