Exemple #1
0
int main(int argc, char **argv) {

  buffer_size = 2048;

  examples_common_init(argc,argv);

  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
  verbmsg ("pitch method: %s, ", pitch_method);
  verbmsg ("pitch unit: %s, ", pitch_unit);
  verbmsg ("buffer_size: %d, ", buffer_size);
  verbmsg ("hop_size: %d, ", hop_size);
  verbmsg ("tolerance: %f\n", pitch_tolerance);

  o = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate);
  if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (o, pitch_tolerance);
  if (pitch_unit != NULL) aubio_pitch_set_unit (o, pitch_unit);
  pitch = new_fvec (1);

  wavetable = new_aubio_wavetable (samplerate, hop_size);
  aubio_wavetable_play ( wavetable );

  examples_common_process((aubio_process_func_t)process_block,process_print);

  del_aubio_pitch (o);
  del_aubio_wavetable (wavetable);
  del_fvec (pitch);

  examples_common_del();
  return 0;
}
void pitchDetector::setup(char_t * unit, char_t * method) {
    
    
    samplerate = 44100;
    uint_t win_s = 2048; // window size
    uint_t hop_s = 512;  // hop size
    
    
    
    pitch_tolerance = 0;
    silence_threshold = -90.;
    pitch_unit = unit;
    pitch_method = method;
    blocks = 0;
    
    o = new_aubio_pitch (pitch_method, win_s, hop_s, samplerate);
    if (pitch_tolerance != 0.)
        aubio_pitch_set_tolerance (o, pitch_tolerance);
    if (silence_threshold != -90.)
        aubio_pitch_set_silence (o, silence_threshold);
    if (pitch_unit != NULL)
        aubio_pitch_set_unit (o, pitch_unit);
    
    pitch = new_fvec (1);


}
Exemple #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;
}
Exemple #4
0
int main(int argc, char **argv) {
  // override general settings from utils.c
  buffer_size = 1024;
  hop_size = 512;

  rgb_music_init();

  examples_common_init(argc,argv);

  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);

  verbmsg ("tempo method: %s, ", tempo_method);
  verbmsg ("buffer_size: %d, ", buffer_size);
  verbmsg ("hop_size: %d, ", hop_size);
  verbmsg ("threshold: %f\n", onset_threshold);

  tempo_out = new_fvec(2);
  tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate);
  if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold);

  pitch = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate);
  if (pitch_tolerance != 0.)
    aubio_pitch_set_tolerance (pitch, pitch_tolerance);
  if (silence_threshold != -90.)
    aubio_pitch_set_silence (pitch, silence_threshold);
  if (pitch_unit != NULL)
    aubio_pitch_set_unit (pitch, pitch_unit);

  pitch_out = new_fvec (1);



  wavetable = new_aubio_wavetable (samplerate, hop_size);
  aubio_wavetable_set_freq ( wavetable, 2450.);
  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");

  examples_common_process((aubio_process_func_t)process_block,process_print);

  del_aubio_tempo(tempo);
  del_aubio_wavetable (wavetable);
  del_fvec(tempo_out);

  del_aubio_pitch (pitch);
  del_fvec (pitch_out);

  examples_common_del();
  return 0;
}
Exemple #5
0
aubio_pitch_t *
new_aubio_pitch (const char_t * pitch_mode,
    uint_t bufsize, uint_t hopsize, uint_t samplerate)
{
  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
  aubio_pitch_type pitch_type;
  if (strcmp (pitch_mode, "mcomb") == 0)
    pitch_type = aubio_pitcht_mcomb;
  else if (strcmp (pitch_mode, "yinfft") == 0)
    pitch_type = aubio_pitcht_yinfft;
  else if (strcmp (pitch_mode, "yin") == 0)
    pitch_type = aubio_pitcht_yin;
  else if (strcmp (pitch_mode, "schmitt") == 0)
    pitch_type = aubio_pitcht_schmitt;
  else if (strcmp (pitch_mode, "fcomb") == 0)
    pitch_type = aubio_pitcht_fcomb;
  else if (strcmp (pitch_mode, "specacf") == 0)
    pitch_type = aubio_pitcht_specacf;
  else if (strcmp (pitch_mode, "default") == 0)
    pitch_type = aubio_pitcht_default;
  else {
    AUBIO_ERR ("unknown pitch detection method %s, using default.\n",
        pitch_mode);
    pitch_type = aubio_pitcht_default;
  }

  // check parameters are valid
  if ((sint_t)hopsize < 1) {
    AUBIO_ERR("pitch: got hopsize %d, but can not be < 1\n", hopsize);
    goto beach;
  } else if ((sint_t)bufsize < 1) {
    AUBIO_ERR("pitch: got buffer_size %d, but can not be < 1\n", bufsize);
    goto beach;
  } else if (bufsize < hopsize) {
    AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);
    goto beach;
  } else if ((sint_t)samplerate < 1) {
    AUBIO_ERR("pitch: samplerate (%d) can not be < 1\n", samplerate);
    goto beach;
  }

  p->samplerate = samplerate;
  p->type = pitch_type;
  aubio_pitch_set_unit (p, "default");
  p->bufsize = bufsize;
  p->silence = DEFAULT_PITCH_SILENCE;
  p->conf_cb = NULL;
  switch (p->type) {
    case aubio_pitcht_yin:
      p->buf = new_fvec (bufsize);
      p->p_object = new_aubio_pitchyin (bufsize);
      p->detect_cb = aubio_pitch_do_yin;
      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence;
      aubio_pitchyin_set_tolerance (p->p_object, 0.15);
      break;
    case aubio_pitcht_mcomb:
      p->filtered = new_fvec (hopsize);
      p->pv = new_aubio_pvoc (bufsize, hopsize);
      p->fftgrain = new_cvec (bufsize);
      p->p_object = new_aubio_pitchmcomb (bufsize, hopsize);
      p->filter = new_aubio_filter_c_weighting (samplerate);
      p->detect_cb = aubio_pitch_do_mcomb;
      break;
    case aubio_pitcht_fcomb:
      p->buf = new_fvec (bufsize);
      p->p_object = new_aubio_pitchfcomb (bufsize, hopsize);
      p->detect_cb = aubio_pitch_do_fcomb;
      break;
    case aubio_pitcht_schmitt:
      p->buf = new_fvec (bufsize);
      p->p_object = new_aubio_pitchschmitt (bufsize);
      p->detect_cb = aubio_pitch_do_schmitt;
      break;
    case aubio_pitcht_yinfft:
      p->buf = new_fvec (bufsize);
      p->p_object = new_aubio_pitchyinfft (samplerate, bufsize);
      p->detect_cb = aubio_pitch_do_yinfft;
      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence;
      aubio_pitchyinfft_set_tolerance (p->p_object, 0.85);
      break;
    case aubio_pitcht_specacf:
      p->buf = new_fvec (bufsize);
      p->p_object = new_aubio_pitchspecacf (bufsize);
      p->detect_cb = aubio_pitch_do_specacf;
      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance;
      aubio_pitchspecacf_set_tolerance (p->p_object, 0.85);
      break;
    default:
      break;
  }
  return p;

beach:
  AUBIO_FREE(p);
  return NULL;
}