Created
March 2, 2020 17:51
-
-
Save lukaspili/19fa0224dc7bde4dc957a2f87438841c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void run() { | |
if (stream != null) { | |
running = true; | |
try { | |
StopWatch sw = new StopWatch(); | |
sw.Start(); | |
float leqA2 = 0f; | |
float leqA = 0f; | |
arr_samples = IOStream.toFloat(stream.get(Utils.LEQ_1SEC)); | |
// KJFFT computation | |
float[] bands = kjfft.frequencyAnalyze24Bands(arr_samples, true); | |
float[] bands_cal = new float[bands.length]; | |
// Apply manual calibration for kiosk | |
if(!isSmartphone) { | |
float[] kiosk_cal = {0f, 0f, 0f, 0f, 1.6f, 4.95f, -0.35f, 4.2f, 5.8f, 1.95f, -1.55f, 3.25f, 1.5f, -1.05f, 1.15f, -2.1f, 5.45f, 10f, 1.6f, -3.1f, 2.3f, -2.6f, -4.15f, -6.25f, -9.85f}; | |
for(int i = 0; i < bands.length; i++) { | |
bands_cal[i] = bands[i]+ kiosk_cal[i]; | |
} | |
} else { | |
bands_cal = bands; | |
} | |
bands = bands_cal; | |
// A weighting calibration | |
float[] bands_A = new float[bands.length]; | |
float[] Aweighting = {-30.2f, -26.2f, -22.5f, -19.1f, -16.1f, -13.4f, -10.9f, -8.6f, -6.6f, -4.8f, -3.2f, -1.9f, -0.8f, 0f, 0.6f, 1f, 1.2f, 1.3f, 1.2f, 1f, 0.5f, -0.1f, -1.1f, -2.5f, -4.3f}; | |
for (int i = 0; i < bands.length; i++) { | |
bands_A[i] = bands_cal[i] + Aweighting[i]; | |
} | |
// calculate overall 1sec dBA value based on the sum of third octave band values | |
for (int i = 0; i < bands.length; i++) { | |
leqA2 += (float) Math.pow(10, (bands_A[i]) / 10); | |
} | |
leqA = (float) (10 * Math.log10(leqA2)); | |
//round 1 decimal place | |
int aux = (int) (leqA * 10); | |
leqA = aux / 10f; | |
if(isSmartphone) { | |
leqA = leqA + smartphoneCalibrationDelta; | |
} else { | |
leqA = leqA + 23.3f; | |
} | |
// Calculate the global LEQ ( averaged over the duration of the measurements | |
// calculate from the global Leq and the last Leq | |
allLEQAcals.add(leqA); | |
currentLEQAcal = (float) (10F * Math.log10((((allLEQAcals.size() - 1) * Math.pow(10, (currentLEQAcal / 10))) + Math.pow(10, (allLEQAcals.lastElement() / 10))) / allLEQAcals.size())); | |
// Log.i("SoundManager", "LEQA calibrated : " + leqAcal); | |
// Log.i("SoundManager", "bande 0 : " + bands[0] ); | |
// Log.i("SoundManager", "bande 1 : " + bands[1] ); | |
// Log.i("SoundManager", "bande 2 : " + bands[2] ); | |
// Log.i("SoundManager", "bande 3 : " + bands[3] ); | |
// Log.i("SoundManager", "bande 4 : " + bands[4] ); | |
// Log.i("SoundManager", "bande 5 : " + bands[5] ); | |
// Log.i("SoundManager", "bande 6 : " + bands[6] ); | |
// Log.i("SoundManager", "bande 7 : " + bands[7] ); | |
// Log.i("SoundManager", "bande 8 : " + bands[8] ); | |
// Log.i("SoundManager", "bande 9 : " + bands[9] ); | |
// Log.i("SoundManager", "bande 10 : " + bands[10] ); | |
// Log.i("SoundManager", "bande 11 : " + bands[11] ); | |
// Log.i("SoundManager", "bande 12 : " + bands[12] ); | |
// Log.i("SoundManager", "bande 13 : " + bands[13] ); | |
// Log.i("SoundManager", "bande 14 : " + bands[14] ); | |
// Log.i("SoundManager", "bande 15 : " + bands[15] ); | |
// Log.i("SoundManager", "bande 16 : " + bands[16] ); | |
// Log.i("SoundManager", "bande 17 : " + bands[17] ); | |
// Log.i("SoundManager", "bande 18 : " + bands[18] ); | |
// Log.i("SoundManager", "bande 19 : " + bands[19] ); | |
// Log.i("SoundManager", "bande 20 : " + bands[20] ); | |
// Log.i("SoundManager", "bande 21 : " + bands[21] ); | |
// Log.i("SoundManager", "bande 22 : " + bands[22] ); | |
// Log.i("SoundManager", "bande 23 : " + bands[23] ); | |
// Log.i("SoundManager", "overall LeqA : " + currentLEQAcal); | |
// Log.i("SoundManager", "Leq 1sec : " + leqA); | |
listener.onReceived(leqA, currentLEQAcal); | |
long t1 = sw.Stop(); | |
// Log.v("SoundManager", "duree de traitement : " + t1); | |
running = false; | |
System.gc(); | |
} catch (Exception e) { | |
running = false; | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment