Created
May 9, 2016 21:52
-
-
Save benmargolin/5089a37d3eaf4d5c1192e3ceb8d7500c to your computer and use it in GitHub Desktop.
Take the average value of part of a ByteBuffer (that is actually 16 bit little endian) easily
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
// posBefore = where in the mBuffer the new data started (before put) | |
ShortBuffer avgBuf = ((ByteBuffer) mBuffer.duplicate().flip().position(posBefore)) | |
.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); | |
long total = 0; | |
while (avgBuf.remaining() > 0) { | |
total += avgBuf.get() & 0xffff; // Because unsigned. | |
} | |
sLastDataAverage = total / numOfBytes / 2 / 65535f; | |
Logger.v(TAG, "Analysis of audio data: avg = %f", sLastDataAverage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment