http://en.wikipedia.org/wiki/Root_mean_square
Sample Code
protected void updateLevelAndPeak(ByteBuffer bytebuffer, int bufferLen) { int numFrame = bufferLen / frameSizeInBytes; long sampleSqureTotal = 0L; long peak = 0L; ShortBuffer shortbuffer = bytebuffer.asShortBuffer(); for (int indexFrame = 0; indexFrame < numFrame; indexFrame++) { int sampleValue = 0; for (int indexChannel = 0; indexChannel < channels; indexChannel++) { sampleValue += shortbuffer.get(channels * indexFrame + indexChannel); } sampleValue /= channels; int k = Math.abs(sampleValue); sampleSqureTotal += sampleValue * sampleValue; if ((long) k > peak) { peak = k; } } currentLevel = numFrame <= 0 ? 0.0D : Math.sqrt(sampleSqureTotal / (long) numFrame); currentPeak = peak; }
Reference:
http://wiki.hydrogenaudio.org/index.php?title=Replaygain
No comments:
Post a Comment