code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
833 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
protected void predict(float[] vec, int N, int direction) { int half = N >> 1; for (int i = 0; i < half; i++) { float predictVal = vec[i]; int j = i + half; if (direction == forward) { vec[j] = vec[j] - predictVal; } else if (direction == inverse) { vec[j] = vec[j] + predictVal; } else { System.out.println("HaarWavelet::predict: bad direction value"); } } }
HaarWavelet predict step
HaarWavelet::predict
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/wavelet/lift/HaarWavelet.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/wavelet/lift/HaarWavelet.java
Apache-2.0
public void forwardTransOne(float[] vec) { final int N = vec.length; split(vec, N); predict(vec, N, forward); update(vec, N, forward); } // forwardTrans
Transform forward @param vec the vector to update.
HaarWavelet::forwardTransOne
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/wavelet/lift/HaarWavelet.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/wavelet/lift/HaarWavelet.java
Apache-2.0
protected void update(float[] vec, int N, int direction) { int half = N >> 1; for (int i = 0; i < half; i++) { int j = i + half; float updateVal = vec[j] / 2.0f; if (direction == forward) { vec[i] = vec[i] + updateVal; } else if (direction == inverse) { vec[i] = vec[i] - updateVal; } else { System.out.println("update: bad direction value"); } } }
<p> Update step of the HaarWavelet wavelet transform. </p> <p> The wavelet transform calculates a set of detail or difference coefficients in the predict step. These are stored in the upper half of the array. The update step calculates an average from the even-odd element pairs. The averages will replace the even elements in the lower half of the array. </p> <p> The HaarWavelet wavelet calculation used in the Lifting Scheme is </p> <pre> d j+1, i = odd j+1, i = odd j, i - even j, i a j+1, i = even j, i = (even j, i + odd j, i )/2 </pre> <p> Note that the Lifting Scheme uses an in-place algorithm. The odd elements have been replaced by the detail coefficients in the predict step. With a little algebra we can substitute the coefficient calculation into the average calculation, which gives us </p> <pre> a j+1, i = even j, i = even j, i + (odd j, i /2) </pre>
HaarWavelet::update
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/wavelet/lift/HaarWavelet.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/wavelet/lift/HaarWavelet.java
Apache-2.0
public void inverseTrans(float[] vec) { final int N = vec.length; for (int n = 2; n <= N; n = n << 1) { normalize(vec, n, inverse); update(vec, n, inverse); predict(vec, n, inverse); updateOne(vec, n, inverse); merge(vec, n); } } // inverseTrans
<p> Default two step Lifting Scheme inverse wavelet transform </p> <p> inverseTrans is passed the result of an ordered wavelet transform, consisting of an average and a set of wavelet coefficients. The inverse transform is calculated in-place and the result is returned in the argument array. </p>
Daubechies4Wavelet::inverseTrans
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/wavelet/lift/Daubechies4Wavelet.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/wavelet/lift/Daubechies4Wavelet.java
Apache-2.0
private PitchConverter() { }
Hide the default constructor.
PitchConverter::PitchConverter
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static int hertzToMidiKey(final Double hertzValue) { final int midiKey = (int) Math.round(hertzToMidiCent(hertzValue)); if (midiKey < 0 || midiKey > 127) { // TODO // LOG.warning("MIDI is only defined between [" + midiKeyToHertz(0) // + "," // + midiKeyToHertz(127) + "] " + hertzValue + // "does not map to a MIDI key."); } return midiKey; }
A MIDI key is an integer between 0 and 127, inclusive. Within a certain range every pitch is mapped to a MIDI key. If a value outside the range is given an IllegalArugmentException is thrown. @param hertzValue The pitch in Hertz. @return An integer representing the closest midi key. @exception IllegalArgumentException if the hertzValue does not fall within the range of valid MIDI key frequencies.
PitchConverter::hertzToMidiKey
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double midiKeyToHertz(final int midiKey) { if (midiKey < 0 || midiKey > 127) { throw new IllegalArgumentException("MIDI keys are values from 0 to 127, inclusive " + midiKey + " is invalid."); } return midiCentToHertz(midiKey); }
Calculates the frequency (Hz) for a MIDI key. @param midiKey The MIDI key. A MIDI key is an integer between 0 and 127, inclusive. @return A frequency in Hz corresponding to the MIDI key. @exception IllegalArgumentException If midiKey is not in the valid range between 0 and 127, inclusive.
PitchConverter::midiKeyToHertz
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double hertzToRelativeCent(final double hertzValue) { double absoluteCentValue = hertzToAbsoluteCent(hertzValue); // make absoluteCentValue positive. E.g. -2410 => 1210 if (absoluteCentValue < 0) { absoluteCentValue = Math.abs(1200 + absoluteCentValue); } // so it can be folded to one octave. E.g. 1210 => 10 return absoluteCentValue % 1200.0; }
Converts a Hertz value to relative cents. E.g. 440Hz is converted to 900 if the reference is a C. @param hertzValue A value in hertz. @return A value in relative cents.
PitchConverter::hertzToRelativeCent
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double hertzToAbsoluteCent(final double hertzValue) { double pitchInAbsCent = 0.0; if (hertzValue > 0) { pitchInAbsCent = 1200 * Math.log(hertzValue / REF_FREQ) / LOG_TWO; } else { throw new IllegalArgumentException("Pitch in Hz schould be greater than zero, is " + hertzValue); } return pitchInAbsCent; }
The reference frequency is configured. The default reference frequency is 16.35Hz. This is C0 on a piano keyboard with A4 tuned to 440 Hz. This means that 0 cents is C0; 1200 is C1; 2400 is C2; ... also -1200 cents is C-1 @param hertzValue The pitch in Hertz. @return The value in absolute cents using the configured reference frequency
PitchConverter::hertzToAbsoluteCent
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double absoluteCentToHertz(final double absoluteCent) { return REF_FREQ * Math.pow(2, absoluteCent / 1200.0); }
Returns the frequency (Hz) of an absolute cent value. This calculation uses a configured reference frequency. @param absoluteCent The pitch in absolute cent. @return A pitch in Hz.
PitchConverter::absoluteCentToHertz
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double hertzToMidiCent(final double hertzValue) { double pitchInMidiCent = 0.0; if (hertzValue != 0) { pitchInMidiCent = 12 * Math.log(hertzValue / 440) / LOG_TWO + 69; } return pitchInMidiCent; }
Converts a frequency in Hz to a MIDI CENT value using <code>(12 * log2 (f / 440)) + 69</code> <br> E.g.<br> <code>69.168 MIDI CENTS = MIDI NOTE 69 + 16,8 cents</code><br> <code>69.168 MIDI CENTS = 440Hz + x Hz</code> @param hertzValue The pitch in Hertz. @return The pitch in MIDI cent.
PitchConverter::hertzToMidiCent
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double midiCentToHertz(final double midiCent) { return 440 * Math.pow(2, (midiCent - 69) / 12d); }
Converts a MIDI CENT frequency to a frequency in Hz. @param midiCent The pitch in MIDI CENT. @return The pitch in Hertz.
PitchConverter::midiCentToHertz
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double centToRatio(final double cent) { final double ratio; ratio = Math.pow(10, Math.log10(2) * cent / 1200.0); return ratio; }
Converts cent values to ratios. See "Ratios Make Cents: Conversions from ratios to cents and back again" in the book "Tuning Timbre Spectrum Scale" William A. Sethares. @param cent A cent value @return A ratio containing the same information.
PitchConverter::centToRatio
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public static double ratioToCent(final double ratio) { final double cent; cent = 1200 / Math.log10(2) * Math.log10(ratio); return cent; }
Converts a ratio to cents. "Ratios Make Cents: Conversions from ratios to cents and back again" in the book "Tuning Timbre Spectrum Scale" William A. Sethares @param ratio A cent value @return A ratio containing the same information.
PitchConverter::ratioToCent
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PitchConverter.java
Apache-2.0
public Complex(double u,double v) { x=u; y=v; }
Constructs the complex number z = u + i*v @param u Real part @param v Imaginary part
Complex::Complex
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public double real() { return x; }
Real part of this Complex number (the x-coordinate in rectangular coordinates). @return Re[z] where z is this Complex number.
Complex::real
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public double imag() { return y; }
Imaginary part of this Complex number (the y-coordinate in rectangular coordinates). @return Im[z] where z is this Complex number.
Complex::imag
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public double mod() { if (x!=0 || y!=0) { return Math.sqrt(x*x+y*y); } else { return 0d; } }
Modulus of this Complex number (the distance from the origin in polar coordinates). @return |z| where z is this Complex number.
Complex::mod
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public double arg() { return Math.atan2(y,x); }
Argument of this Complex number (the angle in radians with the x-axis in polar coordinates). @return arg(z) where z is this Complex number.
Complex::arg
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex conj() { return new Complex(x,-y); }
Complex conjugate of this Complex number (the conjugate of x+i*y is x-i*y). @return z-bar where z is this Complex number.
Complex::conj
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex plus(Complex w) { return new Complex(x+w.real(),y+w.imag()); }
Addition of Complex numbers (doesn't change this Complex number). <br>(x+i*y) + (s+i*t) = (x+s)+i*(y+t). @param w is the number to add. @return z+w where z is this Complex number.
Complex::plus
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex minus(Complex w) { return new Complex(x-w.real(),y-w.imag()); }
Subtraction of Complex numbers (doesn't change this Complex number). <br>(x+i*y) - (s+i*t) = (x-s)+i*(y-t). @param w is the number to subtract. @return z-w where z is this Complex number.
Complex::minus
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex times(Complex w) { return new Complex(x*w.real()-y*w.imag(),x*w.imag()+y*w.real()); }
Complex multiplication (doesn't change this Complex number). @param w is the number to multiply by. @return z*w where z is this Complex number.
Complex::times
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex div(Complex w) { double den=Math.pow(w.mod(),2); return new Complex((x*w.real()+y*w.imag())/den,(y*w.real()-x*w.imag())/den); }
Division of Complex numbers (doesn't change this Complex number). <br>(x+i*y)/(s+i*t) = ((x*s+y*t) + i*(y*s-y*t)) / (s^2+t^2) @param w is the number to divide by @return new Complex number z/w where z is this Complex number
Complex::div
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex exp() { return new Complex(Math.exp(x)*Math.cos(y),Math.exp(x)*Math.sin(y)); }
Complex exponential (doesn't change this Complex number). @return exp(z) where z is this Complex number.
Complex::exp
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex log() { return new Complex(Math.log(this.mod()),this.arg()); }
Principal branch of the Complex logarithm of this Complex number. (doesn't change this Complex number). The principal branch is the branch with -pi &lt; arg &lt;= pi. @return log(z) where z is this Complex number.
Complex::log
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex sqrt() { double r=Math.sqrt(this.mod()); double theta=this.arg()/2; return new Complex(r*Math.cos(theta),r*Math.sin(theta)); }
Complex square root (doesn't change this complex number). Computes the principal branch of the square root, which is the value with 0 &lt;= arg &lt; pi. @return sqrt(z) where z is this Complex number.
Complex::sqrt
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex sin() { return new Complex(cosh(y)*Math.sin(x),sinh(y)*Math.cos(x)); }
Sine of this Complex number (doesn't change this Complex number). <br>sin(z) = (exp(i*z)-exp(-i*z))/(2*i). @return sin(z) where z is this Complex number.
Complex::sin
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex cos() { return new Complex(cosh(y)*Math.cos(x),-sinh(y)*Math.sin(x)); }
Cosine of this Complex number (doesn't change this Complex number). <br>cos(z) = (exp(i*z)+exp(-i*z))/ 2. @return cos(z) where z is this Complex number.
Complex::cos
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex sinh() { return new Complex(sinh(x)*Math.cos(y),cosh(x)*Math.sin(y)); }
Hyperbolic sine of this Complex number (doesn't change this Complex number). <br>sinh(z) = (exp(z)-exp(-z))/2. @return sinh(z) where z is this Complex number.
Complex::sinh
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex cosh() { return new Complex(cosh(x)*Math.cos(y),sinh(x)*Math.sin(y)); }
Hyperbolic cosine of this Complex number (doesn't change this Complex number). <br>cosh(z) = (exp(z) + exp(-z)) / 2. @return cosh(z) where z is this Complex number.
Complex::cosh
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex tan() { return (this.sin()).div(this.cos()); }
Tangent of this Complex number (doesn't change this Complex number). <br>tan(z) = sin(z)/cos(z). @return tan(z) where z is this Complex number.
Complex::tan
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public Complex chs() { return new Complex(-x,-y); }
Negative of this complex number (chs stands for change sign). This produces a new Complex number and doesn't change this Complex number. <br>-(x+i*y) = -x-i*y. @return -z where z is this Complex number.
Complex::chs
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public String toString() { if (x!=0 && y>0) { return x+" + "+y+"i"; } if (x!=0 && y<0) { return x+" - "+(-y)+"i"; } if (y==0) { return String.valueOf(x); } if (x==0) { return y+"i"; } // shouldn't get here (unless Inf or NaN) return x+" + i*"+y; }
String representation of this Complex number. @return x+i*y, x-i*y, x, or i*y as appropriate.
Complex::toString
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/Complex.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/Complex.java
Apache-2.0
public PeakPicker(double threshold) { /* Low-pass filter cutoff [0.34, 1] */ biquad = new BiQuadFilter(0.1600,0.3200,0.1600,-0.5949,0.2348); this.threshold = threshold; win_post = 5; win_pre = 1; onset_keep = new float[win_post + win_pre +1]; onset_proc = new float[win_post + win_pre +1]; scratch = new float[win_post + win_pre +1]; onset_peek = new float[3]; }
Initializes a new moving mean adaptive threshold peak picker. @param threshold The threshold defines when a peak is selected. It should be between zero and one, 0.3 is a reasonable value. If too many peaks are detected go to 0.5 - 0.8.
PeakPicker::PeakPicker
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
Apache-2.0
public void setThreshold(double threshold) { this.threshold = threshold; }
Sets a new threshold. @param threshold The threshold defines when a peak is selected. It should be between zero and one, 0.3 is a reasonable value. If too many peaks are detected go to 0.5 - 0.8.
PeakPicker::setThreshold
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
Apache-2.0
public boolean pickPeak(float onset) { float mean = 0.f; float median = 0.f; int length = win_post + win_pre + 1; /* store onset in onset_keep */ /* shift all elements but last, then write last */ /* for (i=0;i<channels;i++) { */ for(int j=0;j<length-1;j++) { onset_keep[j] = onset_keep[j+1]; onset_proc[j] = onset_keep[j]; } onset_keep[length-1] = onset; onset_proc[length-1] = onset; /* filter onset_proc */ /** \bug filtfilt calculated post+pre times, should be only once !? */ biquad.doFiltering(onset_proc,scratch); /* calculate mean and median for onset_proc */ /* copy to scratch */ float sum = 0.0f; for (int j = 0; j < length; j++){ scratch[j] = onset_proc[j]; sum += scratch[j]; } Arrays.sort(scratch); median = scratch[scratch.length/2]; mean = sum/Float.valueOf(length); /* shift peek array */ for (int j=0;j<3-1;j++){ onset_peek[j] = onset_peek[j+1]; } /* calculate new peek value */ onset_peek[2] = (float) (onset_proc[win_post] - median - mean * threshold); boolean isPeak = isPeak(1); lastPeekValue = onset; return isPeak; }
Modified version for real time, moving mean adaptive threshold this method is slightly more permissive than the off-LineWavelet one, and yields to an increase of false positives. @param onset The new onset value. @return True if a peak is detected, false otherwise.
PeakPicker::pickPeak
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
Apache-2.0
public float getLastPeekValue() { return lastPeekValue; }
@return The value of the last detected peak, or zero.
PeakPicker::getLastPeekValue
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
Apache-2.0
private boolean isPeak(int index) { return ( onset_peek[index] > onset_peek[index - 1] && onset_peek[index] > onset_peek[index + 1] && onset_peek[index] > 0.); }
Returns true if the onset is a peak. @param index the index in onset_peak to check. @return True if the onset is a peak, false otherwise.
PeakPicker::isPeak
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/PeakPicker.java
Apache-2.0
public FFMPEGDownloader(){ String filename = operatingSystemName() + "_" + processorArchitecture() + "_ffmpeg" + suffix(); url = url + filename; String tempDirectory = System.getProperty("java.io.tmpdir"); String saveTo = new File(tempDirectory,filename).getAbsolutePath(); if(new File(saveTo).exists() && new File(saveTo).length() > 1000){ LOG.info("Found an already download ffmpeg static binary: " + saveTo); ffmpegBinary = saveTo; }else{ LOG.info("Started downloading an ffmpeg static binary from " + url + " to " + saveTo ); downloadExecutable(saveTo); if(new File(saveTo).exists() && new File(saveTo).length() > 1000){ LOG.info("Downloaded an ffmpeg static binary. Stored at: " + saveTo); //make it executable new File(saveTo).setExecutable(true); ffmpegBinary = saveTo; }else{ //Unable to download or unknown architecture LOG.warning("Unable to find or download an ffmpeg static binary. " + filename); ffmpegBinary = null; } } }
A new FFMPEGDownloader
FFMPEGDownloader::FFMPEGDownloader
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/FFMPEGDownloader.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/FFMPEGDownloader.java
Apache-2.0
public String ffmpegBinary(){ if(ffmpegBinary!=null){ return ffmpegBinary.replace(suffix(), ""); } return null; }
The path of the downloaded ffmpeg binary or null @return The path of the downloaded ffmpeg binary or null
FFMPEGDownloader::ffmpegBinary
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/FFMPEGDownloader.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/FFMPEGDownloader.java
Apache-2.0
public BiQuadFilter(double b1, double b2, double b3, double a2, double a3) { this.a2 = a2; this.a3 = a3; this.b1 = b1; this.b2 = b2; this.b3 = b3; this.i1 = 0.; this.i2 = 0.; this.o1 = 0.; this.o2 = 0.; }
Create a new biquad filter @param b1 first @param b2 second @param b3 third @param a2 a first @param a3 a second
BiQuadFilter::BiQuadFilter
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/BiQuadFilter.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/BiQuadFilter.java
Apache-2.0
public static String sanitizeResource(String inputResource) { if (inputResource.toLowerCase().endsWith("pls")) { inputResource = parsePLS(inputResource); } else if (inputResource.toLowerCase().endsWith("m3u")) { inputResource = parseM3U(inputResource); } else if (inputResource.toLowerCase().endsWith("asx")){ inputResource = parseASX(inputResource); } else if (inputResource.toLowerCase().endsWith("xspf")){ inputResource = parseXSPF(inputResource); } return inputResource; }
Returns a more practical audio resource name. E.g. if http://stream.com/stream.pls is given, the PLS-file is parsed and the first audio file is returned. It supports PLS, M3U, AXS and XSPF" @param inputResource The input resource, a file, URL, PLS-file or M3U-file. @return A more practical audio resource name.
AudioResourceUtils::sanitizeResource
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
Apache-2.0
public static String parsePLS(String inputUrl) { String inputFile = ""; try { String plsContents = readTextFromUrl(new URL(inputUrl)); for (String line : plsContents.split("\n")) { if (line.startsWith("File1=")) { inputFile = line.replace("File1=", "").trim(); break; } } } catch (MalformedURLException e) { e.printStackTrace(); } return inputFile; }
Parses the PLS file and returns the first file name. @param inputUrl The input PLS file. @return The first file name in the PLS playlist.
AudioResourceUtils::parsePLS
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
Apache-2.0
public static String parseM3U(String inputUrl) { String inputFile = ""; try { String plsContents = readTextFromUrl(new URL(inputUrl)); for (String line : plsContents.split("\n")) { if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { inputFile = line.trim(); break; } } } catch (MalformedURLException e) { e.printStackTrace(); } return inputFile; }
Parses the M3U file and returns the first file name. @param inputUrl The input M3U file. @return The first file name in the M3U play list.
AudioResourceUtils::parseM3U
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
Apache-2.0
public static String readTextFromUrl(URL url) { StringBuffer fubber = new StringBuffer(); try { BufferedReader in = new BufferedReader(new InputStreamReader( url.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) { fubber.append(inputLine).append("\n"); } in.close(); } catch (IOException exception) { exception.printStackTrace(); } return fubber.toString(); }
Return the text of the file with the given URL. E.g. if http://test.be/text.txt is given the contents of text.txt is returned. @param url The URL. @return The contents of the file.
AudioResourceUtils::readTextFromUrl
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/AudioResourceUtils.java
Apache-2.0
public static int getNumberOfProcessors() { return Runtime.getRuntime().availableProcessors(); }
Returns the number of available processors. @return number of available processors
CustomThreadFactory::getNumberOfProcessors
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int getNumberOfThreads() { return NTHREADS; }
Returns the current number of threads. @return the current number of threads.
CustomThreadFactory::getNumberOfThreads
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void setNumberOfThreads(int n) { NTHREADS = prevPow2(n); }
Sets the number of threads. If n is not a power-of-two number, then the number of threads is set to the closest power-of-two number less than n. @param n The number of threads
CustomThreadFactory::setNumberOfThreads
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int getThreadsBeginN_1D_FFT_2Threads() { return THREADS_BEGIN_N_1D_FFT_2THREADS; }
Returns the minimal size of 1D data for which two threads are used. @return the minimal size of 1D data for which two threads are used
CustomThreadFactory::getThreadsBeginN_1D_FFT_2Threads
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int getThreadsBeginN_1D_FFT_4Threads() { return THREADS_BEGIN_N_1D_FFT_4THREADS; }
Returns the minimal size of 1D data for which four threads are used. @return the minimal size of 1D data for which four threads are used
CustomThreadFactory::getThreadsBeginN_1D_FFT_4Threads
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int getThreadsBeginN_2D() { return THREADS_BEGIN_N_2D; }
Returns the minimal size of 2D data for which threads are used. @return the minimal size of 2D data for which threads are used
CustomThreadFactory::getThreadsBeginN_2D
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int getThreadsBeginN_3D() { return THREADS_BEGIN_N_3D; }
Returns the minimal size of 3D data for which threads are used. @return the minimal size of 3D data for which threads are used
CustomThreadFactory::getThreadsBeginN_3D
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void setThreadsBeginN_1D_FFT_2Threads(int n) { if (n < 512) { THREADS_BEGIN_N_1D_FFT_2THREADS = 512; } else { THREADS_BEGIN_N_1D_FFT_2THREADS = n; } }
Sets the minimal size of 1D data for which two threads are used. @param n the minimal size of 1D data for which two threads are used
CustomThreadFactory::setThreadsBeginN_1D_FFT_2Threads
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void setThreadsBeginN_1D_FFT_4Threads(int n) { if (n < 512) { THREADS_BEGIN_N_1D_FFT_4THREADS = 512; } else { THREADS_BEGIN_N_1D_FFT_4THREADS = n; } }
Sets the minimal size of 1D data for which four threads are used. @param n the minimal size of 1D data for which four threads are used
CustomThreadFactory::setThreadsBeginN_1D_FFT_4Threads
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void setThreadsBeginN_2D(int n) { THREADS_BEGIN_N_2D = n; }
Sets the minimal size of 2D data for which threads are used. @param n the minimal size of 2D data for which threads are used
CustomThreadFactory::setThreadsBeginN_2D
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void setThreadsBeginN_3D(int n) { THREADS_BEGIN_N_3D = n; }
Sets the minimal size of 3D data for which threads are used. @param n the minimal size of 3D data for which threads are used
CustomThreadFactory::setThreadsBeginN_3D
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void resetThreadsBeginN_FFT() { THREADS_BEGIN_N_1D_FFT_2THREADS = 8192; THREADS_BEGIN_N_1D_FFT_4THREADS = 65536; }
Resets the minimal size of 1D data for which two and four threads are used.
CustomThreadFactory::resetThreadsBeginN_FFT
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void resetThreadsBeginN() { THREADS_BEGIN_N_2D = 65536; THREADS_BEGIN_N_3D = 65536; }
Resets the minimal size of 2D and 3D data for which threads are used.
CustomThreadFactory::resetThreadsBeginN
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int nextPow2(int x) { if (x < 1) throw new IllegalArgumentException("x must be greater or equal 1"); if ((x & (x - 1)) == 0) { return x; // x is already a power-of-two number } x |= (x >>> 1); x |= (x >>> 2); x |= (x >>> 4); x |= (x >>> 8); x |= (x >>> 16); x |= (x >>> 32); return x + 1; }
Returns the closest power-of-two number greater than or equal to x. @param x the number to process @return the closest power-of-two number greater than or equal to x
CustomThreadFactory::nextPow2
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static int prevPow2(int x) { if (x < 1) throw new IllegalArgumentException("x must be greater or equal 1"); return (int) Math.pow(2, Math.floor(Math.log(x) / Math.log(2))); }
Returns the closest power-of-two number less than or equal to x. @param x the number to process @return the closest power-of-two number less then or equal to x
CustomThreadFactory::prevPow2
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static boolean isPowerOf2(int x) { if (x <= 0) return false; else return (x & (x - 1)) == 0; }
Checks if x is a power-of-two number. @param x the number to process @return true if x is a power-of-two number
CustomThreadFactory::isPowerOf2
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); } }
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. @param millis the number to millis to sleep
CustomThreadFactory::sleep
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static Future<?> submit(Runnable task) { return THREAD_POOL.submit(task); }
Submits a Runnable task for execution and returns a Future representing that task. @param task a Runnable task for execution @return a Future representing the task
CustomThreadFactory::submit
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public static void waitForCompletion(Future<?>[] futures) { int size = futures.length; try { for (int j = 0; j < size; j++) { futures[j].get(); } } catch (ExecutionException ex) { ex.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
Waits for all threads to complete computation. @param futures The futures which need completion.
CustomThreadFactory::waitForCompletion
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/ConcurrencyUtils.java
Apache-2.0
public HammingWindow() { super(); }
Constructs a Hamming window.
HammingWindow::HammingWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/HammingWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/HammingWindow.java
Apache-2.0
public LanczosWindow() { }
A Lanczos window function. @author Damien Di Fede @author Corban Brook @see <a href="http://en.wikipedia.org/wiki/Window_function#Lanczos_window">The Lanczos Window</a> public class LanczosWindow extends WindowFunction { /** Constructs a Lanczos window.
LanczosWindow::LanczosWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/LanczosWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/LanczosWindow.java
Apache-2.0
public BartlettHannWindow() { }
A Bartlett-Hann window function. @author Damien Di Fede @author Corban Brook @see <a href="http://en.wikipedia.org/wiki/Window_function#Bartlett.E2.80.93Hann_window">The Bartlett-Hann Window</a> public class BartlettHannWindow extends WindowFunction { /** Constructs a Bartlett-Hann window.
BartlettHannWindow::BartlettHannWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/BartlettHannWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/BartlettHannWindow.java
Apache-2.0
public FFT(final int size) { this(size,null); }
Create a new fft @param size of this size
FFT::FFT
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public FFT(final int size, final WindowFunction windowFunction){ fft = new FloatFFT(size); fftSize = size; this.windowFunction = windowFunction; if(windowFunction==null) window = null; else window = windowFunction.generateCurve(size); }
Create a new fft of the specified size. Apply the specified window on the samples before a forward transform. arning: the window is not applied in reverse when a backwards transform is requested. @param size The size of the fft. @param windowFunction Apply the specified window on the samples before a forward transform. arning: the window is not applied in reverse when a backwards transform is requested.
FFT::FFT
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void forwardTransform(final float[] data) { if(windowFunction!=null){ for(int i = 0 ; i < data.length ; i++){ data[i] = data[i] * window[i]; } //windowFunction.apply(data); } fft.realForward(data); }
Computes forward DFT. @param data data to transform.
FFT::forwardTransform
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void complexForwardTransform(final float[] data) { if(windowFunction!=null){ for(int i = 0 ; i < data.length ; i++){ data[i] = data[i] * window[i]; } //windowFunction.apply(data); } fft.complexForward(data); }
do a complex forward transform @param data do a complex forward transform on these complex numbers
FFT::complexForwardTransform
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void backwardsTransform(final float[] data) { fft.realInverse(data, true); }
Computes inverse DFT. Warning, does not reverse the window function. @param data data to transform
FFT::backwardsTransform
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public double binToHz(final int binIndex, final float sampleRate) { return binIndex * sampleRate / (double) fftSize; }
Calculate the frequency of the bin. @param binIndex The index of the bin. @param sampleRate The sample rate of the audio. @return The frequency in Hz of the bin.
FFT::binToHz
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public int size(){ return fftSize; }
The size of the fft. @return The size of the fft.
FFT::size
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public float modulus(final float[] data, final int index) { final int realIndex = 2 * index; final int imgIndex = 2 * index + 1; final float modulus = data[realIndex] * data[realIndex] + data[imgIndex] * data[imgIndex]; return (float) Math.sqrt(modulus); }
Returns the modulus of the element at index bufferCount. The modulus, magnitude or absolute value is (a²+b²) ^ 0.5 with a being the real part and b the imaginary part of a complex number. @param data The FFT transformed data. @param index The index of the element. @return The modulus, magnitude or absolute value of the element at index bufferCount
FFT::modulus
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void modulus(final float[] data, final float[] amplitudes) { assert data.length / 2 == amplitudes.length; for (int i = 0; i < amplitudes.length; i++) { amplitudes[i] = modulus(data, i); } }
Calculates the the modulus for each element in data and stores the result in amplitudes. @param data The input data. @param amplitudes The output modulus info or amplitude.
FFT::modulus
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void powerPhaseFFT(float[] data,float[] power, float[] phase) { assert data.length / 2 == power.length; assert data.length / 2 == phase.length; if(windowFunction!=null){ windowFunction.apply(data); } fft.realForward(data); powerAndPhaseFromFFT(data, power, phase); }
Computes an FFT and converts the results to polar coordinates (power and phase). Both the power and phase arrays must be the same length, data should be double the length. @param data The input audio signal. @param power The power (modulus) of the data. @param phase The phase of the data
FFT::powerPhaseFFT
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void powerAndPhaseFromFFT(float[] data,float[] power, float[] phase){ phase[0] = (float) Math.PI; power[0] = -data[0]; for (int i = 1; i < power.length; i++) { int realIndex = 2 * i; int imgIndex = 2 * i + 1; power[i] = (float) Math.sqrt(data[realIndex] * data[realIndex] + data[imgIndex] * data[imgIndex]); phase[i] = (float) Math.atan2(data[imgIndex], data[realIndex]); } }
Returns magnitude (or power) and phase for the FFT transformed data. @param data The FFT transformed data. @param power The array where the magnitudes or powers are going to be stored. It is half the length of data (FFT size). @param phase The array where the phases are going to be stored. It is half the length of data (FFT size).
FFT::powerAndPhaseFromFFT
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void powerPhaseFFTBeatRootOnset(float[] data,float[] power, float[] phase) { powerPhaseFFT(data, power, phase); power[0] = (float) Math.sqrt(data[0] * data[0] + data[1] * data[1]); }
Beatroot expects a different first power element @param data The FFT transformed data. @param power The array where the magnitudes or powers are going to be stored. It is half the length of data (FFT size). @param phase The array where the phases are going to be stored. It is half the length of data (FFT size).
FFT::powerPhaseFFTBeatRootOnset
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
public void multiply(float[] data, float[] other){ assert data.length == other.length; if(data.length!=other.length){ throw new IllegalArgumentException("Both arrays with imaginary numbers shouldb e of equal length"); } for (int i = 1; i < data.length-1; i+=2) { int realIndex = i; int imgIndex = i + 1; float tempReal = data[realIndex] * other[realIndex] + -1 * data[imgIndex] * other[imgIndex]; float tempImg = data[realIndex] * other[imgIndex] + data[imgIndex] * other[realIndex]; data[realIndex] = tempReal; data[imgIndex] = tempImg; //fix by perfecthu //data[realIndex] = data[realIndex] * other[realIndex] + -1 * data[imgIndex] * other[imgIndex]; //data[imgIndex] = data[realIndex] * other[imgIndex] + data[imgIndex] * other[realIndex]; } }
Multiplies to arrays containing imaginary numbers. The data in the first argument is modified! The real part is stored at <code>2*i</code>, the imaginary part <code>2*i+i</code> @param data The array with imaginary numbers that is modified. @param other The array with imaginary numbers that is not modified. Data and other need to be the same length.
FFT::multiply
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FFT.java
Apache-2.0
protected WindowFunction() { }
Construct a new window.
WindowFunction::WindowFunction
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/WindowFunction.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/WindowFunction.java
Apache-2.0
public void apply(float[] samples) { this.length = samples.length; for (int n = 0; n < samples.length; n++) { samples[n] *= value(samples.length, n); } }
Apply the window function to a sample buffer. @param samples a sample buffer
WindowFunction::apply
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/WindowFunction.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/WindowFunction.java
Apache-2.0
public float[] generateCurve(int length) { float[] samples = new float[length]; for (int n = 0; n < length; n++) { samples[n] = value(length, n); } return samples; }
Generates the curve of the window function. @param length the length of the window @return the shape of the window function
WindowFunction::generateCurve
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/WindowFunction.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/WindowFunction.java
Apache-2.0
public BlackmanWindow(float alpha) { this.alpha = alpha; }
Constructs a Blackman window. @param alpha The Blackman alpha parameter
BlackmanWindow::BlackmanWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/BlackmanWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/BlackmanWindow.java
Apache-2.0
public BlackmanWindow() { this(0.16f); }
Constructs a Blackman window. @param alpha The Blackman alpha parameter public BlackmanWindow(float alpha) { this.alpha = alpha; } /** Constructs a Blackman window with a default alpha value of 0.16
BlackmanWindow::BlackmanWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/BlackmanWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/BlackmanWindow.java
Apache-2.0
public CosineWindow() { }
A Cosine window function. @author Damien Di Fede @author Corban Brook @see <a href="http://en.wikipedia.org/wiki/Window_function#Cosine_window">The Cosine Window</a> public class CosineWindow extends WindowFunction { /** Constructs a Cosine window.
CosineWindow::CosineWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/CosineWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/CosineWindow.java
Apache-2.0
public BartlettWindow() { }
A Bartlett window function. @author Damien Di Fede @author Corban Brook @see <a href="http://en.wikipedia.org/wiki/Window_function#Bartlett_window_.28zero_valued_end-points.29">The Bartlett Window</a> public class BartlettWindow extends WindowFunction { /** Constructs a Bartlett window.
BartlettWindow::BartlettWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/BartlettWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/BartlettWindow.java
Apache-2.0
public RectangularWindow() { }
A Rectangular window function A Rectangular window is equivalent to using no window at all. @author Damien Di Fede @author Corban Brook @see <a href="http://en.wikipedia.org/wiki/Window_function#Rectangular_window">The Rectangular Window</a> public class RectangularWindow extends WindowFunction { /** Constructs a Rectangular window.
RectangularWindow::RectangularWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/RectangularWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/RectangularWindow.java
Apache-2.0
public HannWindow() { }
A Hann window function. @author Damien Di Fede @author Corban Brook @see <a href="http://en.wikipedia.org/wiki/Window_function#Hann_window">The Hann Window</a> public class HannWindow extends WindowFunction { /** Constructs a Hann window.
HannWindow::HannWindow
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/HannWindow.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/HannWindow.java
Apache-2.0
public FloatFFT(int n) { if (n < 1) { throw new IllegalArgumentException("n must be greater than 0"); } this.n = n; if (!ConcurrencyUtils.isPowerOf2(n)) { if (getReminder(n, factors) >= 211) { plan = Plans.BLUESTEIN; nBluestein = ConcurrencyUtils.nextPow2(n * 2 - 1); bk1 = new float[2 * nBluestein]; bk2 = new float[2 * nBluestein]; this.ip = new int[2 + (int) Math.ceil(2 + (1 << (int) (Math.log(nBluestein + 0.5) / Math.log(2)) / 2))]; this.w = new float[nBluestein]; int twon = 2 * nBluestein; nw = ip[0]; if (twon > (nw << 2)) { nw = twon >> 2; makewt(nw); } nc = ip[1]; if (nBluestein > (nc << 2)) { nc = nBluestein >> 2; makect(nc, w, nw); } bluesteini(); } else { plan = Plans.MIXED_RADIX; wtable = new float[4 * n + 15]; wtable_r = new float[2 * n + 15]; cffti(); rffti(); } } else { plan = Plans.SPLIT_RADIX; this.ip = new int[2 + (int) Math.ceil(2 + (1 << (int) (Math.log(n + 0.5) / Math.log(2)) / 2))]; this.w = new float[n]; int twon = 2 * n; nw = ip[0]; if (twon > (nw << 2)) { nw = twon >> 2; makewt(nw); } nc = ip[1]; if (n > (nc << 2)) { nc = n >> 2; makect(nc, w, nw); } } }
Creates new instance of FloatFFT. @param n size of data
FloatFFT::FloatFFT
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void complexForward(float[] a) { complexForward(a, 0); }
Computes 1D forward DFT of complex data leaving the result in <code>a</code>. Complex number is stored as two float values in sequence: the real and imaginary part, i.e. the size of the input array must be greater or equal 2*n. The physical layout of the input data has to be as follows:<br> <pre> a[2*k] = Re[k], a[2*k+1] = Im[k], 0&lt;=k&lt;n </pre> @param a data to transform
FloatFFT::complexForward
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void complexForward(float[] a, int offa) { if (n == 1) return; switch (plan) { case SPLIT_RADIX: cftbsub(2 * n, a, offa, ip, nw, w); break; case MIXED_RADIX: cfftf(a, offa, -1); break; case BLUESTEIN: bluestein_complex(a, offa, -1); break; } }
Computes 1D forward DFT of complex data leaving the result in <code>a</code>. Complex number is stored as two float values in sequence: the real and imaginary part, i.e. the size of the input array must be greater or equal 2*n. The physical layout of the input data has to be as follows:<br> <pre> a[offa+2*k] = Re[k], a[offa+2*k+1] = Im[k], 0&lt;=k&lt;n </pre> @param a data to transform @param offa index of the first element in array <code>a</code>
FloatFFT::complexForward
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void complexInverse(float[] a, boolean scale) { complexInverse(a, 0, scale); }
Computes 1D inverse DFT of complex data leaving the result in <code>a</code>. Complex number is stored as two float values in sequence: the real and imaginary part, i.e. the size of the input array must be greater or equal 2*n. The physical layout of the input data has to be as follows:<br> <pre> a[2*k] = Re[k], a[2*k+1] = Im[k], 0&lt;=k&lt;n </pre> @param a data to transform @param scale if true then scaling is performed
FloatFFT::complexInverse
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void complexInverse(float[] a, int offa, boolean scale) { if (n == 1) return; switch (plan) { case SPLIT_RADIX: cftfsub(2 * n, a, offa, ip, nw, w); break; case MIXED_RADIX: cfftf(a, offa, +1); break; case BLUESTEIN: bluestein_complex(a, offa, 1); break; } if (scale) { scale(n, a, offa, true); } }
Computes 1D inverse DFT of complex data leaving the result in <code>a</code>. Complex number is stored as two float values in sequence: the real and imaginary part, i.e. the size of the input array must be greater or equal 2*n. The physical layout of the input data has to be as follows:<br> <pre> a[offa+2*k] = Re[k], a[offa+2*k+1] = Im[k], 0&lt;=k&lt;n </pre> @param a data to transform @param offa index of the first element in array <code>a</code> @param scale if true then scaling is performed
FloatFFT::complexInverse
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void realForward(float[] a) { realForward(a, 0); }
Computes 1D forward DFT of real data leaving the result in <code>a</code> . The physical layout of the output data is as follows:<br> if n is even then <pre> a[2*k] = Re[k], 0&lt;=k&lt;n/2 a[2*k+1] = Im[k], 0&lt;k&lt;n/2 a[1] = Re[n/2] </pre> if n is odd then <pre> a[2*k] = Re[k], 0&lt;=k&lt;(n+1)/2 a[2*k+1] = Im[k], 0&lt;k&lt;(n-1)/2 a[1] = Im[(n-1)/2] </pre> This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real forward transform, use <code>realForwardFull</code>. To get back the original data, use <code>realInverse</code> on the output of this method. @param a data to transform
FloatFFT::realForward
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void realForward(float[] a, int offa) { if (n == 1) return; switch (plan) { case SPLIT_RADIX: float xi; if (n > 4) { cftfsub(n, a, offa, ip, nw, w); rftfsub(n, a, offa, nc, w, nw); } else if (n == 4) { cftx020(a, offa); } xi = a[offa] - a[offa + 1]; a[offa] += a[offa + 1]; a[offa + 1] = xi; break; case MIXED_RADIX: rfftf(a, offa); for (int k = n - 1; k >= 2; k--) { int idx = offa + k; float tmp = a[idx]; a[idx] = a[idx - 1]; a[idx - 1] = tmp; } break; case BLUESTEIN: bluestein_real_forward(a, offa); break; } }
Computes 1D forward DFT of real data leaving the result in <code>a</code> . The physical layout of the output data is as follows:<br> if n is even then <pre> a[offa+2*k] = Re[k], 0&lt;=k&lt;n/2 a[offa+2*k+1] = Im[k], 0&lt;k&lt;n/2 a[offa+1] = Re[n/2] </pre> if n is odd then <pre> a[offa+2*k] = Re[k], 0&lt;=k&lt;(n+1)/2 a[offa+2*k+1] = Im[k], 0&lt;k&lt;(n-1)/2 a[offa+1] = Im[(n-1)/2] </pre> This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real forward transform, use <code>realForwardFull</code>. To get back the original data, use <code>realInverse</code> on the output of this method. @param a data to transform @param offa index of the first element in array <code>a</code>
FloatFFT::realForward
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void realForwardFull(float[] a) { realForwardFull(a, 0); }
Computes 1D forward DFT of real data leaving the result in <code>a</code> . This method computes the full real forward transform, i.e. you will get the same result as from <code>complexForward</code> called with all imaginary parts equal 0. Because the result is stored in <code>a</code>, the size of the input array must greater or equal 2*n, with only the first n elements filled with real data. To get back the original data, use <code>complexInverse</code> on the output of this method. @param a data to transform
FloatFFT::realForwardFull
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void realForwardFull(final float[] a, final int offa) { final int twon = 2 * n; switch (plan) { case SPLIT_RADIX: realForward(a, offa); int nthreads = ConcurrencyUtils.getNumberOfThreads(); if ((nthreads > 1) && (n / 2 > ConcurrencyUtils.getThreadsBeginN_1D_FFT_2Threads())) { Future<?>[] futures = new Future[nthreads]; int k = n / 2 / nthreads; for (int i = 0; i < nthreads; i++) { final int firstIdx = i * k; final int lastIdx = (i == (nthreads - 1)) ? n / 2 : firstIdx + k; futures[i] = ConcurrencyUtils.submit(new Runnable() { public void run() { int idx1, idx2; for (int k = firstIdx; k < lastIdx; k++) { idx1 = 2 * k; idx2 = offa + ((twon - idx1) % twon); a[idx2] = a[offa + idx1]; a[idx2 + 1] = -a[offa + idx1 + 1]; } } }); } ConcurrencyUtils.waitForCompletion(futures); } else { int idx1, idx2; for (int k = 0; k < n / 2; k++) { idx1 = 2 * k; idx2 = offa + ((twon - idx1) % twon); a[idx2] = a[offa + idx1]; a[idx2 + 1] = -a[offa + idx1 + 1]; } } a[offa + n] = -a[offa + 1]; a[offa + 1] = 0; break; case MIXED_RADIX: rfftf(a, offa); int m; if (n % 2 == 0) { m = n / 2; } else { m = (n + 1) / 2; } for (int k = 1; k < m; k++) { int idx1 = offa + twon - 2 * k; int idx2 = offa + 2 * k; a[idx1 + 1] = -a[idx2]; a[idx1] = a[idx2 - 1]; } for (int k = 1; k < n; k++) { int idx = offa + n - k; float tmp = a[idx + 1]; a[idx + 1] = a[idx]; a[idx] = tmp; } a[offa + 1] = 0; break; case BLUESTEIN: bluestein_real_full(a, offa, -1); break; } }
Computes 1D forward DFT of real data leaving the result in <code>a</code> . This method computes the full real forward transform, i.e. you will get the same result as from <code>complexForward</code> called with all imaginary part equal 0. Because the result is stored in <code>a</code>, the size of the input array must greater or equal 2*n, with only the first n elements filled with real data. To get back the original data, use <code>complexInverse</code> on the output of this method. @param a data to transform @param offa index of the first element in array <code>a</code>
FloatFFT::realForwardFull
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0
public void realInverse(float[] a, boolean scale) { realInverse(a, 0, scale); }
Computes 1D inverse DFT of real data leaving the result in <code>a</code> . The physical layout of the input data has to be as follows:<br> if n is even then <pre> a[2*k] = Re[k], 0&lt;=k&lt;n/2 a[2*k+1] = Im[k], 0&lt;k&lt;n/2 a[1] = Re[n/2] </pre> if n is odd then <pre> a[2*k] = Re[k], 0&lt;=k&lt;(n+1)/2 a[2*k+1] = Im[k], 0&lt;k&lt;(n-1)/2 a[1] = Im[(n-1)/2] </pre> This method computes only half of the elements of the real transform. The other half satisfies the symmetry condition. If you want the full real inverse transform, use <code>realInverseFull</code>. @param a data to transform @param scale if true then scaling is performed
FloatFFT::realInverse
java
ZTFtrue/MonsterMusic
app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
https://github.com/ZTFtrue/MonsterMusic/blob/master/app/src/main/java/be/tarsos/dsp/util/fft/FloatFFT.java
Apache-2.0