jdk/src/java.desktop/share/classes/com/sun/media/sound/JavaSoundAudioClip.java
author serb
Thu, 18 Feb 2016 22:11:29 +0300
changeset 36454 d2853d1fc614
parent 32865 f9cb6e427f9e
child 37557 00d5cb18c86b
permissions -rw-r--r--
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV Reviewed-by: prr, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.media.sound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.applet.AudioClip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.sound.sampled.AudioSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.sound.sampled.Clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.sound.sampled.AudioInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.sound.sampled.AudioFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.sound.sampled.DataLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.sound.sampled.SourceDataLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.sound.sampled.LineEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.sound.sampled.LineListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.sound.sampled.UnsupportedAudioFileException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.sound.midi.MidiSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.sound.midi.MidiFileFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.sound.midi.MetaMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.sound.midi.Sequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.sound.midi.Sequencer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.sound.midi.InvalidMidiDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.sound.midi.MidiUnavailableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.sound.midi.MetaEventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Java Sound audio clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Arthur van Hoff, Kara Kytle, Jan Borgersen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
    60
public final class JavaSoundAudioClip implements AudioClip, MetaEventListener, LineListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final boolean DEBUG = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final int BUFFER_SIZE = 16384; // number of bytes written each time to the source data line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private long lastPlayCall = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final int MINIMUM_PLAY_DELAY = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private byte loadedAudio[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int loadedAudioByteLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private AudioFormat loadedAudioFormat = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private AutoClosingClip clip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private boolean clipLooping = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private DataPusher datapusher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Sequencer sequencer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private Sequence sequence = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private boolean sequencerloop = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * used for determining how many samples is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * threshhold between playing as a Clip and streaming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * from the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * $$jb: 11.07.99: the engine has a limit of 1M
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * samples to play as a Clip, so compare this number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * with the number of samples in the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    91
    private static final long CLIP_THRESHOLD = 1048576;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    //private final static long CLIP_THRESHOLD = 1;
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    93
    private static final int STREAM_BUFFER_SIZE = 1024;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public JavaSoundAudioClip(InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        bis.mark(STREAM_BUFFER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        boolean success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            AudioInputStream as = AudioSystem.getAudioInputStream(bis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            // load the stream data into memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            success = loadAudioData(as);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            if (success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                if (loadedAudioByteLength < CLIP_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    success = createClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    success = createSourceDataLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } catch (UnsupportedAudioFileException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            // not an audio file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                MidiFileFormat mff = MidiSystem.getMidiFileFormat(bis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                success = createSequencer(bis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            } catch (InvalidMidiDataException e1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (!success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new IOException("Unable to create AudioClip from input stream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public synchronized void play() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        startImpl(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public synchronized void loop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        startImpl(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private synchronized void startImpl(boolean loop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // hack for some applets that call the start method very rapidly...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        long currentTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        long diff = currentTime - lastPlayCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (diff < MINIMUM_PLAY_DELAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            if (DEBUG || Printer.debug) Printer.debug("JavaSoundAudioClip.startImpl(loop="+loop+"): abort - too rapdly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        lastPlayCall = currentTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (DEBUG || Printer.debug) Printer.debug("JavaSoundAudioClip.startImpl(loop="+loop+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            if (clip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                if (!clip.isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.open()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    clip.open(loadedAudioFormat, loadedAudio, 0, loadedAudioByteLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.flush()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    clip.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    if (loop != clipLooping) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        // need to stop in case the looped status changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.stop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                        clip.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                clip.setFramePosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                if (loop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.loop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    clip.loop(Clip.LOOP_CONTINUOUSLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.start()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    clip.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                clipLooping = loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (DEBUG || Printer.debug)Printer.debug("Clip should be playing/looping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            } else if (datapusher != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                datapusher.start(loop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                if (DEBUG || Printer.debug)Printer.debug("Stream should be playing/looping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            } else if (sequencer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                sequencerloop = loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (sequencer.isRunning()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    sequencer.setMicrosecondPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                if (!sequencer.isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        sequencer.open();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        sequencer.setSequence(sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    } catch (InvalidMidiDataException e1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        if (DEBUG || Printer.err)e1.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    } catch (MidiUnavailableException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        if (DEBUG || Printer.err)e2.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                sequencer.addMetaEventListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    sequencer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    if (DEBUG || Printer.err) e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                if (DEBUG || Printer.debug)Printer.debug("Sequencer should be playing/looping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (DEBUG || Printer.err)e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public synchronized void stop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->stop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        lastPlayCall = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (clip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.flush()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                clip.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } catch (Exception e1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if (Printer.err) e1.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip: clip.stop()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                clip.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            } catch (Exception e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                if (Printer.err) e2.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (DEBUG || Printer.debug)Printer.debug("Clip should be stopped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } else if (datapusher != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            datapusher.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            if (DEBUG || Printer.debug)Printer.debug("Stream should be stopped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        } else if (sequencer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                sequencerloop = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                sequencer.addMetaEventListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                sequencer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            } catch (Exception e3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (Printer.err) e3.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                sequencer.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            } catch (Exception e4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                if (Printer.err) e4.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (DEBUG || Printer.debug)Printer.debug("Sequencer should be stopped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    // Event handlers (for debugging)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public synchronized void update(LineEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (DEBUG || Printer.debug) Printer.debug("line event received: "+event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    // handle MIDI track end meta events for looping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public synchronized void meta( MetaMessage message ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (DEBUG || Printer.debug)Printer.debug("META EVENT RECEIVED!!!!! ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if( message.getType() == 47 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (sequencerloop){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                //notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                sequencer.setMicrosecondPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                loop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return getClass().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    protected void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (clip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if (DEBUG || Printer.trace)Printer.trace("JavaSoundAudioClip.finalize: clip.close()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            clip.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        //$$fb 2001-09-26: may improve situation related to bug #4302884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (datapusher != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            datapusher.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (sequencer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            sequencer.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    // FILE LOADING METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    private boolean loadAudioData(AudioInputStream as)  throws IOException, UnsupportedAudioFileException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->openAsClip()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // first possibly convert this stream to PCM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        as = Toolkit.getPCMConvertedAudioInputStream(as);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (as == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        loadedAudioFormat = as.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        long frameLen = as.getFrameLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        int frameSize = loadedAudioFormat.getFrameSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        long byteLen = AudioSystem.NOT_SPECIFIED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (frameLen != AudioSystem.NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            && frameLen > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            && frameSize != AudioSystem.NOT_SPECIFIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            && frameSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            byteLen = frameLen * frameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (byteLen != AudioSystem.NOT_SPECIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            // if the stream length is known, it can be efficiently loaded into memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            readStream(as, byteLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            // otherwise we use a ByteArrayOutputStream to load it into memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            readStream(as);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // if everything went fine, we have now the audio data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // loadedAudio, and the byte length in loadedAudioByteLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    private void readStream(AudioInputStream as, long byteLen) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // arrays "only" max. 2GB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        int intLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (byteLen > 2147483647) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            intLen = 2147483647;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            intLen = (int) byteLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        loadedAudio = new byte[intLen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        loadedAudioByteLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // this loop may throw an IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            int bytesRead = as.read(loadedAudio, loadedAudioByteLength, intLen - loadedAudioByteLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            if (bytesRead <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                as.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            loadedAudioByteLength += bytesRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private void readStream(AudioInputStream as) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        DirectBAOS baos = new DirectBAOS();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        byte buffer[] = new byte[16384];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int bytesRead = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int totalBytesRead = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        // this loop may throw an IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        while( true ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            bytesRead = as.read(buffer, 0, buffer.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (bytesRead <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                as.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            totalBytesRead += bytesRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            baos.write(buffer, 0, bytesRead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        loadedAudio = baos.getInternalBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        loadedAudioByteLength = totalBytesRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    // METHODS FOR CREATING THE DEVICE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private boolean createClip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createClip()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            DataLine.Info info = new DataLine.Info(Clip.class, loadedAudioFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (!(AudioSystem.isLineSupported(info)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                if (DEBUG || Printer.err)Printer.err("Clip not supported: "+loadedAudioFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                // fail silently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            Object line = AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            if (!(line instanceof AutoClosingClip)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (DEBUG || Printer.err)Printer.err("Clip is not auto closing!"+clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                // fail -> will try with SourceDataLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            clip = (AutoClosingClip) line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            clip.setAutoClosing(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            if (DEBUG || Printer.debug) clip.addLineListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (DEBUG || Printer.err)e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            // fail silently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (clip==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            // fail silently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (DEBUG || Printer.debug)Printer.debug("Loaded clip.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private boolean createSourceDataLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSourceDataLine()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, loadedAudioFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (!(AudioSystem.isLineSupported(info)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                if (DEBUG || Printer.err)Printer.err("Line not supported: "+loadedAudioFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                // fail silently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            SourceDataLine source = (SourceDataLine) AudioSystem.getLine(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            datapusher = new DataPusher(source, loadedAudioFormat, loadedAudio, loadedAudioByteLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (DEBUG || Printer.err)e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            // fail silently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (datapusher==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            // fail silently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (DEBUG || Printer.debug)Printer.debug("Created SourceDataLine.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private boolean createSequencer(BufferedInputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSequencer()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        // get the sequencer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            sequencer = MidiSystem.getSequencer( );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        } catch(MidiUnavailableException me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (DEBUG || Printer.err)me.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (sequencer==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            sequence = MidiSystem.getSequence(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (sequence == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        } catch (InvalidMidiDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (DEBUG || Printer.err)e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (DEBUG || Printer.debug)Printer.debug("Created Sequencer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * private inner class representing a ByteArrayOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * which allows retrieval of the internal array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    private static class DirectBAOS extends ByteArrayOutputStream {
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   473
        DirectBAOS() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        public byte[] getInternalBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            return buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    } // class DirectBAOS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}