aubio_pitchmcomb_t * new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize) { aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t); /* bug: should check if size / 8 > post+pre+1 */ uint_t i, j; uint_t spec_size; p->spec_partition = 4; p->ncand = 5; p->npartials = 5; p->cutoff = 1.; p->threshold = 0.01; p->win_post = 8; p->win_pre = 7; // p->tau = samplerate/bufsize; p->alpha = 9.; p->goodcandidate = 0; p->phasefreq = bufsize / hopsize / TWO_PI; p->phasediff = TWO_PI * hopsize / bufsize; spec_size = bufsize / p->spec_partition; //p->pickerfn = quadpick; //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348); /* allocate temp memory */ p->newmag = new_fvec (spec_size); /* array for median */ p->scratch = new_fvec (spec_size); /* array for phase */ p->theta = new_fvec (spec_size); /* array for adaptative threshold */ p->scratch2 = new_fvec (p->win_post + p->win_pre + 1); /* array of spectral peaks */ p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size); for (i = 0; i < spec_size; i++) { p->peaks[i].bin = 0.; p->peaks[i].ebin = 0.; p->peaks[i].mag = 0.; } /* array of pointers to spectral candidates */ p->candidates = AUBIO_ARRAY (aubio_spectralcandidate_t *, p->ncand); for (i = 0; i < p->ncand; i++) { p->candidates[i] = AUBIO_NEW (aubio_spectralcandidate_t); p->candidates[i]->ecomb = AUBIO_ARRAY (smpl_t, spec_size); for (j = 0; j < spec_size; j++) { p->candidates[i]->ecomb[j] = 0.; } p->candidates[i]->ene = 0.; p->candidates[i]->ebin = 0.; p->candidates[i]->len = 0.; } return p; }
aubio_resampler_t * new_aubio_resampler (smpl_t ratio, uint_t type) { aubio_resampler_t *s = AUBIO_NEW (aubio_resampler_t); int error = 0; s->stat = src_new (type, 1, &error); /* only one channel */ if (error) { AUBIO_ERR ("Failed creating resampler: %s\n", src_strerror (error)); del_aubio_resampler(s); return NULL; } s->proc = AUBIO_NEW (SRC_DATA); s->ratio = ratio; return s; }
cvec_t * new_cvec( uint_t length) { cvec_t * s = AUBIO_NEW(cvec_t); s->length = length/2 + 1; s->norm = AUBIO_ARRAY(smpl_t,s->length); s->phas = AUBIO_ARRAY(smpl_t,s->length); return s; }
aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) { aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t); s->max_size = MAX_SIZE; if (path == NULL) { AUBIO_ERR("sink_sndfile: Aborted opening null path\n"); return NULL; } if (s->path) AUBIO_FREE(s->path); s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); s->samplerate = 0; s->channels = 0; // negative samplerate given, abort if ((sint_t)samplerate < 0) goto beach; // zero samplerate given. do not open yet if ((sint_t)samplerate == 0) return s; s->samplerate = samplerate; s->channels = 1; if (aubio_sink_sndfile_open(s) != AUBIO_OK) {; goto beach; } return s; beach: del_aubio_sink_sndfile(s); return NULL; }
aubio_filterbank_t * new_aubio_filterbank (uint_t n_filters, uint_t win_s) { /* allocate space for filterbank object */ aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t); if ((sint_t)n_filters <= 0) { AUBIO_ERR("filterbank: n_filters should be > 0, got %d\n", n_filters); goto fail; } if ((sint_t)win_s <= 0) { AUBIO_ERR("filterbank: win_s should be > 0, got %d\n", win_s); goto fail; } fb->win_s = win_s; fb->n_filters = n_filters; /* allocate filter tables, a matrix of length win_s and of height n_filters */ fb->filters = new_fmat (n_filters, win_s / 2 + 1); fb->norm = 1; fb->power = 1; return fb; fail: AUBIO_FREE (fb); return NULL; }
aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s) { aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t); /* if (win_s < 2*hop_s) { AUBIO_WRN("Hop size bigger than half the window size!\n"); } */ if (hop_s < 1) { AUBIO_ERR("Hop size is smaller than 1!\n"); AUBIO_ERR("Resetting hop size to half the window size.\n"); hop_s = win_s / 2; } pv->fft = new_aubio_fft (win_s); /* remember old */ pv->data = new_fvec (win_s); pv->synth = new_fvec (win_s); /* new input output */ pv->dataold = new_fvec (win_s-hop_s); pv->synthold = new_fvec (win_s-hop_s); pv->w = new_aubio_window ("hanningz", win_s); pv->hop_s = hop_s; pv->win_s = win_s; return pv; }
aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) { aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t); if (win_s < 2*hop_s) { AUBIO_ERR("Hop size bigger than half the window size!\n"); AUBIO_ERR("Resetting hop size to half the window size.\n"); hop_s = win_s / 2; } if (hop_s < 1) { AUBIO_ERR("Hop size is smaller than 1!\n"); AUBIO_ERR("Resetting hop size to half the window size.\n"); hop_s = win_s / 2; } pv->fft = new_aubio_mfft(win_s,channels); /* remember old */ pv->data = new_fvec (win_s, channels); pv->synth = new_fvec (win_s, channels); /* new input output */ pv->dataold = new_fvec (win_s-hop_s, channels); pv->synthold = new_fvec (win_s-hop_s, channels); pv->w = AUBIO_ARRAY(smpl_t,win_s); aubio_window(pv->w,win_s,aubio_win_hanningz); pv->channels = channels; pv->hop_s = hop_s; pv->win_s = win_s; return pv; }
aubio_wavetable_t *new_aubio_wavetable(uint_t samplerate, uint_t blocksize) { uint_t i = 0; aubio_wavetable_t *s = AUBIO_NEW(aubio_wavetable_t); if ((sint_t)samplerate <= 0) { AUBIO_ERR("Can not create wavetable with samplerate %d\n", samplerate); goto beach; } s->samplerate = samplerate; s->blocksize = blocksize; s->wavetable_length = WAVETABLE_LEN; s->wavetable = new_fvec(s->wavetable_length + 3); for (i = 0; i < s->wavetable_length; i++) { s->wavetable->data[i] = SIN(TWO_PI * i / (smpl_t) s->wavetable_length ); } s->wavetable->data[s->wavetable_length] = s->wavetable->data[0]; s->wavetable->data[s->wavetable_length + 1] = s->wavetable->data[1]; s->wavetable->data[s->wavetable_length + 2] = s->wavetable->data[2]; s->playing = 0; s->last_pos = 0.; s->freq = new_aubio_parameter( 0., s->samplerate / 2., 10 ); s->amp = new_aubio_parameter( 0., 1., 100 ); return s; beach: AUBIO_FREE(s); return NULL; }
aubio_pitchyin_t * new_aubio_pitchyin (uint_t bufsize) { aubio_pitchyin_t *o = AUBIO_NEW (aubio_pitchyin_t); o->yin = new_fvec (bufsize / 2); o->tol = 0.15; return o; }
aubio_list_t* new_aubio_list(void) { aubio_list_t* list; list = AUBIO_NEW(aubio_list_t); list->data = NULL; list->next = NULL; return list; }
lvec_t * new_lvec( uint_t length) { lvec_t * s = AUBIO_NEW(lvec_t); uint_t j; s->length = length; s->data = AUBIO_ARRAY(lsmp_t, s->length); for (j=0; j< s->length; j++) { s->data[j]=0.; } return s; }
fvec_t * new_fvec(uint_t length) { fvec_t * s; if ((sint_t)length <= 0) { return NULL; } s = AUBIO_NEW(fvec_t); s->length = length; s->data = AUBIO_ARRAY(smpl_t, s->length); return s; }
/* memory management */ static aubio_jack_t * aubio_jack_alloc(uint_t ichan, uint_t ochan) { aubio_jack_t *jack_setup = AUBIO_NEW(aubio_jack_t); jack_setup->ichan = ichan; jack_setup->ochan = ochan; jack_setup->oports = AUBIO_ARRAY(jack_port_t*, ichan); jack_setup->iports = AUBIO_ARRAY(jack_port_t*, ochan); jack_setup->ibufs = AUBIO_ARRAY(jack_sample_t*, ichan); jack_setup->obufs = AUBIO_ARRAY(jack_sample_t*, ochan); return jack_setup; }
cvec_t * new_cvec(uint_t length) { cvec_t * s; if ((sint_t)length <= 0) { return NULL; } s = AUBIO_NEW(cvec_t); s->length = length/2 + 1; s->norm = AUBIO_ARRAY(smpl_t,s->length); s->phas = AUBIO_ARRAY(smpl_t,s->length); return s; }
aubio_sampler_t *new_aubio_sampler(uint_t samplerate, uint_t blocksize) { aubio_sampler_t *s = AUBIO_NEW(aubio_sampler_t); s->samplerate = samplerate; s->blocksize = blocksize; s->source_output = new_fvec(blocksize); s->source_output_multi = new_fmat(blocksize, 4); s->source = NULL; s->playing = 0; return s; }
aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) { aubio_sink_t * s = AUBIO_NEW(aubio_sink_t); #ifdef HAVE_SINK_APPLE_AUDIO s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate); if (s->sink) { s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do); s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_apple_audio_do_multi); s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_apple_audio_preset_samplerate); s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_apple_audio_preset_channels); s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_apple_audio_get_samplerate); s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_apple_audio_get_channels); s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close); s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio); return s; } #endif /* HAVE_SINK_APPLE_AUDIO */ #ifdef HAVE_SNDFILE s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate); if (s->sink) { s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do); s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_sndfile_do_multi); s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_sndfile_preset_samplerate); s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_sndfile_preset_channels); s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_sndfile_get_samplerate); s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_sndfile_get_channels); s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close); s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile); return s; } #endif /* HAVE_SNDFILE */ #ifdef HAVE_WAVWRITE s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate); if (s->sink) { s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do); s->s_do_multi = (aubio_sink_do_multi_t)(aubio_sink_wavwrite_do_multi); s->s_preset_samplerate = (aubio_sink_preset_samplerate_t)(aubio_sink_wavwrite_preset_samplerate); s->s_preset_channels = (aubio_sink_preset_channels_t)(aubio_sink_wavwrite_preset_channels); s->s_get_samplerate = (aubio_sink_get_samplerate_t)(aubio_sink_wavwrite_get_samplerate); s->s_get_channels = (aubio_sink_get_channels_t)(aubio_sink_wavwrite_get_channels); s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close); s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite); return s; } #endif /* HAVE_WAVWRITE */ #if !defined(HAVE_WAVWRITE) && \ !defined(HAVE_SNDFILE) && \ !defined(HAVE_SINK_APPLE_AUDIO) AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate); #endif AUBIO_FREE(s); return NULL; }
aubio_pitchfcomb_t * new_aubio_pitchfcomb (uint_t bufsize, uint_t hopsize) { aubio_pitchfcomb_t *p = AUBIO_NEW (aubio_pitchfcomb_t); p->fftSize = bufsize; p->stepSize = hopsize; p->winput = new_fvec (bufsize); p->fftOut = new_cvec (bufsize); p->fftLastPhase = new_fvec (bufsize); p->fft = new_aubio_fft (bufsize); p->win = new_aubio_window ("hanning", bufsize); return p; }
aubio_beattracking_t * new_aubio_beattracking (uint_t winlen, uint_t hop_size, uint_t samplerate) { aubio_beattracking_t *p = AUBIO_NEW (aubio_beattracking_t); uint_t i = 0; /* default value for rayleigh weighting - sets preferred tempo to 120bpm */ smpl_t rayparam = 60. * samplerate / 120. / hop_size; smpl_t dfwvnorm = EXP ((LOG (2.0) / rayparam) * (winlen + 2)); /* length over which beat period is found [128] */ uint_t laglen = winlen / 4; /* step increment - both in detection function samples -i.e. 11.6ms or * 1 onset frame [128] */ uint_t step = winlen / 4; /* 1.5 seconds */ p->hop_size = hop_size; p->samplerate = samplerate; p->lastbeat = 0; p->counter = 0; p->flagstep = 0; p->g_var = 3.901; // constthresh empirically derived! p->rp = 1; p->gp = 0; p->rayparam = rayparam; p->step = step; p->rwv = new_fvec (laglen); p->gwv = new_fvec (laglen); p->dfwv = new_fvec (winlen); p->dfrev = new_fvec (winlen); p->acf = new_fvec (winlen); p->acfout = new_fvec (laglen); p->phwv = new_fvec (2 * laglen); p->phout = new_fvec (winlen); p->timesig = 0; /* exponential weighting, dfwv = 0.5 when i = 43 */ for (i = 0; i < winlen; i++) { p->dfwv->data[i] = (EXP ((LOG (2.0) / rayparam) * (i + 1))) / dfwvnorm; } for (i = 0; i < (laglen); i++) { p->rwv->data[i] = ((smpl_t) (i + 1.) / SQR ((smpl_t) rayparam)) * EXP ((-SQR ((smpl_t) (i + 1.)) / (2. * SQR ((smpl_t) rayparam)))); } return p; }
aubio_audio_unit_t * new_aubio_audio_unit(uint_t samplerate, uint_t sw_input_channels, uint_t sw_output_channels, uint_t blocksize) { aubio_audio_unit_t * o = AUBIO_NEW(aubio_audio_unit_t); o->hw_output_channels = 2; o->hw_input_channels = 2; o->sw_output_channels = sw_output_channels; o->sw_input_channels = sw_input_channels; o->samplerate = samplerate; o->latency = PREFERRED_LATENCY; o->blocksize = blocksize; o->au_ios_start = 0; o->au_ios_end = 0; o->verbose = 0; o->input_enabled = true; o->prevent_feedback = 1; o->dio_error = 0; o->total_frames = 0; /* the integers coming from and to the audio unit */ o->au_ios_outbuf = AUBIO_ARRAY(SInt16, AU_IOS_MAX_FRAMES * o->hw_output_channels); o->au_ios_inbuf = AUBIO_ARRAY(SInt16, AU_IOS_MAX_FRAMES * o->hw_input_channels); /* the floats coming from and to the device callback */ o->output_frames = new_fmat(sw_output_channels, blocksize); o->input_frames = new_fmat(sw_input_channels, blocksize); /* check for some sizes */ if ( o->hw_output_channels != o->output_frames->height ) { AUBIO_ERR ("got hw_output_channels = %d, but output_frames has %d rows\n", o->hw_output_channels, o->output_frames->height); } if ( o->blocksize != o->output_frames->length ) { AUBIO_ERR ("got blocksize = %d, but output_frames has length %d\n", o->blocksize, o->output_frames->length); } if ( o->hw_input_channels != o->input_frames->height ) { AUBIO_ERR ("got hw_input_channels = %d, but input_frames has %d rows\n", o->hw_input_channels, o->input_frames->height); } if ( o->blocksize != o->input_frames->length ) { AUBIO_ERR ("got blocksize = %d, but input_frames has length %d\n", o->blocksize, o->input_frames->length); } return o; }
fmat_t * new_fmat (uint_t length, uint_t height) { fmat_t * s = AUBIO_NEW(fmat_t); uint_t i,j; s->height = height; s->length = length; s->data = AUBIO_ARRAY(smpl_t*,s->height); for (i=0; i< s->height; i++) { s->data[i] = AUBIO_ARRAY(smpl_t, s->length); for (j=0; j< s->length; j++) { s->data[i][j]=0.; } } return s; }
aubio_pitchspecacf_t * new_aubio_pitchspecacf (uint_t bufsize) { aubio_pitchspecacf_t *p = AUBIO_NEW (aubio_pitchspecacf_t); p->win = new_aubio_window ("hanningz", bufsize); p->winput = new_fvec (bufsize); p->fft = new_aubio_fft (bufsize); p->fftout = new_fvec (bufsize); p->sqrmag = new_fvec (bufsize); p->acf = new_fvec (bufsize / 2 + 1); p->tol = 1.; p->confidence = 0.; return p; }
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; }
/** new_aubio_track */ aubio_track_t* new_aubio_track(int num) { aubio_track_t* track; track = AUBIO_NEW(aubio_track_t); if (track == NULL) { return NULL; } track->name = NULL; track->num = num; track->first = NULL; track->cur = NULL; track->last = NULL; track->ticks = 0; return track; }
aubio_filter_t * new_aubio_filter (uint_t order) { aubio_filter_t *f = AUBIO_NEW (aubio_filter_t); f->x = new_lvec (order); f->y = new_lvec (order); f->a = new_lvec (order); f->b = new_lvec (order); /* by default, samplerate is not set */ f->samplerate = 0; f->order = order; /* set default to identity */ f->a->data[1] = 1.; return f; }
aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) { aubio_source_t * s = AUBIO_NEW(aubio_source_t); #ifdef __APPLE__ s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); if (s->source) return s; #else /* __APPLE__ */ #if HAVE_SNDFILE s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); if (s->source) return s; #endif /* HAVE_SNDFILE */ #endif /* __APPLE__ */ AUBIO_ERROR("failed creating aubio source with %s\n", uri); AUBIO_FREE(s); return NULL; }
aubio_tss_t * new_aubio_tss(uint_t buf_size, uint_t hop_size) { aubio_tss_t * o = AUBIO_NEW(aubio_tss_t); uint_t rsize = buf_size/2+1; o->threshold = 0.25; o->thrsfact = TWO_PI*hop_size/rsize; o->alpha = 3.; o->beta = 4.; o->parm = o->threshold*o->thrsfact; o->theta1 = new_fvec(rsize); o->theta2 = new_fvec(rsize); o->oft1 = new_fvec(rsize); o->oft2 = new_fvec(rsize); o->dev = new_fvec(rsize); return o; }
/* * new_aubio_midi_event */ aubio_midi_event_t* new_aubio_midi_event() { aubio_midi_event_t* evt; evt = AUBIO_NEW(aubio_midi_event_t); if (evt == NULL) { AUBIO_ERR( "Out of memory"); return NULL; } evt->dtime = 0; evt->type = 0; evt->channel = 0; evt->param1 = 0; evt->param2 = 0; evt->next = NULL; return evt; }
aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) { aubio_source_t * s = AUBIO_NEW(aubio_source_t); AUBIO_MSG("new aubio source"); #if HAVE_LIBAV AUBIO_MSG("libav"); s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate); s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek); s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec); return s; } #endif /* HAVE_LIBAV */ #ifdef __APPLE__ AUBIO_MSG("apple"); s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate); s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek); s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio); return s; } #endif /* __APPLE__ */ #if HAVE_SNDFILE AUBIO_MSG("sndfile"); s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate); s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek); s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile); return s; } #endif /* HAVE_SNDFILE */ AUBIO_ERROR("failed creating aubio source with %s\n", uri); AUBIO_FREE(s); return NULL; }
fmat_t * new_fmat (uint_t height, uint_t length) { if ((sint_t)length <= 0 || (sint_t)height <= 0 ) { return NULL; } fmat_t * s = AUBIO_NEW(fmat_t); uint_t i,j; s->height = height; s->length = length; s->data = AUBIO_ARRAY(smpl_t*,s->height); for (i=0; i< s->height; i++) { s->data[i] = AUBIO_ARRAY(smpl_t, s->length); for (j=0; j< s->length; j++) { s->data[i][j]=0.; } } return s; }
/* 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; }