static t_int *aubiotempo_tilde_perform(t_int *w) 
{
  t_aubiotempo_tilde *x = (t_aubiotempo_tilde *)(w[1]);
  t_sample *in          = (t_sample *)(w[2]);
  int n                 = (int)(w[3]);
  int j;
  for (j=0;j<n;j++) {
    /* write input to datanew */
    fvec_write_sample(x->vec, in[j], 0, x->pos);
    /*time for fft*/
    if (x->pos == x->hopsize-1) {         
      /* block loop */
      aubio_tempo (x->t, x->vec, x->output);
      if (x->output->data[0][0]) {
        outlet_bang(x->tempobang);
      }
      if (x->output->data[0][1]) {
        outlet_bang(x->onsetbang);
      }
      /* end of block loop */
      x->pos = -1; /* so it will be zero next j loop */
    }
    x->pos++;
  }
  return (w+4);
}
int aubio_process(float **input, float **output, int nframes) {
  unsigned int i;       /*channels*/
  unsigned int j;       /*frames*/
  for (j=0;j<(unsigned)nframes;j++) {
    if(usejack) {
      for (i=0;i<channels;i++) {
        /* write input to datanew */
        fvec_write_sample(ibuf, input[i][j], i, pos);
        /* put synthnew in output */
        output[i][j] = fvec_read_sample(obuf, i, pos);
      }
    }
    /*time for fft*/
    if (pos == overlap_size-1) {         
      /* block loop */
      aubio_tempo(bt,ibuf,out);
      if (out->data[0][0]==1) 
        istactus = 1;
      else 
        istactus = 0;
      if (istactus) {
              for (pos = 0; pos < overlap_size; pos++)
                      obuf->data[0][pos] = woodblock->data[0][pos];
      } else {
              for (pos = 0; pos < overlap_size; pos++)
                      obuf->data[0][pos] = 0.;
      }
      /* end of block loop */
      pos = -1; /* so it will be zero next j loop */
    }
    pos++;
  }
  return 1;
}
// this is the 32-bit perform method for Max 5 and earlier
t_int *aubioOnset_perform(t_int *w)
{
    int j, n;
    // DO NOT CALL post IN HERE, but you can call defer_low (not defer)

    // args are in a vector, sized as specified in aubioOnset_dsp method
    // w[0] contains &aubioOnset_perform, so we start at w[1]
    t_aubioOnset *x = (t_aubioOnset *)(w[1]);
    //t_float *inL = (t_float *)(w[2]);
    //t_float *outL = (t_float *)(w[3]);
    t_sample *in = (t_float *)(w[2]);
    n = (int)w[3];

    for (j = 0; j < n; j++) {
        /* write input to datanew */
        fvec_write_sample (x->in, in[j], 0, x->pos);
        /*time to do something */
        if (x->pos == x->hopsize - 1) {
            /* block loop */
            aubio_onset (x->o, x->in, x->out);
            if (fvec_read_sample (x->out, 0, 0) > 0.) {
                outlet_bang (x->onsetbang);
            }
            /* end of block loop */
            x->pos = -1;              /* so it will be zero next j loop */
        }
        x->pos++;
    }

    // you have to return the NEXT pointer in the array OR MAX WILL CRASH
    return w + 4;
}
bool AubioPitch::processFrame(float* frame, int size){//
	//note this no longer called
	int j;
	bool pitchDetected = false;
	//smpl_t pitch;
	
	for (j=0;j<size;j++) {
		
		fvec_write_sample(vec, frame[j], 0, pos);

		if (pos == hopsize-1) {  //anr recent change from hopsize       
			// block loop /
			
			pitch = aubio_pitchdetection(pitchDetect, vec);
			pitchDetected = true;
			printf("PITCH IS %f\n", pitch);
		
			//			printf("Pitch detected %f\n", pitch);
//			outlet_float(x->pitchOutlet, pitch);
			
			// end of block loop 
			pos = -1; // so it will be zero next j loop //
		}
		pos++;
		
	}
	return pitchDetected;
	
}
Beispiel #5
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;
}
// this is 64-bit perform method for Max 6
void aubioOnset_perform64(t_aubioOnset *x, t_object *dsp64, double **ins, long numins, double **outs, long numouts, long sampleframes, long flags, void *userparam)
{
    int j, n;
    //t_double *inL = ins[0];		// we get audio for each inlet of the object from the **ins argument
    t_sample *in = ins[0];
    //t_double *outL = outs[0];	// we get audio for each outlet of the object from the **outs argument
    n = sampleframes;

    for (j = 0; j < n; j++) {
        /* write input to datanew */
        fvec_write_sample (x->in, in[j], 0, x->pos);
        /*time to do something */
        if (x->pos == x->hopsize - 1) {
            /* block loop */
            aubio_onset (x->o, x->in, x->out);
            if (fvec_read_sample (x->out, 0, 0) > 0.) {
                outlet_bang (x->onsetbang);
            }
            /* end of block loop */
            x->pos = -1;              /* so it will be zero next j loop */
        }
        x->pos++;
    }


    // this perform method simply copies the input to the output, offsetting the value
    //while (n--)
    //	*outL++ = *inL++ + x->offset;
}
Beispiel #7
0
static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
  unsigned int i;       /*channels*/
  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_onset_do (o, ibuf, onset);
      if ( fvec_read_sample(onset, 0) ) {
        fvec_copy (woodblock, obuf);
      } else {
        fvec_zeros (obuf);
      }
      /* end of block loop */
      pos = -1; /* so it will be zero next j loop */
    }
    pos++;
  }
  return 1;
}
Beispiel #8
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 */
      
      //compute mag spectrum
      aubio_pvoc_do (pv, ibuf, fftgrain);
     
      //compute mfccs
      aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
      
      /* end of block loop */
      pos = -1; /* so it will be zero next j loop */
    }
    pos++;
  }
  return 1;
}
bool AubioOnsetDetector :: processframe(float* frame, const int& n){
	bool newFrameResult = false;
	//Paul Brossier's aubioonsetclass~ code ported from Pd
	int j,isonset;
	for (j=0;j<n;j++) {
		
		// write input to datanew 
		fvec_write_sample(vec, frame[j], 0, pos);//vec->data[0][pos] = frame[j]
		//time for fft
		
		if (pos == hopsize-1) {  //hopsize is 512       
			newFrameResult = true;
			aubioOnsetFound = false;
			
			// block loop 
			aubio_pvoc_do (pv,vec, fftgrain);
			
			fftgrain->norm[0][0] = fabs(fftgrain->norm[0][0]);
			//added hack to solve bug that norm[0][0] is negative sometimes.
			
			aubio_onsetdetection(o, fftgrain, onset);
			rawDetectionValue = onset->data[0][0];
			//Paul Brossier's method to return value of peak picking process
			
			
			postProcessing();
			
			//	smpl_t my_sample_value;
			//peakPickedDetectionValue = aubio_peakpick_pimrt_getval(parms); 
			//peakPickedDetectionValue = my_sample_value;
			
			//Paul Brossier's onset detection method
			isonset = aubio_peakpick_pimrt(onset,parms);
			if (isonset) {
				// test for silence 
				if (aubio_silence_detection(vec, threshold2)==1){
					isonset=0;
				}
				else{
					//				outlet_bang(x->bangoutlet);
					aubioOnsetFound = true;
				}
			}//end if (isonset)
			
			
			
			// end of block loop 
			pos = -1; // so it will be zero next j loop 
		}
		pos++;
		
	}//end for j 
	//end of Paul's code
	
	return newFrameResult;
	
}
void AubioOnsetDetector :: initialise(){
	//reinitialises our object
		o = new_aubio_onsetdetection(aubio_onset_complex, buffersize, 1);//initially in complex mode
		pv = (aubio_pvoc_t *)new_aubio_pvoc(buffersize, hopsize, 1);
		parms = new_aubio_peakpicker(threshold);
		vec = (fvec_t *)new_fvec(hopsize,1);
		pos = 0;
				fvec_write_sample(vec, 0.234, 0, pos);
				fftgrain  = (cvec_t *)new_cvec(buffersize,1);
				onset = (fvec_t *)new_fvec(1,1);
		}
Beispiel #11
0
static GstFlowReturn
gst_aubio_tempo_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
  uint j;
  GstAubioTempo *filter = GST_AUBIOTEMPO(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_tempo_do(filter->t, filter->ibuf, filter->out);

      if (filter->out->data[0]> 0.) {
        gdouble now = GST_BUFFER_OFFSET (buf);
        // correction of inside buffer time
        now += (smpl_t)(j - filter->hop_size + 1);
        // correction of float period
        now += (filter->out->data[0] - 1.)*(smpl_t)filter->hop_size;

        if (filter->last_beat != -1 && now > filter->last_beat) {
          filter->bpm = 60./(GST_FRAMES_TO_CLOCK_TIME(now - filter->last_beat, audiofilter->format.rate))*1.e+9;
        } else {
          filter->bpm = 0.;
        }

        if (filter->silent == FALSE) {
          g_print ("beat: %f ", GST_FRAMES_TO_CLOCK_TIME( now, audiofilter->format.rate)*1.e-9);
          g_print ("| bpm: %f\n", filter->bpm);
        }

        GST_LOG_OBJECT (filter, "beat %" GST_TIME_FORMAT ", bpm %3.2f",
            GST_TIME_ARGS(now), filter->bpm);

        if (filter->message) {
          GstMessage *m = gst_aubio_tempo_message_new (filter, now);
          gst_element_post_message (GST_ELEMENT (filter), m);
        }

        filter->last_beat = now;
      }

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

  return GST_FLOW_OK;
}
//anr idea of adding to buffer
void AubioPitch::addToBuffer(float* tmpFrame, const int& n){
	for (int j=0;j < n;j++) {
		fvec_write_sample(vec, tmpFrame[j], 0, pos);
		
		if (pos == hopsize - 1){
			//pitch = aubio_pitchdetection(x->o,x->vec);
			//outlet_float(x->pitchOutlet, pitch);
			
			pitch = aubio_pitchdetection(pitchDetect, vec);
			pos = -1;
		}
		
		pos++;
	}
}
float AubioPitch::doPitchDetection(float* frame, const int& length){
	//fn to do pitch detection without all the buffering etc
	float newPitch = -1.0;
	if (length == bufsize){
		fvec_t* tmpVec;
		tmpVec = new_fvec(bufsize,1);
		for (int j =0;j < length;j++){
			fvec_write_sample(tmpVec, frame[j], 0, j);
		//	printf("vec[%i] = %.3f\n", j, frame[j]);
		}
		newPitch = aubio_pitchdetection(pitchDetect, tmpVec);
	//	printf("NEW PITCH FOUND %f\n", newPitch);
	}
	return newPitch;
}
Beispiel #14
0
int *aubio_process(t_sample *sample, float *input, sf_count_t nframes) {
    unsigned int j, i;

    int *result;

    for (j=0; j < nframes; j++) {
        for (i=0; i < channels; i++) {
            /* write input to datanew */
            fvec_write_sample(ibuf, input[channels*j+i], i, pos % overlap_size);
        }

        /*time for fft*/
        if (pos % overlap_size == (overlap_size - 1)) {
            int isonset;
            /* block loop */
            aubio_pvoc_do(pv, ibuf, fftgrain);
            aubio_onsetdetection(o, fftgrain, onset);
            if (usedoubled) {
                aubio_onsetdetection(o2,fftgrain, onset2);
                onset->data[0][0] *= onset2->data[0][0];
            }
            isonset = aubio_peakpick_pimrt(onset, parms);
            if (isonset) {
                /* test for silence */
                if (aubio_silence_detection(ibuf, silence)==1) {
                    printf("silence.\n");
                    isonset=0;
                }
                else {
                    printf("onset! %d\n", pos);
                    onsets[onset_n++] = pos;
                }
            }
        }
        pos++;
    }

    result = (int *) calloc(1, sizeof(int) * (onset_n + 1));
    memcpy(result, onsets, sizeof(int) * onset_n);
    result[onset_n] = -1;
    printf("found %d onsets\n", onset_n);

    return(result);
}
Beispiel #15
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;
}
static t_int *
aubioOnset_tilde_perform (t_int * w)
{
    t_aubioOnset_tilde *x = (t_aubioOnset_tilde *) (w[1]);
    t_sample *in = (t_sample *) (w[2]);
    int n = (int) (w[3]);
    int j;
    for (j = 0; j < n; j++) {
        /* write input to datanew */
        fvec_write_sample (x->in, in[j], 0, x->pos);
        /*time to do something */
        if (x->pos == x->hopsize - 1) {
            /* block loop */
            aubio_onset (x->o, x->in, x->out);
            if (fvec_read_sample (x->out, 0, 0) > 0.) {
                outlet_bang (x->onsetbang);
            }
            /* end of block loop */
            x->pos = -1;              /* so it will be zero next j loop */
        }
        x->pos++;
    }
    return (w + 4);
}
Beispiel #17
0
AubioBeatDetector::AubioBeatDetector(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

    on<Trigger<messages::input::SoundChunkSettings>>([this](const messages::input::SoundChunkSettings& settings) {

        // Store the settings of the sound chunks
        m->sampleRate = settings.sampleRate;
        m->channels = settings.channels;
        m->chunkSize = settings.chunkSize;

        // Build our audio tempo tracker  can set to (aubio_onset_kl or aubio_onset_complex onset tracking)
        m->tempoTracker = new_aubio_tempo(aubio_onset_kl, WINDOW_SIZE, HOP_SIZE, m->channels);
        m->outputData = new_fvec(HOP_SIZE, m->channels);
        m->inputData = new_fvec(HOP_SIZE, m->channels);


    });

    on<Trigger<messages::input::SoundChunk>>([this](const messages::input::SoundChunk& chunk) {

        for (size_t i = 0; i < m->chunkSize; ++i) {

            // Write to our vector
            size_t index = (i + m->offset) % HOP_SIZE;
            fvec_write_sample(m->inputData, chunk.data[i * m->channels], 0, index);

            // If we are done filling this hop chunk
            if(index == HOP_SIZE - 1) {

                aubio_tempo(m->tempoTracker, m->inputData, m->outputData);
                for (int i = 1; i <= m->outputData->data[0][0]; ++i) {

                    auto beatTime = std::make_unique<BeatTime>();

                    // Work out how many samples from the end we are in total
                    const size_t position = ((i - HOP_SIZE) + (m->outputData->data[0][i]));

                    // Start at our end time and go back
                    beatTime->time = chunk.endTime - NUClear::clock::duration(int(NUClear::clock::period::den * (double(position) / m->sampleRate)));

                    emit(std::move(beatTime));
                }
            }
        }

        m->offset = (m->chunkSize + m->offset) % HOP_SIZE;
    });

    on<Trigger<Last<2, BeatTime>>>([this](const std::vector<std::shared_ptr<const BeatTime>>& lastTwoBeats) {

        if(lastTwoBeats.size() == 2) {
            auto beat = std::make_unique<messages::audio::Beat>();
            beat->time = lastTwoBeats[0]->time; //apparently the latest one is 0
            beat->period = lastTwoBeats[0]->time - lastTwoBeats[1]->time;

            emit(std::move(beat));
        }
    });

    on<Trigger<Shutdown>>([this](const Shutdown&) {
        del_aubio_tempo(m->tempoTracker);
        del_fvec(m->inputData);
        del_fvec(m->outputData);
    });
}
Beispiel #18
0
bool AubioOnsetDetector :: processframe(float frame[], int n){
	bool newFrameResult = false;
	//Paul Brossier's aubioonsetclass~ code ported from Pd
		int j,isonset;
	for (j=0;j<n;j++) {
		// write input to datanew 
		fvec_write_sample(vec, frame[j], 0, pos);//vec->data[0][pos] = frame[j]
		//time for fft
	
			if (pos == hopsize-1) {  //hopsize is 512       
			newFrameResult = true;
			aubioOnsetFound = false;
			// block loop 
			aubio_pvoc_do (pv,vec, fftgrain);
			
			fftgrain->norm[0][0] = fabs(fftgrain->norm[0][0]);
			//added hack to solve bug that norm[0][0] is negative sometimes.
			
			aubio_onsetdetection(o, fftgrain, onset);
			rawDetectionValue = onset->data[0][0];
		//Paul Brossier's method to return value of peak picking process
				
			anrMedianProcessedOnsetFound = checkForMedianOnset(rawDetectionValue);
				
			bestSlopeValue = getBestSlopeValue(rawDetectionValue); 
			anrBestSlopeOnset =	checkForSlopeOnset(bestSlopeValue);
				
	//	smpl_t my_sample_value;
		peakPickedDetectionValue = aubio_peakpick_pimrt_getval(parms); 
	//peakPickedDetectionValue = my_sample_value;

	//this was what got sent from max object::			
	//	outlet_float(x->detectionFunctionOutlet, my_sample_value);
	//	outlet_float(x->rawDetectionFunctionOutlet, x->onset->data[0][0]);
		
			isonset = aubio_peakpick_pimrt(onset,parms);
			if (isonset) {
				// test for silence 
				if (aubio_silence_detection(vec, -ofGetMouseX())==1)
					{
                        printf("silence \n");
					isonset=0;
					}
				else{
	//				outlet_bang(x->bangoutlet);
					aubioOnsetFound = true;
								
							}
			}//end if (isonset)
		
			
		
			// end of block loop 
			pos = -1; // so it will be zero next j loop 
		}
		pos++;
//	outL[j] = frame[j];//have added this so signal is "see through": outputting the input signal
	
	}
//end of Paul's code

return newFrameResult;
		
}