DCoder
DCoder

Reputation: 3488

How to extract amplitude from byte array in android?

I am recording sound from mic using audio recorder. recoChunk byte[] store raw recording as shown below.

while (isRecording == true) {
    Log.w("myMsg", "recording..");
    recoChunk = new byte[minBuffSize];
    audioRecord.read(recoChunk, 0, minBuffSize);
    mFosRaw.write(recoChunk);
}

now from recoChunk I want to find largest amplitude recorded how can I do that?

Upvotes: 1

Views: 1775

Answers (1)

agunal
agunal

Reputation: 508

You can cast your byte array to an array of a type that matches the bit-depth of your recorded audio in its size. For example for 16-bit audio, you can use short, since it holds a 16-bit signed integer value. For 8-bit you can just use the byte array without casting. Then, simply, the largest "number" in the array (you would probably want to take the absolute value) will be the sample with the highest amplitude value.

Upvotes: 7

Related Questions