Java Code Examples for be.tarsos.dsp.AudioEvent#getOverlap()

The following examples show how to use be.tarsos.dsp.AudioEvent#getOverlap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelayEffect.java    From cythara with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean process(AudioEvent audioEvent) {
	float[] audioFloatBuffer = audioEvent.getFloatBuffer();
	int overlap = audioEvent.getOverlap();
		
	for(int i = overlap ; i < audioFloatBuffer.length ; i++){
		if(position >= echoBuffer.length){
			position = 0;
		}
		
		//output is the input added with the decayed echo 		
		audioFloatBuffer[i] = audioFloatBuffer[i] + echoBuffer[position] * decay;
		//store the sample in the buffer;
		echoBuffer[position] = audioFloatBuffer[i];
		
		position++;
	}
	
	applyNewEchoLength();
	
	return true;
}
 
Example 2
Source File: IIRFilter.java    From cythara with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean process(AudioEvent audioEvent) {
	float[] audioFloatBuffer = audioEvent.getFloatBuffer();
	
	for (int i = audioEvent.getOverlap(); i < audioFloatBuffer.length; i++) {
		//shift the in array
		System.arraycopy(in, 0, in, 1, in.length - 1);
		in[0] = audioFloatBuffer[i];

		//calculate y based on a and b coefficients
		//and in and out.
		float y = 0;
		for(int j = 0 ; j < a.length ; j++){
			y += a[j] * in[j];
		}			
		for(int j = 0 ; j < b.length ; j++){
			y += b[j] * out[j];
		}
		//shift the out array
		System.arraycopy(out, 0, out, 1, out.length - 1);
		out[0] = y;
		
		audioFloatBuffer[i] = y;
	} 
	return true;
}
 
Example 3
Source File: PercussionOnsetDetector.java    From cythara with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean process(AudioEvent audioEvent) {
	float[] audioFloatBuffer = audioEvent.getFloatBuffer();
	this.processedSamples += audioFloatBuffer.length;
	this.processedSamples -= audioEvent.getOverlap();

	fft.forwardTransform(audioFloatBuffer);
	fft.modulus(audioFloatBuffer, currentMagnitudes);
	int binsOverThreshold = 0;
	for (int i = 0; i < currentMagnitudes.length; i++) {
		if (priorMagnitudes[i] > 0.f) {
			double diff = 10 * Math.log10(currentMagnitudes[i]
					/ priorMagnitudes[i]);
			if (diff >= threshold) {
				binsOverThreshold++;
			}
		}
		priorMagnitudes[i] = currentMagnitudes[i];
	}

	if (dfMinus2 < dfMinus1
			&& dfMinus1 >= binsOverThreshold
			&& dfMinus1 > ((100 - sensitivity) * audioFloatBuffer.length) / 200) {
		float timeStamp = processedSamples / sampleRate;
		handler.handleOnset(timeStamp,-1);
	}

	dfMinus2 = dfMinus1;
	dfMinus1 = binsOverThreshold;

	return true;
}
 
Example 4
Source File: AndroidAudioPlayer.java    From cythara with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean process(AudioEvent audioEvent) {
    int overlapInSamples = audioEvent.getOverlap();
    int stepSizeInSamples = audioEvent.getBufferSize() - overlapInSamples;
    byte[] byteBuffer = audioEvent.getByteBuffer();

    //int ret = audioTrack.write(audioEvent.getFloatBuffer(),overlapInSamples,stepSizeInSamples,AudioTrack.WRITE_BLOCKING);
    int ret = audioTrack.write(byteBuffer,overlapInSamples*2,stepSizeInSamples*2);
    if (ret < 0) {
        Log.e(TAG, "AudioTrack.write returned error code " + ret);
    }
    return true;
}
 
Example 5
Source File: ComplexOnsetDetector.java    From cythara with GNU General Public License v3.0 4 votes vote down vote up
private void onsetDetection(AudioEvent audioEvent){
	//calculate the complex fft (the magnitude and phase)
	float[] data = audioEvent.getFloatBuffer().clone();
	float[] power = new float[data.length/2];
	float[] phase = new float[data.length/2];
	fft.powerPhaseFFT(data, power, phase);
	
	float onsetValue = 0;
	
	for(int j = 0 ; j < power.length ; j++){
		//int imgIndex = (power.length - 1) * 2 - j;
		
		 // compute the predicted phase
		dev1[j] = 2.f * theta1[j] - theta2[j];
		
		// compute the euclidean distance in the complex domain
	    // sqrt ( r_1^2 + r_2^2 - 2 * r_1 * r_2 * \cos ( \phi_1 - \phi_2 ) )
		onsetValue += Math.sqrt(Math.abs(Math.pow(oldmag[j],2) + Math.pow(power[j],2) - 2. * oldmag[j] *power[j] * Math.cos(dev1[j] - phase[j])));
				
		/* swap old phase data (need to remember 2 frames behind)*/
		theta2[j] = theta1[j];
		theta1[j] = phase[j];
		
		/* swap old magnitude data (1 frame is enough) */
		oldmag[j]= power[j];
	}
	
	lastOnsetValue = onsetValue;
	
	
	boolean isOnset = peakPicker.pickPeak(onsetValue);
	if(isOnset){
		if(audioEvent.isSilence(silenceThreshold)){
			isOnset = false;
		} else {				
			double delay = ((audioEvent.getOverlap()  * 4.3 ))/ audioEvent.getSampleRate(); 
			double onsetTime = audioEvent.getTimeStamp() - delay;
			if(onsetTime - lastOnset > minimumInterOnsetInterval){
				handler.handleOnset(onsetTime,peakPicker.getLastPeekValue());
				lastOnset = onsetTime;
			}
		}
	}
}
 
Example 6
Source File: FlangerEffect.java    From cythara with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean process(AudioEvent audioEvent) {
	float[] audioFloatBuffer = audioEvent.getFloatBuffer();
	int overlap = audioEvent.getOverlap();

	// Divide f by two, to counter rectifier below, which effectively
	// doubles the frequency
	double twoPIf = 2 * Math.PI * lfoFrequency / 2.0;
	double time = audioEvent.getTimeStamp();
	double timeStep = 1.0 / sampleRate;

	for (int i = overlap; i < audioFloatBuffer.length; i++) {

		// Calculate the LFO delay value with a sine wave:
		//fix by hans bickel
		double lfoValue = (flangerBuffer.length - 1) * Math.sin(twoPIf * time);
		// add a time step, each iteration
		time += timeStep;

		// Make the delay a positive integer
		int delay = (int) (Math.round(Math.abs(lfoValue)));
		
		// store the current sample in the delay buffer;
		if (writePosition >= flangerBuffer.length) {
			writePosition = 0;
		}
		flangerBuffer[writePosition] = audioFloatBuffer[i];

		// find out the position to read the delayed sample:
		int readPosition = writePosition - delay;
		if (readPosition < 0) {
			readPosition += flangerBuffer.length;
		}

		//increment the write position
		writePosition++;

		// Output is the input summed with the value at the delayed flanger
		// buffer
		audioFloatBuffer[i] = dry * audioFloatBuffer[i] + wet * flangerBuffer[readPosition];
	}
	return true;
}