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
23 * questions.
24 */
25
26 package com.sun.media.sound;
27
28 import java.io.IOException;
29 import java.util.Vector;
30
31 import javax.sound.sampled.AudioFormat;
32 import javax.sound.sampled.AudioInputStream;
33 import javax.sound.sampled.AudioSystem;
34
35
36 /**
37 * Converts among signed/unsigned and little/big endianness of sampled.
38 *
39 * @author Jan Borgersen
40 */
41 public final class PCMtoPCMCodec extends SunCodec {
42
43
44 private static final AudioFormat.Encoding[] inputEncodings = {
45 AudioFormat.Encoding.PCM_SIGNED,
46 AudioFormat.Encoding.PCM_UNSIGNED,
47 };
48
70 /**
71 */
72 public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat){
73
74 if( sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED ) ||
75 sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_UNSIGNED ) ) {
76
77 AudioFormat.Encoding encs[] = new AudioFormat.Encoding[2];
78 encs[0] = AudioFormat.Encoding.PCM_SIGNED;
79 encs[1] = AudioFormat.Encoding.PCM_UNSIGNED;
80 return encs;
81 } else {
82 return new AudioFormat.Encoding[0];
83 }
84 }
85
86
87 /**
88 */
89 public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
90
91 // filter out targetEncoding from the old getOutputFormats( sourceFormat ) method
92
93 AudioFormat[] formats = getOutputFormats( sourceFormat );
94 Vector<AudioFormat> newFormats = new Vector<>();
95 for(int i=0; i<formats.length; i++ ) {
96 if( formats[i].getEncoding().equals( targetEncoding ) ) {
97 newFormats.addElement( formats[i] );
98 }
99 }
100
101 AudioFormat[] formatArray = new AudioFormat[newFormats.size()];
102
103 for (int i = 0; i < formatArray.length; i++) {
104 formatArray[i] = newFormats.elementAt(i);
105 }
106
107 return formatArray;
108 }
109
|
1 /*
2 * Copyright (c) 1999, 2015, 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
23 * questions.
24 */
25
26 package com.sun.media.sound;
27
28 import java.io.IOException;
29 import java.util.Objects;
30 import java.util.Vector;
31
32 import javax.sound.sampled.AudioFormat;
33 import javax.sound.sampled.AudioInputStream;
34 import javax.sound.sampled.AudioSystem;
35
36
37 /**
38 * Converts among signed/unsigned and little/big endianness of sampled.
39 *
40 * @author Jan Borgersen
41 */
42 public final class PCMtoPCMCodec extends SunCodec {
43
44
45 private static final AudioFormat.Encoding[] inputEncodings = {
46 AudioFormat.Encoding.PCM_SIGNED,
47 AudioFormat.Encoding.PCM_UNSIGNED,
48 };
49
71 /**
72 */
73 public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat){
74
75 if( sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_SIGNED ) ||
76 sourceFormat.getEncoding().equals( AudioFormat.Encoding.PCM_UNSIGNED ) ) {
77
78 AudioFormat.Encoding encs[] = new AudioFormat.Encoding[2];
79 encs[0] = AudioFormat.Encoding.PCM_SIGNED;
80 encs[1] = AudioFormat.Encoding.PCM_UNSIGNED;
81 return encs;
82 } else {
83 return new AudioFormat.Encoding[0];
84 }
85 }
86
87
88 /**
89 */
90 public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
91 Objects.requireNonNull(targetEncoding);
92
93 // filter out targetEncoding from the old getOutputFormats( sourceFormat ) method
94
95 AudioFormat[] formats = getOutputFormats( sourceFormat );
96 Vector<AudioFormat> newFormats = new Vector<>();
97 for(int i=0; i<formats.length; i++ ) {
98 if( formats[i].getEncoding().equals( targetEncoding ) ) {
99 newFormats.addElement( formats[i] );
100 }
101 }
102
103 AudioFormat[] formatArray = new AudioFormat[newFormats.size()];
104
105 for (int i = 0; i < formatArray.length; i++) {
106 formatArray[i] = newFormats.elementAt(i);
107 }
108
109 return formatArray;
110 }
111
|