844429 wrote:
..And i would like to know how to show the volume from a recording in real time..
It can never be truly 'real time' since the calculations require a 'chunk' of sound samples to produce a value. The shorter the chunk, the more arbitrary the value, but the more 'real time' it seems.
..in a meter? I allready have the meter..
(chuckle) That is the
easy part.
..but now i don´t know how to pass the volume and show in the meter.
In what units? dB, RMS, tuna? I did an RMS calculation for the left/right channels of a more complex audio trace. RMS is relatively easy to calculate. E.G.
/** Computes the RMS volume of a group of signal sizes ranging from -1 to 1. */
public double volumeRMS(double[] raw) {
double sum = 0d;
if (raw.length==0) {
return sum;
} else {
for (int ii=0; ii<raw.length; ii++) {
sum += raw[ii];
}
}
double average = sum/raw.length;
double[] meanSquare = new double[raw.length];
double sumMeanSquare = 0d;
for (int ii=0; ii<raw.length; ii++) {
sumMeanSquare += Math.pow(raw[ii]-average,2d);
meanSquare[ii] = sumMeanSquare;
}
double averageMeanSquare = sumMeanSquare/raw.length;
double rootMeanSquare = Math.pow(averageMeanSquare,0.5d);
return rootMeanSquare;
}
Of course, you will need to get directly into the sound data streams then convert the signal to PCM, split the channels and scale the values to a range of -1 to 1 to use that
exact method shown. ;)