package party.bami.eqfix.analysis;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;

import java.util.Random;

public class WhiteNoise {
    /**
     * Generates white and returns it as a float array.
     * @param nSamp The number of white noise samples in the PCM.
     * @return The white noise PCM.
     */
    static public float[] gen(int nSamp) {
        float[] rndPCM = new float[nSamp];
        Random rand = new Random();

        for (int i = 0; i < nSamp; i++) {
            float r1 = rand.nextFloat();
            float r2 = rand.nextFloat();
            rndPCM[i] = (float) (Math.pow((-2 * Math.log(r1)), 0.5) * Math.cos(2 * Math.PI * r2));
        }

        return rndPCM;
    }
}
