I am trying to obtain and represent the SPL of a a wav file previously recorded with the internal mic of my device. The problem is that the values that I am getting seem not to be logic at all, as I´m getting values over 100 db simply clapping my hands as you can see here:
(source: subirimagenes.com)
This is what I am doing:
- First of all, as the wav file is saved in 16-bit PCM, I operate with its bytes to have an unique double value normalized between [-1,1] ( I don´t operate with the first 44 bytes as it is the wav header).
- Then, following this equation SPL=10*log(audioSample/Iref) I obtain each of the desired sound levels (being Iref=10^-12).
- At the end I calculate the max and min values to set the margins of the plot.
Do you guys know what Im I doing wrong? I think the values should be around half of the ones obtained
Here is the piece of code:
protected void miThread() {
Thread t=new Thread() {
public void run(){
//Operaciones ope=new Operaciones();
double [] st =new double [arr.length];
int j=0;
try{
for (int i = 44; i < s; i+=2) {
// convert byte pair to int
double audioSample = (double) (array[i+1] << 8 | array[i] & 0xff)/ 32767.0;
arr[j]=audioSample; //double
n[j] = (Number)arr[j]; //Number
st[j]=10*Math.log10(Math.abs((audioSample/Math.pow(10, -12)))); //double
l[j]=(Number)(10*Math.log10(Math.abs((audioSample/Math.pow(10, -12))))); //Number
if(audioSample == 0.0 ){
if(j!=0){
l[j]=l[j-1];
st[j]=st[j-1];
}else{
l[j]=0.0;
st[j]=0.0;
}
}
j=j+1;}
min=Operaciones.minimum(arr);
max=Operaciones.maximum(arr);
min2=Operaciones.minimum(st);
max2=Operaciones.maximum(st);
}
catch (NullPointerException e){
e.printStackTrace();
}
handle.post(proceso);
} }; t.start();
}
final Runnable proceso=new Runnable(){
public void run(){
//plot.redraw();
//plot2.redraw();
Toast.makeText(Grafica.this,
"Ya se ha cargado todo el array", Toast.LENGTH_LONG).show();
}
};