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;
	
}
Пример #2
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);
}
Пример #3
0
/* execute tempo detection function on iput buffer */
void aubio_tempo(aubio_tempo_t *o, fvec_t * input, fvec_t * tempo)
{
  uint_t i;
  uint_t winlen = o->winlen;
  uint_t step   = o->step;
  aubio_pvoc_do (o->pv, input, o->fftgrain);
  aubio_onsetdetection(o->od, o->fftgrain, o->of);
  /*if (usedoubled) {
    aubio_onsetdetection(o2,fftgrain, onset2);
    onset->data[0][0] *= onset2->data[0][0];
  }*/
  /* execute every overlap_size*step */
  if (o->blockpos == (signed)step -1 ) {
    /* check dfframe */
    aubio_beattracking_do(o->bt,o->dfframe,o->out);
    /* rotate dfframe */
    for (i = 0 ; i < winlen - step; i++ ) 
      o->dfframe->data[0][i] = o->dfframe->data[0][i+step];
    for (i = winlen - step ; i < winlen; i++ ) 
      o->dfframe->data[0][i] = 0.;
    o->blockpos = -1;
  }
  o->blockpos++;
  tempo->data[0][1] = aubio_peakpick_pimrt_wt(o->of,o->pp,
    &(o->dfframe->data[0][winlen - step + o->blockpos]));
  /* end of second level loop */
  tempo->data[0][0] = 0; /* reset tactus */
  i=0;
  for (i = 1; i < o->out->data[0][0]; i++ ) {
    /* if current frame is a predicted tactus */
    if (o->blockpos == o->out->data[0][i]) {
      /* test for silence */
      if (aubio_silence_detection(input, o->silence)==1) {
        tempo->data[0][1] = 0; /* unset onset */
        tempo->data[0][0] = 0; /* unset tactus */
      } else {
        tempo->data[0][0] = 1; /* set tactus */
      }
    }
  }
}
Пример #4
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;
		
}