1 /*
2 * Copyright (c) 1999, 2016, 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
146 // HELPER METHODS
147
148 /**
149 * Closes the InputStream when we have read all necessary data from it, and
150 * ignores an IOException.
151 *
152 * @param is the InputStream which should be closed
153 */
154 private static void closeSilently(final InputStream is) {
155 try {
156 is.close();
157 } catch (final IOException ignored) {
158 // IOException is ignored
159 }
160 }
161
162 /**
163 * rllong
164 * Protected helper method to read 64 bits and changing the order of
165 * each bytes.
166 * @param DataInputStream
167 * @return 32 bits swapped value.
168 * @exception IOException
169 */
170 final int rllong(DataInputStream dis) throws IOException {
171
172 int b1, b2, b3, b4 ;
173 int i = 0;
174
175 i = dis.readInt();
176
177 b1 = ( i & 0xFF ) << 24 ;
178 b2 = ( i & 0xFF00 ) << 8;
179 b3 = ( i & 0xFF0000 ) >> 8;
180 b4 = ( i & 0xFF000000 ) >>> 24;
181
182 i = ( b1 | b2 | b3 | b4 );
183
184 return i;
185 }
186
187 /**
188 * big2little
189 * Protected helper method to swap the order of bytes in a 32 bit int
190 * @param int
191 * @return 32 bits swapped value
192 */
193 final int big2little(int i) {
194
195 int b1, b2, b3, b4 ;
196
197 b1 = ( i & 0xFF ) << 24 ;
198 b2 = ( i & 0xFF00 ) << 8;
199 b3 = ( i & 0xFF0000 ) >> 8;
200 b4 = ( i & 0xFF000000 ) >>> 24;
201
202 i = ( b1 | b2 | b3 | b4 );
203
204 return i;
205 }
206
207 /**
208 * rlshort
209 * Protected helper method to read 16 bits value. Swap high with low byte.
210 * @param DataInputStream
211 * @return the swapped value.
212 * @exception IOException
213 */
214 final short rlshort(DataInputStream dis) throws IOException {
215
216 short s=0;
217 short high, low;
218
219 s = dis.readShort();
220
221 high = (short)(( s & 0xFF ) << 8) ;
222 low = (short)(( s & 0xFF00 ) >>> 8);
223
224 s = (short)( high | low );
225
226 return s;
227 }
228
229 /**
230 * big2little
231 * Protected helper method to swap the order of bytes in a 16 bit short
232 * @param int
233 * @return 16 bits swapped value
234 */
235 final short big2littleShort(short i) {
236
237 short high, low;
238
239 high = (short)(( i & 0xFF ) << 8) ;
240 low = (short)(( i & 0xFF00 ) >>> 8);
241
242 i = (short)( high | low );
243
244 return i;
245 }
246
247 /** Calculates the frame size for PCM frames.
248 * Note that this method is appropriate for non-packed samples.
249 * For instance, 12 bit, 2 channels will return 4 bytes, not 3.
250 * @param sampleSizeInBits the size of a single sample in bits
251 * @param channels the number of channels
252 * @return the size of a PCM frame in bytes.
|
1 /*
2 * Copyright (c) 1999, 2017, 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
146 // HELPER METHODS
147
148 /**
149 * Closes the InputStream when we have read all necessary data from it, and
150 * ignores an IOException.
151 *
152 * @param is the InputStream which should be closed
153 */
154 private static void closeSilently(final InputStream is) {
155 try {
156 is.close();
157 } catch (final IOException ignored) {
158 // IOException is ignored
159 }
160 }
161
162 /**
163 * rllong
164 * Protected helper method to read 64 bits and changing the order of
165 * each bytes.
166 * @return 32 bits swapped value.
167 * @exception IOException
168 */
169 final int rllong(DataInputStream dis) throws IOException {
170
171 int b1, b2, b3, b4 ;
172 int i = 0;
173
174 i = dis.readInt();
175
176 b1 = ( i & 0xFF ) << 24 ;
177 b2 = ( i & 0xFF00 ) << 8;
178 b3 = ( i & 0xFF0000 ) >> 8;
179 b4 = ( i & 0xFF000000 ) >>> 24;
180
181 i = ( b1 | b2 | b3 | b4 );
182
183 return i;
184 }
185
186 /**
187 * big2little
188 * Protected helper method to swap the order of bytes in a 32 bit int
189 * @return 32 bits swapped value
190 */
191 final int big2little(int i) {
192
193 int b1, b2, b3, b4 ;
194
195 b1 = ( i & 0xFF ) << 24 ;
196 b2 = ( i & 0xFF00 ) << 8;
197 b3 = ( i & 0xFF0000 ) >> 8;
198 b4 = ( i & 0xFF000000 ) >>> 24;
199
200 i = ( b1 | b2 | b3 | b4 );
201
202 return i;
203 }
204
205 /**
206 * rlshort
207 * Protected helper method to read 16 bits value. Swap high with low byte.
208 * @return the swapped value.
209 * @exception IOException
210 */
211 final short rlshort(DataInputStream dis) throws IOException {
212
213 short s=0;
214 short high, low;
215
216 s = dis.readShort();
217
218 high = (short)(( s & 0xFF ) << 8) ;
219 low = (short)(( s & 0xFF00 ) >>> 8);
220
221 s = (short)( high | low );
222
223 return s;
224 }
225
226 /**
227 * big2little
228 * Protected helper method to swap the order of bytes in a 16 bit short
229 * @return 16 bits swapped value
230 */
231 final short big2littleShort(short i) {
232
233 short high, low;
234
235 high = (short)(( i & 0xFF ) << 8) ;
236 low = (short)(( i & 0xFF00 ) >>> 8);
237
238 i = (short)( high | low );
239
240 return i;
241 }
242
243 /** Calculates the frame size for PCM frames.
244 * Note that this method is appropriate for non-packed samples.
245 * For instance, 12 bit, 2 channels will return 4 bytes, not 3.
246 * @param sampleSizeInBits the size of a single sample in bits
247 * @param channels the number of channels
248 * @return the size of a PCM frame in bytes.
|