Ignore:
Timestamp:
Apr 2, 2005, 3:29:23 PM (19 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
cf7c76a
Parents:
e50b695
Message:

merge aubionotes and aubionotesmedian

add make_audio_plot to gnuplot.py
adds autocorrelation to mathutils
adds Makefile.in to junk files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/aubionotes.c

    re50b695 ra0fd4e4  
    2222#include <getopt.h>
    2323#include <unistd.h>
    24 #include <math.h> // how do i do a floorf with a mask again ?
     24#include <math.h>
    2525#include "aubio.h"
    2626#include "aubioext.h"
     
    3535int usedoubled = 1;
    3636int usemidi = 1;
     37int median = 0;
    3738
    3839/* energy,specdiff,hfc,complexdomain,phase */
    3940aubio_onsetdetection_type type_onset  = hfc;
    40 aubio_onsetdetection_type type_onset2 = hfc;
     41aubio_onsetdetection_type type_onset2 = complexdomain;
    4142smpl_t threshold                      = 0.3;
    4243smpl_t threshold2                     = -90.;
     
    6162
    6263/* pitch objects */
    63 int curnote                = 0;
    6464smpl_t pitch               = 0.;
    6565aubio_pitchdetection_t * pitchdet;
    66 int bufpos = 0;
    67 smpl_t curlevel = 0;
     66
     67fvec_t * note_buffer = NULL;
     68fvec_t * note_buffer2 = NULL;
     69uint_t medianfiltlen = 6;
     70smpl_t curlevel = 0.;
    6871smpl_t maxonset = 0.;
    6972
     
    101104}
    102105
     106
     107/** append new note candidate to the note_buffer and return filtered value. we
     108 * need to copy the input array as vec_median destroy its input data.*/
     109
     110void note_append(fvec_t * note_buffer, smpl_t curnote);
     111void note_append(fvec_t * note_buffer, smpl_t curnote) {
     112  uint_t i = 0;
     113  for (i = 0; i < note_buffer->length - 1; i++) {
     114      note_buffer->data[0][i] = note_buffer->data[0][i+1];
     115  }
     116  note_buffer->data[0][note_buffer->length - 1] = curnote;
     117  return;
     118}
     119
     120uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2);
     121uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2){
     122  uint_t i = 0;
     123  for (i = 0; i < note_buffer->length; i++) {
     124      note_buffer2->data[0][i] = note_buffer->data[0][i];
     125  }
     126  return vec_median(note_buffer2);
     127}
     128
     129
     130smpl_t curnote = 0.;
     131smpl_t newnote = 0.;
     132uint_t isready = 0;
     133
    103134int aubio_process(float **input, float **output, int nframes);
    104135int aubio_process(float **input, float **output, int nframes) {
     
    126157     
    127158      pitch = aubio_pitchdetection(pitchdet,ibuf);
     159      if(median){
     160      newnote = (FLOOR)(bintomidi(pitch,samplerate,buffer_size*4)+.5);
     161      note_append(note_buffer, newnote);
     162      }
    128163
    129164      /* curlevel is negatif or 1 if silence */
     
    133168        if (curlevel == 1.) {
    134169          isonset=0;
     170          if (median) isready = 0;
    135171          /* send note off */
    136172          send_noteon(mdriver,curnote,0);
    137173        } else {
     174          if (median) {
     175                  isready = 1;
     176          } else {
    138177          /* kill old note */
    139178          send_noteon(mdriver,curnote,0);
     
    147186            send_noteon(mdriver,curnote,127+(int)FLOOR(curlevel));
    148187          }
     188          }
     189         
    149190          for (pos = 0; pos < overlap_size; pos++){
    150191            obuf->data[0][pos] = woodblock->data[0][pos];
     
    152193        }
    153194      } else {
     195              if (median) {
     196//        if (curlevel != 1) {
     197//          if (bufpos == note_buffer->length)
     198//            curnote = aubio_getnote(note_buffer);
     199//        }
     200//
     201        if (isready > 0)
     202            isready++;
     203        if (isready == note_buffer->length)
     204        {
     205            //outmsg("%d, %f\n", isready, curnote);
     206            send_noteon(mdriver,curnote,0);
     207        /* kill old note */
     208            newnote = get_note(note_buffer, note_buffer2);
     209            curnote = newnote;
     210        /* get and send new one */
     211        /*if (curnote<45){
     212          send_noteon(mdriver,curnote,0);
     213        } else {*/
     214            if (curnote>45){
     215                send_noteon(mdriver,curnote,127+(int)FLOOR(curlevel));
     216            }
     217        }
     218        } // if median
    154219        for (pos = 0; pos < overlap_size; pos++)
    155220          obuf->data[0][pos] = 0.;
     
    188253  fftgrain    = new_cvec(buffer_size, channels);
    189254
    190   pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mcomb, freq);
    191   //pitchdet = new_aubio_pitchdetection(buffer_size*2, overlap_size, channels, samplerate, yin, freq);
     255  aubio_pitchdetection_type mode = yin; // mcomb
     256  pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mode, freq);
    192257 
     258if (median) {
     259  note_buffer = new_fvec(medianfiltlen, 1);
     260  note_buffer2= new_fvec(medianfiltlen, 1);
     261}
    193262  /* read the output sound once */
    194263  file_read(onsetfile, overlap_size, woodblock);
     
    262331  del_aubio_pitchdetection(pitchdet);
    263332  del_fvec(onset);
     333  if (median) {
     334  del_fvec(note_buffer);
     335  del_fvec(note_buffer2);
     336  }
    264337
    265338  debug("End of program.\n");
Note: See TracChangeset for help on using the changeset viewer.