1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
284 decodeFormat = inputFormat;
285 PCMIsBigEndian = inputFormat.isBigEndian();
286 tempBuffer = new byte[tempBufferSize];
287 }
288
289 // setup tables according to byte order
290 if (PCMIsBigEndian) {
291 tabByte1 = ULAW_TABH;
292 tabByte2 = ULAW_TABL;
293 highByte = 0;
294 lowByte = 1;
295 } else {
296 tabByte1 = ULAW_TABL;
297 tabByte2 = ULAW_TABH;
298 highByte = 1;
299 lowByte = 0;
300 }
301
302 // set the AudioInputStream length in frames if we know it
303 if (stream instanceof AudioInputStream) {
304 frameLength = ((AudioInputStream)stream).getFrameLength();
305 }
306 // set framePos to zero
307 framePos = 0;
308 frameSize = inputFormat.getFrameSize();
309 if (frameSize == AudioSystem.NOT_SPECIFIED) {
310 frameSize = 1;
311 }
312 }
313
314
315 /*
316 * $$jb 2/23/99
317 * Used to determine segment number in uLaw encoding
318 */
319 private short search(short val, short table[], short size) {
320 for(short i = 0; i < size; i++) {
321 if (val <= table[i]) { return i; }
322 }
323 return size;
324 }
389 currentPos++;
390 }
391 /* And update pointers and counters for next iteration */
392 readLeft -= readCount;
393 readLen = ( (readLeft>tempBufferSize) ? tempBufferSize : readLeft );
394 }
395 if( currentPos==off && readCount<0 ) { // EOF or error on read
396 return readCount;
397 }
398 return (currentPos - off); /* Number of bytes written to new buffer */
399 } else {
400 int i;
401 int readLen = len/2;
402 int readOffset = off + len/2;
403 int readCount = super.read(b, readOffset, readLen);
404
405 if(readCount<0) { // EOF or error
406 return readCount;
407 }
408 for (i = off; i < (off + (readCount*2)); i+=2) {
409 b[i] = (byte)tabByte1[b[readOffset] & 0xFF];
410 b[i+1] = (byte)tabByte2[b[readOffset] & 0xFF];
411 readOffset++;
412 }
413 return (i - off);
414 }
415 }
416 } // end class UlawCodecStream
417
418 } // end class ULAW
|
1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
284 decodeFormat = inputFormat;
285 PCMIsBigEndian = inputFormat.isBigEndian();
286 tempBuffer = new byte[tempBufferSize];
287 }
288
289 // setup tables according to byte order
290 if (PCMIsBigEndian) {
291 tabByte1 = ULAW_TABH;
292 tabByte2 = ULAW_TABL;
293 highByte = 0;
294 lowByte = 1;
295 } else {
296 tabByte1 = ULAW_TABL;
297 tabByte2 = ULAW_TABH;
298 highByte = 1;
299 lowByte = 0;
300 }
301
302 // set the AudioInputStream length in frames if we know it
303 if (stream instanceof AudioInputStream) {
304 frameLength = stream.getFrameLength();
305 }
306 // set framePos to zero
307 framePos = 0;
308 frameSize = inputFormat.getFrameSize();
309 if (frameSize == AudioSystem.NOT_SPECIFIED) {
310 frameSize = 1;
311 }
312 }
313
314
315 /*
316 * $$jb 2/23/99
317 * Used to determine segment number in uLaw encoding
318 */
319 private short search(short val, short table[], short size) {
320 for(short i = 0; i < size; i++) {
321 if (val <= table[i]) { return i; }
322 }
323 return size;
324 }
389 currentPos++;
390 }
391 /* And update pointers and counters for next iteration */
392 readLeft -= readCount;
393 readLen = ( (readLeft>tempBufferSize) ? tempBufferSize : readLeft );
394 }
395 if( currentPos==off && readCount<0 ) { // EOF or error on read
396 return readCount;
397 }
398 return (currentPos - off); /* Number of bytes written to new buffer */
399 } else {
400 int i;
401 int readLen = len/2;
402 int readOffset = off + len/2;
403 int readCount = super.read(b, readOffset, readLen);
404
405 if(readCount<0) { // EOF or error
406 return readCount;
407 }
408 for (i = off; i < (off + (readCount*2)); i+=2) {
409 b[i] = tabByte1[b[readOffset] & 0xFF];
410 b[i+1] = tabByte2[b[readOffset] & 0xFF];
411 readOffset++;
412 }
413 return (i - off);
414 }
415 }
416 } // end class UlawCodecStream
417
418 } // end class ULAW
|