AudioRecord extract amplitude from ShortArray

81 Views Asked by At

I'm using

val data = ShortArray(minBuffer)
audioRecord.read(data, 0, minBuffer)

I have seen few solutions of how to extract amplitude from ByteArray, but how to do it with ShortArray?

1

There are 1 best solutions below

1
Pavel Poley On
var sum = 0L
for (i in 0 until minBufferSize step 2) {
  sum += abs(data[i].toInt())
}

amplitude = (sum / (minBufferSize / 8)).toInt()