Encode a block of data. Throws IllegalArgumentException when parameters are wrong. When the encoded array is too small, an ArrayIndexOutOfBoundsException is thrown. length should be the value returned by getPCMBufferSize. @return the number of bytes written to encode
(byte[] pcm, int offset, int length, byte[] encoded)
| 459 | * @return the number of bytes written to <code>encoded</code>. May be 0. |
| 460 | */ |
| 461 | public int encodeBuffer(byte[] pcm, int offset, int length, byte[] encoded) |
| 462 | throws ArrayIndexOutOfBoundsException { |
| 463 | if (length < 0 || (offset + length) > pcm.length) { |
| 464 | throw new IllegalArgumentException("inconsistent parameters"); |
| 465 | } |
| 466 | int result = doEncodeBuffer(pcm, offset, length, encoded); |
| 467 | if (result < 0) { |
| 468 | if (result == -1) { |
| 469 | throw new ArrayIndexOutOfBoundsException( |
| 470 | "Encode buffer too small"); |
| 471 | } |
| 472 | throw new RuntimeException("crucial error in encodeBuffer."); |
| 473 | } |
| 474 | return result; |
| 475 | } |
| 476 | |
| 477 | public int encodeFinish(byte[] encoded) { |
| 478 | return lame.lame_encode_flush(gfp, encoded, 0, encoded.length); |
no test coverage detected