Closed for maintenance

Pas d’article ces derniers jours à cause d’un plantage des serveurs toile-libre.org
Je vais devoir réfléchir à changer d’hébergement pour ce blog…
Sinon, quoi de neuf ? un bout de code pour trouver la fréquence fondamentale (f0) d’un son en Java, à un instant t :
Soit la classe FrequenciesState : un array de nombres Complexes + un entier maxFrequency == sampleRate


public static int f0 (FrequenciesState fs, int hpsfactor) {
return FrequenciesHelper
.freqFromSampleRate (FrequenciesHelper.getMaxIndex (FrequenciesHelper.hps (fs, hpsfactor), 0, fs.getState ().length / hpsfactor), fs.getState ().length * 2 / hpsfactor);

}

public static int freqFromSampleRate (int freq, int sampleRate) {
return (int) (freq * MAX_EAR_FREQUENCY / (sampleRate * 2.0));
}

public static int getMaxIndex (FrequenciesState fs, int low, int high) {
double max = 0;
int maxIndex = 0;
int reallow = low == 0 ? 1 : low;
int realhigh = Math.min (high, fs.getState ().length);
for (int i = reallow; i < realhigh; i++) { if (max < fs.getState () [i].abs ()) { max = fs.getState () [i].abs (); maxIndex = i; } } return maxIndex; } private static FrequenciesState hps (FrequenciesState fs, int factor) { int max = fs.getState ().length / factor; Complex [] result = new Complex [max]; for (int i = 0; i < max; i++) { double val = fs.getState () [i].abs (); for (int j = 1; j < factor; j++) { if (i * factor < fs.getMaxfrequency () / 2 && i * factor < fs.getState ().length) { val *= fs.getState () [i * factor].abs (); } } result [i] = new Complex (val); } return new FrequenciesState (result, fs.getMaxfrequency () / factor); }