/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Java Sound audio clip;
*
* @author Arthur van Hoff, Kara Kytle, Jan Borgersen
* @author Florian Bomers
*/
private static final boolean DEBUG = false;
private static final int BUFFER_SIZE = 16384; // number of bytes written each time to the source data line
private boolean clipLooping = false;
private boolean sequencerloop = false;
/**
* used for determining how many samples is the
* threshhold between playing as a Clip and streaming
* from the file.
*
* $$jb: 11.07.99: the engine has a limit of 1M
* samples to play as a Clip, so compare this number
* with the number of samples in the stream.
*
*/
//private final static long CLIP_THRESHOLD = 1;
boolean success = false;
try {
// load the stream data into memory
if (success) {
success = false;
if (loadedAudioByteLength < CLIP_THRESHOLD) {
success = createClip();
}
if (!success) {
}
}
} catch (UnsupportedAudioFileException e) {
// not an audio file
try {
} catch (InvalidMidiDataException e1) {
success = false;
}
}
if (!success) {
throw new IOException("Unable to create AudioClip from input stream");
}
}
public synchronized void play() {
startImpl(false);
}
public synchronized void loop() {
startImpl(true);
}
// hack for some applets that call the start method very rapidly...
if (diff < MINIMUM_PLAY_DELAY) {
if (DEBUG || Printer.debug) Printer.debug("JavaSoundAudioClip.startImpl(loop="+loop+"): abort - too rapdly");
return;
}
try {
} else {
if (loop != clipLooping) {
// need to stop in case the looped status changed
}
}
if (loop) {
} else {
}
clipLooping = loop;
} else if (datapusher != null ) {
}
try {
} catch (InvalidMidiDataException e1) {
} catch (MidiUnavailableException e2) {
}
}
sequencer.addMetaEventListener(this);
try {
} catch (Exception e) {
}
}
} catch (Exception e) {
}
}
public synchronized void stop() {
lastPlayCall = 0;
try {
}
try {
}
} else if (datapusher != null) {
datapusher.stop();
try {
sequencerloop = false;
sequencer.addMetaEventListener(this);
}
try {
}
}
}
// Event handlers (for debugging)
}
// handle MIDI track end meta events for looping
if (sequencerloop){
//notifyAll();
loop();
} else {
stop();
}
}
}
}
protected void finalize() {
}
//$$fb 2001-09-26: may improve situation related to bug #4302884
if (datapusher != null) {
datapusher.close();
}
}
}
// FILE LOADING METHODS
private boolean loadAudioData(AudioInputStream as) throws IOException, UnsupportedAudioFileException {
// first possibly convert this stream to PCM
return false;
}
&& frameLen > 0
&& frameSize > 0) {
}
// if the stream length is known, it can be efficiently loaded into memory
} else {
// otherwise we use a ByteArrayOutputStream to load it into memory
readStream(as);
}
// if everything went fine, we have now the audio data in
// loadedAudio, and the byte length in loadedAudioByteLength
return true;
}
// arrays "only" max. 2GB
int intLen;
if (byteLen > 2147483647) {
intLen = 2147483647;
} else {
}
loadedAudio = new byte[intLen];
// this loop may throw an IOException
while (true) {
if (bytesRead <= 0) {
break;
}
}
}
byte buffer[] = new byte[16384];
int bytesRead = 0;
int totalBytesRead = 0;
// this loop may throw an IOException
while( true ) {
if (bytesRead <= 0) {
break;
}
}
}
// METHODS FOR CREATING THE DEVICE
private boolean createClip() {
try {
// fail silently
return false;
}
if (!(line instanceof AutoClosingClip)) {
// fail -> will try with SourceDataLine
return false;
}
clip.setAutoClosing(true);
} catch (Exception e) {
// fail silently
return false;
}
// fail silently
return false;
}
return true;
}
private boolean createSourceDataLine() {
try {
// fail silently
return false;
}
} catch (Exception e) {
// fail silently
return false;
}
if (datapusher==null) {
// fail silently
return false;
}
return true;
}
// get the sequencer
try {
} catch(MidiUnavailableException me) {
return false;
}
return false;
}
try {
return false;
}
} catch (InvalidMidiDataException e) {
return false;
}
return true;
}
/*
* private inner class representing a ByteArrayOutputStream
* which allows retrieval of the internal array
*/
DirectBAOS() {
super();
}
public byte[] getInternalBuffer() {
return buf;
}
} // class DirectBAOS
}