summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/file/gsm/GSMAudioFileReader.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/file/gsm/GSMAudioFileReader.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/file/gsm/GSMAudioFileReader.java')
-rw-r--r--songdbj/org/tritonus/file/gsm/GSMAudioFileReader.java142
1 files changed, 142 insertions, 0 deletions
diff --git a/songdbj/org/tritonus/file/gsm/GSMAudioFileReader.java b/songdbj/org/tritonus/file/gsm/GSMAudioFileReader.java
new file mode 100644
index 0000000000..26859ddf24
--- /dev/null
+++ b/songdbj/org/tritonus/file/gsm/GSMAudioFileReader.java
@@ -0,0 +1,142 @@
1/*
2 * GSMAudioFileReader.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 1999 - 2004 by Matthias Pfisterer
9 * Copyright (c) 2001 by Florian Bomers <http://www.bomers.de>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Library General Public License as published
13 * by the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26/*
27|<--- this code is formatted to fit into 80 columns --->|
28*/
29
30package org.tritonus.sampled.file.gsm;
31
32import java.io.InputStream;
33import java.io.IOException;
34import java.io.EOFException;
35
36import java.util.HashMap;
37import java.util.Map;
38
39import javax.sound.sampled.AudioSystem;
40import javax.sound.sampled.AudioFormat;
41import javax.sound.sampled.AudioFileFormat;
42import javax.sound.sampled.AudioInputStream;
43import javax.sound.sampled.UnsupportedAudioFileException;
44import javax.sound.sampled.spi.AudioFileReader;
45
46import org.tritonus.share.TDebug;
47import org.tritonus.share.sampled.file.TAudioFileFormat;
48import org.tritonus.share.sampled.file.TAudioFileReader;
49
50
51
52/** AudioFileReader class for GSM 06.10 data.
53 @author Matthias Pfisterer
54 */
55public class GSMAudioFileReader
56extends TAudioFileReader
57{
58 private static final int GSM_MAGIC = 0xD0;
59 private static final int GSM_MAGIC_MASK = 0xF0;
60
61 private static final int MARK_LIMIT = 1;
62
63
64
65 public GSMAudioFileReader()
66 {
67 super(MARK_LIMIT, true);
68 }
69
70
71
72 protected AudioFileFormat getAudioFileFormat(InputStream inputStream, long lFileSizeInBytes)
73 throws UnsupportedAudioFileException, IOException
74 {
75 if (TDebug.TraceAudioFileReader) { TDebug.out("GSMAudioFileReader.getAudioFileFormat(): begin"); }
76 int b0 = inputStream.read();
77 if (b0 < 0)
78 {
79 throw new EOFException();
80 }
81
82 /*
83 * Check for magic number.
84 */
85 if ((b0 & GSM_MAGIC_MASK) != GSM_MAGIC)
86 {
87 throw new UnsupportedAudioFileException("not a GSM stream: wrong magic number");
88 }
89
90
91 /*
92 If the file size is known, we derive the number of frames
93 ('frame size') from it.
94 If the values don't fit into integers, we leave them at
95 NOT_SPECIFIED. 'Unknown' is considered less incorrect than
96 a wrong value.
97 */
98 // [fb] not specifying it causes Sun's Wave file writer to write rubbish
99 int nByteSize = AudioSystem.NOT_SPECIFIED;
100 int nFrameSize = AudioSystem.NOT_SPECIFIED;
101 Map<String, Object> properties = new HashMap<String, Object>();
102 if (lFileSizeInBytes != AudioSystem.NOT_SPECIFIED)
103 {
104 // the number of GSM frames
105 long lFrameSize = lFileSizeInBytes / 33;
106 // duration in microseconds
107 long lDuration = lFrameSize * 20000;
108 properties.put("duration", lDuration);
109 if (lFileSizeInBytes <= Integer.MAX_VALUE)
110 {
111 nByteSize = (int) lFileSizeInBytes;
112 nFrameSize = (int) (lFileSizeInBytes / 33);
113 }
114 }
115
116 Map<String, Object> afProperties = new HashMap<String, Object>();
117 afProperties.put("bitrate", 13200L);
118 AudioFormat format = new AudioFormat(
119 new AudioFormat.Encoding("GSM0610"),
120 8000.0F,
121 AudioSystem.NOT_SPECIFIED /* ??? [sample size in bits] */,
122 1,
123 33,
124 50.0F,
125 true, // this value is chosen arbitrarily
126 afProperties);
127 AudioFileFormat audioFileFormat =
128 new TAudioFileFormat(
129 new AudioFileFormat.Type("GSM","gsm"),
130 format,
131 nFrameSize,
132 nByteSize,
133 properties);
134 if (TDebug.TraceAudioFileReader) { TDebug.out("GSMAudioFileReader.getAudioFileFormat(): end"); }
135 return audioFileFormat;
136 }
137}
138
139
140
141/*** GSMAudioFileReader.java ***/
142