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;
	
}
Example #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);
}
Example #3
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;
		
}