(byte[] pcm, int offset, int length, byte[] encoded)
| 365 | } |
| 366 | |
| 367 | private int doEncodeBuffer(byte[] pcm, int offset, int length, byte[] encoded) { |
| 368 | int bytes_per_sample = sourceSampleSizeInBits >> 3; |
| 369 | int samples_read = length / bytes_per_sample; |
| 370 | |
| 371 | |
| 372 | |
| 373 | int[] sample_buffer = new int[samples_read]; |
| 374 | |
| 375 | int sample_index = samples_read; |
| 376 | if (!sourceEncoding.toString().equals("PCM_FLOAT")){ |
| 377 | if (sourceByteOrder == ByteOrder.LITTLE_ENDIAN) { |
| 378 | if (bytes_per_sample == 1) |
| 379 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 380 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) << 24; |
| 381 | if (bytes_per_sample == 2) |
| 382 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 383 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) << 16 |
| 384 | | (pcm[offset + i + 1] & 0xff) << 24; |
| 385 | if (bytes_per_sample == 3) |
| 386 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 387 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) << 8 |
| 388 | | (pcm[offset + i + 1] & 0xff) << 16 |
| 389 | | (pcm[offset + i + 2] & 0xff) << 24; |
| 390 | if (bytes_per_sample == 4) |
| 391 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 392 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) |
| 393 | | (pcm[offset + i + 1] & 0xff) << 8 |
| 394 | | (pcm[offset + i + 2] & 0xff) << 16 |
| 395 | | (pcm[offset + i + 3] & 0xff) << 24; |
| 396 | } else { |
| 397 | if (bytes_per_sample == 1) |
| 398 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 399 | sample_buffer[--sample_index] = ((pcm[offset + i] & 0xff) ^ 0x80) << 24 |
| 400 | | 0x7f << 16; |
| 401 | if (bytes_per_sample == 2) |
| 402 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 403 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) << 24 |
| 404 | | (pcm[offset + i + 1] & 0xff) << 16; |
| 405 | if (bytes_per_sample == 3) |
| 406 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 407 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) << 24 |
| 408 | | (pcm[offset + i + 1] & 0xff) << 16 |
| 409 | | (pcm[offset + i + 2] & 0xff) << 8; |
| 410 | if (bytes_per_sample == 4) |
| 411 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;) |
| 412 | sample_buffer[--sample_index] = (pcm[offset + i] & 0xff) << 24 |
| 413 | | (pcm[offset + i + 1] & 0xff) << 16 |
| 414 | | (pcm[offset + i + 2] & 0xff) << 8 |
| 415 | | (pcm[offset + i + 3] & 0xff); |
| 416 | } |
| 417 | } else { |
| 418 | if (bytes_per_sample == 4) |
| 419 | for (int i = samples_read * bytes_per_sample; (i -= bytes_per_sample) >= 0;){ |
| 420 | byte[] sample = new byte[4]; |
| 421 | sample[0] = pcm [offset + i]; |
| 422 | sample[1] = pcm [offset + i + 1]; |
| 423 | sample[2] = pcm [offset + i + 2]; |
| 424 | sample[3] = pcm [offset + i + 3]; |
no test coverage detected