summaryrefslogtreecommitdiff
path: root/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/org/tritonus/share/sampled/mixer/TDataLine.java')
-rw-r--r--songdbj/org/tritonus/share/sampled/mixer/TDataLine.java304
1 files changed, 0 insertions, 304 deletions
diff --git a/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java b/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java
deleted file mode 100644
index a493bac6c5..0000000000
--- a/songdbj/org/tritonus/share/sampled/mixer/TDataLine.java
+++ /dev/null
@@ -1,304 +0,0 @@
1/*
2 * TDataLine.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 *
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.mixer;
32
33import java.util.Collection;
34import java.util.EventListener;
35import java.util.EventObject;
36import java.util.HashSet;
37import java.util.Set;
38
39import javax.sound.sampled.AudioFormat;
40import javax.sound.sampled.AudioSystem;
41import javax.sound.sampled.Control;
42import javax.sound.sampled.DataLine;
43import javax.sound.sampled.LineEvent;
44import javax.sound.sampled.Line;
45
46import org.tritonus.share.TDebug;
47
48
49
50/** Base class for classes implementing DataLine.
51 */
52public abstract class TDataLine
53extends TLine
54implements DataLine
55{
56 private static final int DEFAULT_BUFFER_SIZE = 128000;
57
58 private AudioFormat m_format;
59 private int m_nBufferSize;
60 private boolean m_bRunning;
61 // private boolean m_bActive;
62
63
64
65
66 public TDataLine(TMixer mixer,
67 DataLine.Info info)
68 {
69 super(mixer,
70 info);
71 init(info);
72 }
73
74
75
76 public TDataLine(TMixer mixer,
77 DataLine.Info info,
78 Collection<Control> controls)
79 {
80 super(mixer,
81 info,
82 controls);
83 init(info);
84 }
85
86
87
88 // IDEA: extract format and bufsize from info?
89 private void init(DataLine.Info info)
90 {
91 m_format = null;
92 m_nBufferSize = AudioSystem.NOT_SPECIFIED;
93 setRunning(false);
94 // setActive(false);
95 }
96
97
98
99 // not defined here:
100 // public void drain()
101 // public void flush()
102
103
104
105 public void start()
106 {
107 if (TDebug.TraceSourceDataLine)
108 {
109 TDebug.out("TDataLine.start(): called");
110 }
111 setRunning(true);
112 }
113
114
115
116 public void stop()
117 {
118 if (TDebug.TraceSourceDataLine)
119 {
120 TDebug.out("TDataLine.stop(): called");
121 }
122 setRunning(false);
123 }
124
125
126
127 public boolean isRunning()
128 {
129 return m_bRunning;
130 }
131
132
133
134 // TODO: recheck
135 protected void setRunning(boolean bRunning)
136 {
137 boolean bOldValue = isRunning();
138 m_bRunning = bRunning;
139 if (bOldValue != isRunning())
140 {
141 if (isRunning())
142 {
143 startImpl();
144 notifyLineEvent(LineEvent.Type.START);
145 }
146 else
147 {
148 stopImpl();
149 notifyLineEvent(LineEvent.Type.STOP);
150 }
151 }
152 }
153
154
155
156 protected void startImpl()
157 {
158 }
159
160
161
162 protected void stopImpl()
163 {
164 }
165
166
167
168 /**
169 * This implementation returns the status of isRunning().
170 * Subclasses should overwrite this method if there is more
171 * precise information about the status of the line available.
172 */
173 public boolean isActive()
174 {
175 return isRunning();
176 }
177
178
179/*
180 public boolean isStarted()
181 {
182 return m_bStarted;
183 }
184*/
185
186 // TODO: should only ALLOW engaging in data I/O.
187 // actual START event should only be sent when line really becomes active
188/*
189 protected void setStarted(boolean bStarted)
190 {
191 m_bStarted = bStarted;
192 if (!isRunning())
193 {
194 setActive(false);
195 }
196 }
197*/
198
199
200 public AudioFormat getFormat()
201 {
202 return m_format;
203 }
204
205
206
207 protected void setFormat(AudioFormat format)
208 {
209 if (TDebug.TraceDataLine)
210 {
211 TDebug.out("TDataLine.setFormat(): setting: " + format);
212 }
213 m_format = format;
214 }
215
216
217
218 public int getBufferSize()
219 {
220 return m_nBufferSize;
221 }
222
223
224
225 protected void setBufferSize(int nBufferSize)
226 {
227 if (TDebug.TraceDataLine)
228 {
229 TDebug.out("TDataLine.setBufferSize(): setting: " + nBufferSize);
230 }
231 m_nBufferSize = nBufferSize;
232 }
233
234
235
236 // not defined here:
237 // public int available()
238
239
240
241 public int getFramePosition()
242 {
243 // TODO:
244 return -1;
245 }
246
247
248
249 public long getLongFramePosition()
250 {
251 // TODO:
252 return -1;
253 }
254
255
256
257 public long getMicrosecondPosition()
258 {
259 return (long) (getFramePosition() * getFormat().getFrameRate() * 1000000);
260 }
261
262
263
264 /*
265 * Has to be overridden to be useful.
266 */
267 public float getLevel()
268 {
269 return AudioSystem.NOT_SPECIFIED;
270 }
271
272
273
274 protected void checkOpen()
275 {
276 if (getFormat() == null)
277 {
278 throw new IllegalStateException("format must be specified");
279 }
280 if (getBufferSize() == AudioSystem.NOT_SPECIFIED)
281 {
282 setBufferSize(getDefaultBufferSize());
283 }
284 }
285
286
287
288 protected int getDefaultBufferSize()
289 {
290 return DEFAULT_BUFFER_SIZE;
291 }
292
293
294
295 protected void notifyLineEvent(LineEvent.Type type)
296 {
297 notifyLineEvent(new LineEvent(this, type, getFramePosition()));
298 }
299}
300
301
302
303/*** TDataLine.java ***/
304