Java Code Examples for be.tarsos.dsp.AudioEvent#getSampleRate()
The following examples show how to use
be.tarsos.dsp.AudioEvent#getSampleRate() .
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: CrossCorrelation.java From Panako with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean process(AudioEvent audioEvent) { float[] fftData = audioEvent.getFloatBuffer().clone(); Arrays.fill(zeroPaddedData, 0); System.arraycopy(fftData, 0, zeroPaddedData, fftData.length/2, fftData.length); fft.forwardTransform(zeroPaddedData); fft.multiply(zeroPaddedData, zeroPaddedInvesedQuery); fft.backwardsTransform(zeroPaddedData); float maxVal = -100000; int maxIndex = 0; for(int i = 0 ; i<zeroPaddedData.length ; i++){ if(zeroPaddedData[i]> maxVal){ maxVal = zeroPaddedData[i]; maxIndex=i; } } float time = (float) (audioEvent.getTimeStamp() - audioEvent.getBufferSize()/audioEvent.getSampleRate() + maxIndex/2 /audioEvent.getSampleRate() + 0.005); handler.handleCrossCorrelation((float)audioEvent.getTimeStamp(), time, maxVal); return true; }
Example 2
Source File: SineGenerator.java From cythara with GNU General Public License v3.0 | 5 votes |
@Override public boolean process(AudioEvent audioEvent) { float[] buffer = audioEvent.getFloatBuffer(); double sampleRate = audioEvent.getSampleRate(); double twoPiF = 2 * Math.PI * frequency; double time = 0; for(int i = 0 ; i < buffer.length ; i++){ time = i / sampleRate; buffer[i] += (float) (gain * Math.sin(twoPiF * time + phase)); } phase = twoPiF * buffer.length / sampleRate + phase; return true; }
Example 3
Source File: AmplitudeLFO.java From cythara with GNU General Public License v3.0 | 5 votes |
@Override public boolean process(AudioEvent audioEvent) { float[] buffer = audioEvent.getFloatBuffer(); double sampleRate = audioEvent.getSampleRate(); double twoPiF = 2 * Math.PI * frequency; double time = 0; for(int i = 0 ; i < buffer.length ; i++){ time = i / sampleRate; float gain = (float) (scaleParameter * Math.sin(twoPiF * time + phase)); buffer[i] = gain * buffer[i]; } phase = twoPiF * buffer.length / sampleRate + phase; return true; }
Example 4
Source File: ComplexOnsetDetector.java From cythara with GNU General Public License v3.0 | 4 votes |
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; } } } }