summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/share/sampled/file/TAudioOutputStream.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/org/tritonus/share/sampled/file/TAudioOutputStream.java')
-rw-r--r--songdbj/org/tritonus/share/sampled/file/TAudioOutputStream.java197
1 files changed, 0 insertions, 197 deletions
diff --git a/songdbj/org/tritonus/share/sampled/file/TAudioOutputStream.java b/songdbj/org/tritonus/share/sampled/file/TAudioOutputStream.java
deleted file mode 100644
index e54316c0a6..0000000000
--- a/songdbj/org/tritonus/share/sampled/file/TAudioOutputStream.java
+++ /dev/null
@@ -1,197 +0,0 @@
1/*
2 * TAudioOutputStream.java
3 *
4 * This file is part of Tritonus: http://www.tritonus.org/
5 */
6
7/*
8 * Copyright (c) 2000 by Matthias Pfisterer
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.share.sampled.file;
32
33import java.io.IOException;
34
35import javax.sound.sampled.AudioFormat;
36import javax.sound.sampled.AudioSystem;
37
38import org.tritonus.share.TDebug;
39
40
41/**
42 * Base class for classes implementing AudioOutputStream.
43 *
44 * @author Matthias Pfisterer
45 */
46
47public abstract class TAudioOutputStream
48implements AudioOutputStream
49{
50 private AudioFormat m_audioFormat;
51 private long m_lLength; // in bytes
52 private long m_lCalculatedLength;
53 private TDataOutputStream m_dataOutputStream;
54 private boolean m_bDoBackPatching;
55 private boolean m_bHeaderWritten;
56
57
58
59 protected TAudioOutputStream(AudioFormat audioFormat,
60 long lLength,
61 TDataOutputStream dataOutputStream,
62 boolean bDoBackPatching)
63 {
64 m_audioFormat = audioFormat;
65 m_lLength = lLength;
66 m_lCalculatedLength = 0;
67 m_dataOutputStream = dataOutputStream;
68 m_bDoBackPatching = bDoBackPatching;
69 m_bHeaderWritten = false;
70 }
71
72
73
74 public AudioFormat getFormat()
75 {
76 return m_audioFormat;
77 }
78
79
80
81 /** Gives length of the stream.
82 * This value is in bytes. It may be AudioSystem.NOT_SPECIFIED
83 * to express that the length is unknown.
84 */
85 public long getLength()
86 {
87 return m_lLength;
88 }
89
90
91
92 /** Gives number of bytes already written.
93 */
94 // IDEA: rename this to BytesWritten or something like that ?
95 public long getCalculatedLength()
96 {
97 return m_lCalculatedLength;
98 }
99
100 protected TDataOutputStream getDataOutputStream()
101 {
102 return m_dataOutputStream;
103 }
104
105
106 /** Writes audio data to the destination (file or output stream).
107 */
108 // IDEA: use long?
109 public int write(byte[] abData, int nOffset, int nLength)
110 throws IOException
111 {
112 if (TDebug.TraceAudioOutputStream)
113 {
114 TDebug.out("TAudioOutputStream.write(): wanted length: " + nLength);
115 }
116 if (! m_bHeaderWritten)
117 {
118 writeHeader();
119 m_bHeaderWritten = true;
120 }
121 // $$fb added
122 // check that total writes do not exceed specified length
123 long lTotalLength=getLength();
124 if (lTotalLength!=AudioSystem.NOT_SPECIFIED && (m_lCalculatedLength+nLength)>lTotalLength) {
125 if (TDebug.TraceAudioOutputStream) {
126 TDebug.out("TAudioOutputStream.write(): requested more bytes to write than possible.");
127 }
128 nLength=(int) (lTotalLength-m_lCalculatedLength);
129 // sanity
130 if (nLength<0) {
131 nLength=0;
132 }
133 }
134 // TODO: throw an exception if nLength==0 ? (to indicate end of file ?)
135 if (nLength>0) {
136 m_dataOutputStream.write(abData, nOffset, nLength);
137 m_lCalculatedLength += nLength;
138 }
139 if (TDebug.TraceAudioOutputStream)
140 {
141 TDebug.out("TAudioOutputStream.write(): calculated (total) length: " + m_lCalculatedLength+" bytes = "+(m_lCalculatedLength/getFormat().getFrameSize())+" frames");
142 }
143 return nLength;
144 }
145
146
147
148 /** Writes the header of the audio file.
149 */
150 protected abstract void writeHeader()
151 throws IOException;
152
153
154
155 /** Closes the stream.
156 * This does write remaining buffered data to the destination,
157 * backpatch the header, if necessary, and closes the destination.
158 */
159 public void close()
160 throws IOException
161 {
162 if (TDebug.TraceAudioOutputStream)
163 {
164 TDebug.out("TAudioOutputStream.close(): called");
165 }
166 // flush?
167 if (m_bDoBackPatching)
168 {
169 if (TDebug.TraceAudioOutputStream)
170 {
171 TDebug.out("TAudioOutputStream.close(): patching header");
172 }
173 patchHeader();
174 }
175 m_dataOutputStream.close();
176 }
177
178
179
180 protected void patchHeader()
181 throws IOException
182 {
183 TDebug.out("TAudioOutputStream.patchHeader(): called");
184 // DO NOTHING
185 }
186
187
188
189 protected void setLengthFromCalculatedLength()
190 {
191 m_lLength = m_lCalculatedLength;
192 }
193}
194
195
196
197/*** TAudioOutputStream.java ***/