Exemplo n.º 1
0
static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
  unsigned int j;       /*frames*/
  for (j=0;j<(unsigned)nframes;j++) {
    if(usejack) {
      /* write input to datanew */
      fvec_write_sample(ibuf, input[0][j], pos);
      /* put synthnew in output */
      output[0][j] = fvec_read_sample(obuf, pos);
    }
    /*time for fft*/
    if (pos == overlap_size-1) {         
      /* block loop */
      aubio_pitch_do (o, ibuf, pitch);
      if (fvec_read_sample(pitch, 0)) {
        for (pos = 0; pos < overlap_size; pos++){
          // TODO, play sine at this freq
        }
      } else {
        fvec_zeros (obuf);
      }
      /* end of block loop */
      pos = -1; /* so it will be zero next j loop */
    }
    pos++;
  }
  return 1;
}
Exemplo n.º 2
0
void process_block(fvec_t * ibuf, fvec_t *obuf) {
  aubio_tempo_do (tempo, ibuf, tempo_out);
  is_beat = fvec_get_sample (tempo_out, 0);
  //smpl_t bpm = aubio_tempo_get_bpm(tempo); 
  //uint_t last_beat = aubio_tempo_get_last(tempo);

  aubio_pitch_do (pitch, ibuf, pitch_out);
  smpl_t freq = fvec_get_sample(pitch_out, 0);

  if (silence_threshold != -90.)
    is_silence = aubio_silence_detection(ibuf, silence_threshold);
  fvec_zeros (obuf);
  if ( is_beat && !is_silence ) {
    samples_per_beat = total_frames - my_last_beat;
    my_last_beat = total_frames;

    aubio_wavetable_play ( wavetable );
  } else {
    aubio_wavetable_stop ( wavetable );
  }

  if (mix_input)
    aubio_wavetable_do (wavetable, ibuf, obuf);
  else
    aubio_wavetable_do (wavetable, obuf, obuf);

  rgb_music_iterate(my_last_beat, samples_per_beat, total_frames, freq);

  total_frames += hop_size;
}
Exemplo n.º 3
0
void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * notes)
{
  smpl_t new_pitch, curlevel;
  fvec_zeros(notes);
  aubio_onset_do(o->onset, input, o->onset_output);

  aubio_pitch_do (o->pitch, input, o->pitch_output);
  new_pitch = o->pitch_output->data[0];
  if(o->median){
    note_append(o->note_buffer, new_pitch);
  }

  /* curlevel is negatif or 1 if silence */
  curlevel = aubio_level_detection(input, o->silence_threshold);
  if (o->onset_output->data[0] != 0) {
    /* test for silence */
    if (curlevel == 1.) {
      if (o->median) o->isready = 0;
      /* send note off */
      //send_noteon(o->curnote,0);
      //notes->data[0] = o->curnote;
      //notes->data[1] = 0.;
      notes->data[2] = o->curnote;
    } else {
      if (o->median) {
        o->isready = 1;
      } else {
        /* kill old note */
        //send_noteon(o->curnote,0, o->samplerate);
        notes->data[2] = o->curnote;
        /* get and send new one */
        //send_noteon(new_pitch,127+(int)floor(curlevel), o->samplerate);
        notes->data[0] = new_pitch;
        notes->data[1] = 127 + (int)floor(curlevel);
        o->curnote = new_pitch;
      }
    }
  } else {
    if (o->median) {
      if (o->isready > 0)
        o->isready++;
      if (o->isready == o->median)
      {
        /* kill old note */
        //send_noteon(curnote,0);
        notes->data[2] = o->curnote;
        o->newnote = aubio_notes_get_latest_note(o);
        o->curnote = o->newnote;
        /* get and send new one */
        if (o->curnote>45){
          //send_noteon(curnote,127+(int)floor(curlevel));
          notes->data[0] = o->curnote;
          notes->data[1] = 127 + (int) floor(curlevel);
        }
      }
    } // if median
  }
}
Exemplo n.º 4
0
void Note2midi::process_block (){


    smpl_t new_pitch, curlevel;
    // fvec_zeros(obuf);
    aubio_onset_do(o, ibuf, onset);

    aubio_pitch_do (pitch, ibuf, pitch_obuf);
    new_pitch = fvec_get_sample(pitch_obuf, 0);
    if(median){
        note_append(note_buffer, new_pitch);
    }

  /* curlevel is negatif or 1 if silence */
    curlevel = aubio_level_detection(ibuf, *_silence_threshold);
    if (fvec_get_sample(onset, 0)) {
    /* test for silence */
        if (curlevel == 1.) {
            if (median) isready = 0;
      /* send note off */
            send_noteon(curnote, 0);
        } else {
            if (median) {
                isready = 1;
            } else {
        /* kill old note */
                send_noteon(curnote, 0);
        /* get and send new one */
                send_noteon(new_pitch, 127+(int)floor(curlevel));
                curnote = new_pitch;
            }
        }
    } 
    else {
        if (median) {
            if (isready > 0)
                isready++;
            if (isready == median){
        /* kill old note */
                send_noteon(curnote, 0);
                newnote = get_note(note_buffer, note_buffer2);
                curnote = newnote;
        /* get and send new one */
                if (curnote>45){
                    send_noteon(curnote, 127+(int)floor(curlevel));
                }
            }
        } // if median
    }

    // lv2_atom_sequence_append_event(this->out, out_capacity, &note.event);
}
Exemplo n.º 5
0
void
process_block(fvec_t * ibuf, fvec_t * obuf) {
  fvec_zeros(obuf);
  aubio_pitch_do (o, ibuf, pitch);
  smpl_t freq = fvec_read_sample(pitch, 0);
  aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
  aubio_wavetable_set_freq ( wavetable, freq );

  if (mix_input)
    aubio_wavetable_do (wavetable, ibuf, obuf);
  else
    aubio_wavetable_do (wavetable, obuf, obuf);
}
Exemplo n.º 6
0
static GstFlowReturn
gst_aubio_pitch_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
  uint j;
  GstAubioPitch *filter = GST_AUBIO_PITCH (trans);
  GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans);

  gint nsamples = GST_BUFFER_SIZE (buf) / (4 * audiofilter->format.channels);

  /* block loop */
  for (j = 0; j < nsamples; j++) {
    /* copy input to ibuf */
    fvec_write_sample(filter->ibuf, ((smpl_t *) GST_BUFFER_DATA(buf))[j],
        filter->pos);

    if (filter->pos == filter->hop_size - 1) {
      aubio_pitch_do(filter->t, filter->ibuf, filter->obuf);
      smpl_t pitch = filter->obuf->data[0];
      GstClockTime now = GST_BUFFER_TIMESTAMP (buf);
      // correction of inside buffer time
      now += GST_FRAMES_TO_CLOCK_TIME(j, audiofilter->format.rate);

      if (filter->silent == FALSE) {
        g_print ("%" GST_TIME_FORMAT "\tpitch: %.3f\n",
                GST_TIME_ARGS(now), pitch);
      }

      GST_LOG_OBJECT (filter, "pitch %" GST_TIME_FORMAT ", freq %3.2f",
              GST_TIME_ARGS(now), pitch);

      filter->pos = -1; /* so it will be zero next j loop */
    }
    filter->pos++;
  }

  return GST_FLOW_OK;
}
Exemplo n.º 7
0
int
main ()
{
  /* allocate some memory */
  uint_t win_s = 1024;          /* window size */
  uint_t hop_s = win_s / 4;     /* hop size */
  uint_t samplerate = 44100;    /* samplerate */
  fvec_t *in = new_fvec (hop_s);      /* input buffer */
  fvec_t *out = new_fvec (1); /* input buffer */
  aubio_pitch_t *o =
      new_aubio_pitch ("default", win_s, hop_s, samplerate);
  uint_t i = 0;

  while (i < 100) {
    aubio_pitch_do (o, in, out);
    i++;
  };

  del_aubio_pitch (o);
  del_fvec (in);
  aubio_cleanup ();

  return 0;
}
void pitchDetector::process_pitch(fvec_t * in) {
    
    aubio_pitch_do (o, in, pitch);
    pitchFound = fvec_get_sample(pitch, 0);
    
}