summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/file/WaveTool.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/org/tritonus/file/WaveTool.java')
-rw-r--r--songdbj/org/tritonus/file/WaveTool.java115
1 files changed, 0 insertions, 115 deletions
diff --git a/songdbj/org/tritonus/file/WaveTool.java b/songdbj/org/tritonus/file/WaveTool.java
deleted file mode 100644
index 3487557088..0000000000
--- a/songdbj/org/tritonus/file/WaveTool.java
+++ /dev/null
@@ -1,115 +0,0 @@
1/*
2 * WaveTool.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2000 by Florian Bomers <http://www.bomers.de>
9 *
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/*
28|<--- this code is formatted to fit into 80 columns --->|
29*/
30
31package org.tritonus.sampled.file;
32
33import javax.sound.sampled.AudioSystem;
34import javax.sound.sampled.AudioFormat;
35import javax.sound.sampled.AudioFileFormat;
36
37
38/**
39 * Common constants and methods for handling wave files.
40 *
41 * @author Florian Bomers
42 */
43
44public class WaveTool {
45
46 public static final int WAVE_RIFF_MAGIC = 0x52494646; // "RIFF"
47 public static final int WAVE_WAVE_MAGIC = 0x57415645; // "WAVE"
48 public static final int WAVE_FMT_MAGIC = 0x666D7420; // "fmt "
49 public static final int WAVE_DATA_MAGIC = 0x64617461; // "DATA"
50 public static final int WAVE_FACT_MAGIC = 0x66616374; // "fact"
51
52 public static final short WAVE_FORMAT_UNSPECIFIED = 0;
53 public static final short WAVE_FORMAT_PCM = 1;
54 public static final short WAVE_FORMAT_MS_ADPCM = 2;
55 public static final short WAVE_FORMAT_ALAW = 6;
56 public static final short WAVE_FORMAT_ULAW = 7;
57 public static final short WAVE_FORMAT_IMA_ADPCM = 17; // same as DVI_ADPCM
58 public static final short WAVE_FORMAT_G723_ADPCM = 20;
59 public static final short WAVE_FORMAT_GSM610 = 49;
60 public static final short WAVE_FORMAT_G721_ADPCM = 64;
61 public static final short WAVE_FORMAT_MPEG = 80;
62
63 public static final int MIN_FMT_CHUNK_LENGTH=14;
64 public static final int MIN_DATA_OFFSET=12+8+MIN_FMT_CHUNK_LENGTH+8;
65 public static final int MIN_FACT_CHUNK_LENGTH = 4;
66
67 // we always write the sample size in bits and the length of extra bytes.
68 // There are programs (CoolEdit) that rely on the
69 // additional entry for sample size in bits.
70 public static final int FMT_CHUNK_SIZE=18;
71 public static final int RIFF_CONTAINER_CHUNK_SIZE=12;
72 public static final int CHUNK_HEADER_SIZE=8;
73 public static final int DATA_OFFSET=RIFF_CONTAINER_CHUNK_SIZE
74 +CHUNK_HEADER_SIZE+FMT_CHUNK_SIZE+CHUNK_HEADER_SIZE;
75
76 public static AudioFormat.Encoding GSM0610 = new AudioFormat.Encoding("GSM0610");
77 public static AudioFormat.Encoding IMA_ADPCM = new AudioFormat.Encoding("IMA_ADPCM");
78
79 public static short getFormatCode(AudioFormat format) {
80 AudioFormat.Encoding encoding = format.getEncoding();
81 int nSampleSize = format.getSampleSizeInBits();
82 boolean littleEndian = !format.isBigEndian();
83 boolean frameSizeOK=format.getFrameSize()==AudioSystem.NOT_SPECIFIED
84 || format.getChannels()!=AudioSystem.NOT_SPECIFIED
85 || format.getFrameSize()==nSampleSize/8*format.getChannels();
86
87 if (nSampleSize==8 && frameSizeOK
88 && (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)
89 || encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED))) {
90 return WAVE_FORMAT_PCM;
91 } else if (nSampleSize>8 && frameSizeOK && littleEndian
92 && encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) {
93 return WAVE_FORMAT_PCM;
94 } else if (encoding.equals(AudioFormat.Encoding.ULAW)
95 && (nSampleSize==AudioSystem.NOT_SPECIFIED || nSampleSize == 8)
96 && frameSizeOK) {
97 return WAVE_FORMAT_ULAW;
98 } else if (encoding.equals(AudioFormat.Encoding.ALAW)
99 && (nSampleSize==AudioSystem.NOT_SPECIFIED || nSampleSize == 8)
100 && frameSizeOK) {
101 return WAVE_FORMAT_ALAW;
102 } else if (encoding.equals(new AudioFormat.Encoding("IMA_ADPCM"))
103 && nSampleSize == 4)
104 {
105 return WAVE_FORMAT_IMA_ADPCM;
106 }
107 else if (encoding.equals(GSM0610)) {
108 return WAVE_FORMAT_GSM610;
109 }
110 return WAVE_FORMAT_UNSPECIFIED;
111 }
112
113}
114
115/*** WaveTool.java ***/