Changeset a0fd4e4


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

Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • examples/Makefile.am

    re50b695 ra0fd4e4  
    99bin_PROGRAMS = \
    1010        aubioonset \
    11         aubionotesmedian \
    1211        aubionotes
    1312       
     
    1716aubioonset_SOURCES = aubioonset.c utils.c
    1817aubionotes_SOURCES = aubionotes.c utils.c
    19 aubionotesmedian_SOURCES = aubionotesmedian.c utils.c
  • 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");
  • examples/utils.h

    re50b695 ra0fd4e4  
    2525extern int usejack;
    2626extern int usedoubled;
     27extern int median;
    2728extern const char * output_filename;
    2829extern const char * input_filename;
  • python/aubio/gnuplot.py

    re50b695 ra0fd4e4  
    109109                        data.append(myvec.get(curpos,i))
    110110                        curpos+=1
    111         # FIXME again for the last frame
    112         curpos = 0
    113         while (curpos < readsize):
    114                 data.append(myvec.get(curpos,i))
    115                 curpos+=1
    116111        time = arange(len(data))*framestep
    117112        return time,data
    118113
    119 def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None, task=audio_to_array):
     114def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None):
    120115        g = Gnuplot.Gnuplot(debug=1, persist=1)
    121116        d = []
     
    125120        g.gnuplot('set multiplot;')
    126121        while (len(filenames)):
    127                 b,a = task(filenames.pop(0))
    128                 d.append(Gnuplot.Data(b,a))
     122                d.append(plot_audio_make(filenames.pop(0)))
    129123                if not noaxis and todraw==1:
    130124                        g.xlabel('Time (s)')
     
    141135                g.hardcopy(fileout, enhanced=1, color=0)
    142136
     137def make_audio_plot(time,data,maxpoints=10000):
     138        """ create gnuplot plot from an audio file """
     139        import numarray
     140        length = len(time)
     141        downsample = length/maxpoints
     142        if downsample == 0: downsample = 1
     143        x = numarray.array(time).resize(length)[0:-1:downsample]
     144        y = numarray.array(data).resize(length)[0:-1:downsample]
     145        return Gnuplot.Data(x,y,with='lines')
  • src/mathutils.c

    re50b695 ra0fd4e4  
    401401      return loudness;
    402402}
     403
     404void aubio_autocorr(fvec_t * input, fvec_t * output){
     405        uint_t i = 0, j = 0, length = input->length;
     406        smpl_t * data = input->data[0];
     407        smpl_t * acf = output->data[0];
     408        smpl_t tmp =0.;
     409        for(i=0;i<length;i++){
     410                for(j=i;j<length;j++){
     411                        tmp += data[j-i]*data[j];
     412                }
     413                acf[i] = tmp/(length-i);
     414                tmp = 0.0;
     415        }
     416}
     417
  • src/mathutils.h

    re50b695 ra0fd4e4  
    236236uint_t aubio_silence_detection(fvec_t * ibuf, smpl_t threshold);
    237237smpl_t aubio_level_detection(fvec_t * ibuf, smpl_t threshold);
     238/**
     239 * calculate normalised autocorrelation function
     240 */
     241void aubio_autocorr(fvec_t * input, fvec_t * output);
    238242
    239243#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.