improved sample helper (normalization is now possible)
This commit is contained in:
parent
153452d10e
commit
a9ffb6b044
@ -100,11 +100,31 @@ public class SampleHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SampleBuffer from the data provided by the given decoder.
|
* Creates a SampleBuffer from the data provided by the given decoder.
|
||||||
*
|
*
|
||||||
* @param deocder The decoder to read from
|
* @param deocder The decoder to read from
|
||||||
* @returns The new SampleBuffer
|
* @returns The new SampleBuffer
|
||||||
*/
|
*/
|
||||||
public static SampleBuffer createSampleBuffer(Decoder decoder) {
|
public static SampleBuffer createSampleBuffer(Decoder decoder) {
|
||||||
return new SampleBuffer(readAllSamples(decoder), decoder.getSamplingRate());
|
return new SampleBuffer(readAllSamples(decoder), decoder.getSamplingRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes a given float array.
|
||||||
|
*
|
||||||
|
* @param data The float array to normalize
|
||||||
|
* @param lowScale The lower bound of the normalized array
|
||||||
|
* @param highScale The higher bound of the normalized array
|
||||||
|
*/
|
||||||
|
public static void normalize(float[] data, float lowScale, float highScale) {
|
||||||
|
float minValue = Float.MAX_VALUE;
|
||||||
|
float maxValue = Float.MIN_VALUE;
|
||||||
|
for (float f : data) {
|
||||||
|
minValue = Math.min(minValue, f);
|
||||||
|
maxValue = Math.max(maxValue, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
|
data[i] = lowScale + (data[i] - minValue) * (highScale - lowScale) / (maxValue - minValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user