summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/share/sampled/AudioFormats.java
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-07-11 15:42:37 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-07-11 15:42:37 +0000
commit9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e (patch)
tree4c304cd4151020bd5494d279ee68a105ae3a5a3a /songdbj/org/tritonus/share/sampled/AudioFormats.java
parentdfa8ecbe609ca8ea194d08560a44fb9a92e94b4b (diff)
downloadrockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.tar.gz
rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.zip
Songdb java version, source. only 1.5 compatible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/org/tritonus/share/sampled/AudioFormats.java')
-rw-r--r--songdbj/org/tritonus/share/sampled/AudioFormats.java131
1 files changed, 131 insertions, 0 deletions
diff --git a/songdbj/org/tritonus/share/sampled/AudioFormats.java b/songdbj/org/tritonus/share/sampled/AudioFormats.java
new file mode 100644
index 0000000000..41ac3f37c7
--- /dev/null
+++ b/songdbj/org/tritonus/share/sampled/AudioFormats.java
@@ -0,0 +1,131 @@
1/*
2 * AudioFormats.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 1999,2000 by Matthias Pfisterer
9 * Copyright (c) 1999 by Florian Bomers <http://www.bomers.de>
10 *
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as published
14 * by the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28/*
29|<--- this code is formatted to fit into 80 columns --->|
30*/
31
32package org.tritonus.share.sampled;
33
34import javax.sound.sampled.AudioFormat;
35import javax.sound.sampled.AudioSystem;
36
37
38
39public class AudioFormats
40{
41 private static boolean doMatch(int i1, int i2)
42 {
43 return i1 == AudioSystem.NOT_SPECIFIED
44 || i2 == AudioSystem.NOT_SPECIFIED
45 || i1 == i2;
46 }
47
48
49
50 private static boolean doMatch(float f1, float f2)
51 {
52 return f1 == AudioSystem.NOT_SPECIFIED
53 || f2 == AudioSystem.NOT_SPECIFIED
54 || Math.abs(f1 - f2) < 1.0e-9;
55 }
56
57
58
59 /**
60 * Tests whether 2 AudioFormats have matching formats.
61 * A field matches when it is AudioSystem.NOT_SPECIFIED in
62 * at least one of the formats or the field is the same
63 * in both formats.<br>
64 * Exceptions:
65 * <ul>
66 * <li>Encoding must always be equal for a match.
67 * <li> For a match, endianness must be equal if SampleSizeInBits is not
68 * AudioSystem.NOT_SPECIFIED and greater than 8bit in both formats.<br>
69 * In other words: If SampleSizeInBits is AudioSystem.NOT_SPECIFIED
70 * in either format or both formats have a SampleSizeInBits<8,
71 * endianness does not matter.
72 * </ul>
73 * This is a proposition to be used as AudioFormat.matches.
74 * It can therefore be considered as a temporary workaround.
75 */
76 // IDEA: create a special "NOT_SPECIFIED" encoding
77 // and a AudioFormat.Encoding.matches method.
78 public static boolean matches(AudioFormat format1,
79 AudioFormat format2)
80 {
81 //$$fb 19 Dec 99: endian must be checked, too.
82 //
83 // we do have a problem with redundant elements:
84 // e.g.
85 // encoding=ALAW || ULAW -> bigEndian and samplesizeinbits don't matter
86 // sample size in bits == 8 -> bigEndian doesn't matter
87 // sample size in bits > 8 -> PCM is always signed.
88 // This is an overall issue in JavaSound, I think.
89 // At present, it is not consistently implemented to support these
90 // redundancies and implicit definitions
91 //
92 // As a workaround of this issue I return in the converters
93 // all combinations, e.g. for ULAW I return bigEndian and !bigEndian formats.
94/* old version
95*/
96 // as proposed by florian
97 return format1.getEncoding().equals(format2.getEncoding())
98 && (format2.getSampleSizeInBits()<=8
99 || format1.getSampleSizeInBits()==AudioSystem.NOT_SPECIFIED
100 || format2.getSampleSizeInBits()==AudioSystem.NOT_SPECIFIED
101 || format1.isBigEndian()==format2.isBigEndian())
102 && doMatch(format1.getChannels(),format2.getChannels())
103 && doMatch(format1.getSampleSizeInBits(), format2.getSampleSizeInBits())
104 && doMatch(format1.getFrameSize(), format2.getFrameSize())
105 && doMatch(format1.getSampleRate(), format2.getSampleRate())
106 && doMatch(format1.getFrameRate(),format2.getFrameRate());
107 }
108
109 /**
110 * Tests for exact equality of 2 AudioFormats.
111 * This is the behaviour of AudioFormat.matches in JavaSound 1.0.
112 * <p>
113 * This is a proposition to be used as AudioFormat.equals.
114 * It can therefore be considered as a temporary workaround.
115 */
116 public static boolean equals(AudioFormat format1,
117 AudioFormat format2)
118 {
119 return format1.getEncoding().equals(format2.getEncoding())
120 && format1.getChannels() == format2.getChannels()
121 && format1.getSampleSizeInBits() == format2.getSampleSizeInBits()
122 && format1.getFrameSize() == format2.getFrameSize()
123 && (Math.abs(format1.getSampleRate() - format2.getSampleRate()) < 1.0e-9)
124 && (Math.abs(format1.getFrameRate() - format2.getFrameRate()) < 1.0e-9);
125 }
126
127}
128
129
130
131/*** AudioFormats.java ***/