private float[] calculateLogAverages(float[] freqs) { var realWidth = this.formWidth / this.pixelsPerLine; const int shift = 0; var width = realWidth + shift;// width used to ignore low frequences int samples = freqs.Length; var averages = new WeightedAverage(realWidth); float logRatio = width / (float)Math.Log(samples, 2); for (int i = 1; i < samples; i++) { float freq = i; float amp = freqs[i]; float logFreq = (float)Math.Log(i, 2); int newIndex = (int)(logFreq * logRatio) - shift; if (newIndex >= 0) { averages.Add(newIndex, amp); } } return(averages.GetAverges()); }
private float[] calculateBands(float[] freqs) { /** * Source https://youtu.be/mHk3ZiKNH48 * 7 hz Bands * 20-60 * 60-250 * 250-500 * 500-2k * 2k-4k * 4k-6k * 6k-11k * 11k-20k * * 4000 samples between 20hz - 20khz * ~ 1 samples every 5hz * * use https://www.szynalski.com/tone-generator/ * for testing * * * * Bands From HeadPhone software * 32 * 64 * 128 * 250 * 500 * 1000 * 2000 * 4000 * 8000 * 16000 * * using above as mid points * * 0= 0-48hz * 1= 48-96hz * 2= 96-.. * 3= 192 * 4= 384 * 5= 768 * 6= 1536 * 7= 3072 * 8= 6144 * 9= 12288 * * can use powers of 2 times 1.5 * 2^n * 1.5 * eg 2^5 * 1.5 = 48 */ const int bandCount = 10; int samples = freqs.Length; var averages = new WeightedAverage(bandCount) { squareValues = true }; const int startPower = 5; var bandThresholds = new float[bandCount]; for (int n = 0; n < bandCount; n++) { var max = (float)Math.Pow(2, n + startPower) * 1.5f; bandThresholds[n] = max; } float ratio = 20000f / samples; for (int i = 1; i < samples; i++) { float freq = i * ratio; float amp = freqs[i]; findBand(averages, bandThresholds, freq, amp); } return(averages.GetAverges()); }