diff options
Diffstat (limited to 'libjava/classpath/gnu/javax/sound')
24 files changed, 474 insertions, 475 deletions
diff --git a/libjava/classpath/gnu/javax/sound/AudioSecurityManager.java b/libjava/classpath/gnu/javax/sound/AudioSecurityManager.java index a6dce60..1daea2d 100644 --- a/libjava/classpath/gnu/javax/sound/AudioSecurityManager.java +++ b/libjava/classpath/gnu/javax/sound/AudioSecurityManager.java @@ -1,5 +1,5 @@ /* AudioSecurityManager.java -- Manages Security requests for Sound classes. - + Copyright (C) 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,10 +42,10 @@ import javax.sound.sampled.AudioPermission; /** * This class handles security requests for classes in the Sound API. - * + * * A class that needs to check against a particular permission type may use this * class to query the <code>SecurityManager</code>. - * + * * For example, to check for a read permission, a class can simply pass the * <code>Permission.READ</code> constant to * {@link #checkPermissions(gnu.javax.sound.AudioSecurityManager.Permission))}, @@ -54,11 +54,11 @@ import javax.sound.sampled.AudioPermission; * <pre> * AudioSecurityManager.checkPermissions(Permission.PLAY); * </pre> - * + * * If there is need to query for all the defined permissions type, the constant * <code>Permission.ALL</code> can be used. In alternative, the - * {@link #checkPermissions()} is presented as a shorthand. - * + * {@link #checkPermissions()} is presented as a shorthand. + * * @author Mario Torre <neugens@limasoftware.net> */ public class AudioSecurityManager @@ -70,19 +70,19 @@ public class AudioSecurityManager { PLAY, RECORD, ALL } - + /** - * Shorthand to <code>checkPermissions(Permission.ALL)</code>. + * Shorthand to <code>checkPermissions(Permission.ALL)</code>. */ public static final void checkPermissions() { checkPermissions(Permission.ALL); } - + /** - * Query the <code>SecurityManager</code> agains the given + * Query the <code>SecurityManager</code> agains the given * <code>Permission</code>. - * + * * @param permission */ public static final void checkPermissions(Permission permission) @@ -96,16 +96,16 @@ public class AudioSecurityManager case PLAY: perm = "play"; break; - + case RECORD: perm = "record"; break; - + case ALL: default: perm = "*"; break; } - + sm.checkPermission(new AudioPermission(perm)); } } diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java index fb9e684..d37a8fd 100644 --- a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaInputPortDevice.java @@ -45,18 +45,18 @@ import gnu.javax.sound.midi.alsa.AlsaMidiDeviceProvider.AlsaPortInfo; /** * ALSA MIDI In Port. - * + * * @author Anthony Green (green@redhat.com) * */ public class AlsaInputPortDevice extends AlsaPortDevice -{ +{ AlsaInputPortDevice (AlsaPortInfo info) { super(info); } - + /* (non-Javadoc) * @see javax.sound.midi.MidiDevice#open() */ diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java index 4951be6..33181b6 100644 --- a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiDeviceProvider.java @@ -46,7 +46,7 @@ import javax.sound.midi.spi.MidiDeviceProvider; /** * Provide ALSA MIDI devices. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -54,7 +54,7 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { /** * Abstract base for ALSA specific MIDI device info. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -62,7 +62,7 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { /** * Create an ALSA specific MIDI device info object. - * + * * @param name the device name * @param description the device description */ @@ -70,13 +70,13 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { super(name, "Alsa", description, "0.0"); } - + abstract MidiDevice getDevice (); - } + } /** * ALSA MIDI Port. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -84,10 +84,10 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { long client; long port; - + /** * Create ALSA MIDI In Port. - * + * * @param name the device name * @param description the device description * @param client the client ID @@ -99,11 +99,11 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider this.client = client; this.port = port; } - } - + } + /** * ALSA Sequencer specific info. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -113,16 +113,16 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { super(name, description); } - + MidiDevice getDevice() { return AlsaMidiSequencerDevice.getInstance(); } } - + /** * ALSA MIDI In Port. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -132,7 +132,7 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { super(name, description, client, port); } - + MidiDevice getDevice() { return new AlsaInputPortDevice(this); @@ -141,7 +141,7 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider /** * ALSA MIDI Out Port. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -151,46 +151,46 @@ public class AlsaMidiDeviceProvider extends MidiDeviceProvider { super(name, description, client, port); } - + MidiDevice getDevice() { return new AlsaOutputPortDevice(this); } } - + private static AlsaInfo[] infos; - + private static native AlsaInfo[] getInputDeviceInfo_(); private static native AlsaInfo[] getOutputDeviceInfo_(); - + /** * Initialize the ALSA system */ private static native void init_(); - + static - { + { if (Configuration.INIT_LOAD_LIBRARY) { System.loadLibrary("gjsmalsa"); - } - + } + init_(); - + AlsaInfo inputs[] = getInputDeviceInfo_(); AlsaInfo outputs[] = getOutputDeviceInfo_(); - + infos = new AlsaInfo[inputs.length + outputs.length + 1]; infos[0] = new AlsaSequencerInfo ("/dev/snd/seq", "ALSA Sequencer"); System.arraycopy(inputs, 0, infos, 1, inputs.length); System.arraycopy(outputs, 0, infos, 1 + inputs.length, outputs.length); } - + public AlsaMidiDeviceProvider() { // Nothing. } - + /* (non-Javadoc) * @see javax.sound.midi.spi.MidiDeviceProvider#getDeviceInfo() */ diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java index 3810dff..3603bb5 100644 --- a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaMidiSequencerDevice.java @@ -53,7 +53,7 @@ import javax.sound.midi.Transmitter; /** * The ALSA MIDI sequencer device. This is a singleton device. - * + * * @author green@redhat.com * */ @@ -61,16 +61,16 @@ public class AlsaMidiSequencerDevice implements Sequencer { // The singleton instance. public final static AlsaMidiSequencerDevice instance = new AlsaMidiSequencerDevice(); - + // A pointer to a native chunk of memory private long nativeState; - + // The sequence to process private Sequence sequence; - + /** * A private constructor. There should only be one instance of this - * device. + * device. */ private AlsaMidiSequencerDevice() { @@ -79,14 +79,14 @@ public class AlsaMidiSequencerDevice implements Sequencer /** * Return the sequencer singleton. - * + * * @return the sequencer singleton */ public static AlsaMidiSequencerDevice getInstance() { return instance; } - + /* (non-Javadoc) * @see javax.sound.midi.Sequencer#setSequence(javax.sound.midi.Sequence) */ @@ -438,23 +438,23 @@ public class AlsaMidiSequencerDevice implements Sequencer // Check to see if we're open already. if (nativeState != 0) return; - + nativeState = open_(); } } /** * Allocate the native state object, and open the sequencer. - * + * * @return a long representation of a pointer to the nativeState. */ private native long open_(); - + /** * Close the sequencer and free the native state object. */ private native void close_(long nativeState); - + /* (non-Javadoc) * @see javax.sound.midi.MidiDevice#close() */ diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java index bc5a5593..9140d59 100644 --- a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaOutputPortDevice.java @@ -46,7 +46,7 @@ import javax.sound.midi.Transmitter; /** * ALSA MIDI Out Device - * + * * @author Anthony Green (green@redhat.com) * */ diff --git a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java index 0e59bc8..f55941b 100644 --- a/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java +++ b/libjava/classpath/gnu/javax/sound/midi/alsa/AlsaPortDevice.java @@ -47,7 +47,7 @@ import gnu.javax.sound.midi.alsa.AlsaMidiDeviceProvider.AlsaPortInfo; /** * ALSA Port Device - * + * * @author Anthony Green (green@redhat.com) * */ @@ -55,7 +55,7 @@ public abstract class AlsaPortDevice implements MidiDevice { /** * The ALSA Receiver class. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -82,22 +82,22 @@ public abstract class AlsaPortDevice implements MidiDevice } AlsaMidiDeviceProvider.AlsaPortInfo info; - + public AlsaPortDevice (AlsaPortInfo info) { this.info = info; } - + public Info getDeviceInfo() { return info; } native void run_receiver_thread_ (long client, long port, Receiver receiver); - + /** * The ALSA Transmitter class. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -109,7 +109,7 @@ public abstract class AlsaPortDevice implements MidiDevice { run_receiver_thread_ (info.client, info.port, receiver); } - + /* (non-Javadoc) * @see javax.sound.midi.Transmitter#setReceiver(javax.sound.midi.Receiver) */ @@ -119,7 +119,7 @@ public abstract class AlsaPortDevice implements MidiDevice { this.receiver = receiver; } - + // Create the processing thread new Thread(this).start(); } diff --git a/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java index 740b124..605c6df 100644 --- a/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java +++ b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSIMidiDeviceProvider.java @@ -50,12 +50,12 @@ import javax.sound.midi.spi.MidiDeviceProvider; /** * A DSSI MIDI device provider. - * - * DSSI (pronounced "dizzy") is an API for audio plugins, with particular + * + * DSSI (pronounced "dizzy") is an API for audio plugins, with particular * application for software synthesis plugins with native user interfaces. - * + * * Read about DSSI at http://dssi.sourceforge.net - * + * * @author Anthony Green (green@redhat.com) * */ @@ -63,7 +63,7 @@ public class DSSIMidiDeviceProvider extends MidiDeviceProvider { /** * The MidiDevice.Info specialized for DSSI synthesizers. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -71,7 +71,7 @@ public class DSSIMidiDeviceProvider extends MidiDeviceProvider { String soname; long index; - + public DSSIInfo(String name, String vendor, String description, String version, String soname, long index) { @@ -88,13 +88,13 @@ public class DSSIMidiDeviceProvider extends MidiDeviceProvider static native String getDSSICopyright_(long handle); static native String getDSSIVendor_(long handle); static native String getDSSILabel_(long handle); - + private static List examineLibrary(String soname) { List list = new ArrayList(); long index = 0; long handle; - + long sohandle = dlopen_(soname); if (sohandle == 0) return list; @@ -107,19 +107,19 @@ public class DSSIMidiDeviceProvider extends MidiDeviceProvider String copyright = getDSSICopyright_(handle); String label = getDSSIName_(handle); String vendor = getDSSIVendor_(handle); - list.add(new DSSIInfo(name, vendor, label, + list.add(new DSSIInfo(name, vendor, label, "DSSI-1", soname, index)); index++; } while (true); - + // Close the library and free memory dlclose_(sohandle); - + return list; } - + private static DSSIInfo[] infos; - + static { if (Configuration.INIT_LOAD_LIBRARY) @@ -131,19 +131,19 @@ public class DSSIMidiDeviceProvider extends MidiDeviceProvider public boolean accept(File dir, String n) { return n.endsWith(".so"); - } + } }); List ilist = new ArrayList(); for (int i = 0; i < sofiles.length; i++) ilist.addAll(examineLibrary(new File(dssidir, sofiles[i]).getAbsolutePath())); infos = (DSSIInfo[]) ilist.toArray(new DSSIInfo[ilist.size()]); } - + public DSSIMidiDeviceProvider() { // Empty. } - + /* Return the Info array. * @see javax.sound.midi.spi.MidiDeviceProvider#getDeviceInfo() */ @@ -162,7 +162,7 @@ public class DSSIMidiDeviceProvider extends MidiDeviceProvider if (info.equals(infos[i])) { return new DSSISynthesizer(infos[i], - infos[i].soname, + infos[i].soname, infos[i].index); } } diff --git a/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java index 2682186..9472ee4 100644 --- a/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java +++ b/libjava/classpath/gnu/javax/sound/midi/dssi/DSSISynthesizer.java @@ -57,9 +57,9 @@ import javax.sound.midi.VoiceStatus; /** * DSSI soft-synth support. - * + * * All DSSI soft-synths are expected to be installed in /usr/lib/dssi. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -67,7 +67,7 @@ public class DSSISynthesizer implements Synthesizer { /** * The DSSI Instrument class. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -77,7 +77,7 @@ public class DSSISynthesizer implements Synthesizer { super (soundbank, patch, name, null); } - + /* @see javax.sound.midi.SoundbankResource#getData() */ public Object getData() @@ -89,7 +89,7 @@ public class DSSISynthesizer implements Synthesizer /** * DSSISoundbank holds all instruments. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -101,7 +101,7 @@ public class DSSISynthesizer implements Synthesizer private List resources = new ArrayList(); private String vendor; private String version; - + public DSSISoundbank(String name, String description, String vendor, String version) { this.name = name; @@ -109,12 +109,12 @@ public class DSSISynthesizer implements Synthesizer this.vendor = vendor; this.version = version; } - + void add(Instrument instrument) { instruments.add(instrument); } - + /* @see javax.sound.midi.Soundbank#getName() */ public String getName() @@ -164,14 +164,14 @@ public class DSSISynthesizer implements Synthesizer public Instrument getInstrument(Patch patch) { Iterator itr = instruments.iterator(); - + while (itr.hasNext()) { Instrument i = (Instrument) itr.next(); if (i.getPatch().equals(patch)) return i; } - + return null; } } @@ -179,7 +179,7 @@ public class DSSISynthesizer implements Synthesizer /** * The Receiver class receives all MIDI messages from a connected * Transmitter. - * + * * @author Anthony Green (green@redhat.com) * */ @@ -194,13 +194,13 @@ public class DSSISynthesizer implements Synthesizer if (message instanceof ShortMessage) { ShortMessage smessage = (ShortMessage) message; - + switch (message.getStatus()) { case ShortMessage.NOTE_ON: int velocity = smessage.getData2(); if (velocity > 0) - channels[smessage.getChannel()].noteOn(smessage.getData1(), + channels[smessage.getChannel()].noteOn(smessage.getData1(), smessage.getData2()); else channels[smessage.getChannel()].noteOff(smessage.getData1()); @@ -226,8 +226,8 @@ public class DSSISynthesizer implements Synthesizer } - static native void noteOn_(long handle, int channel, int noteNumber, int velocity); - static native void noteOff_(long handle, int channel, int noteNumber, int velocity); + static native void noteOn_(long handle, int channel, int noteNumber, int velocity); + static native void noteOff_(long handle, int channel, int noteNumber, int velocity); static native void setPolyPressure_(long handle, int channel, int noteNumber, int pressure); static native int getPolyPressure_(long handle, int channel, int noteNumber); static native void controlChange_(long handle, int channel, int control, int value); @@ -237,7 +237,7 @@ public class DSSISynthesizer implements Synthesizer static native int getProgramBank_(long handle, int index); static native int getProgramProgram_(long handle, int index); static native void selectProgram_(long handle, int bank, int program); - + /** * @author Anthony Green (green@redhat.com) * @@ -245,7 +245,7 @@ public class DSSISynthesizer implements Synthesizer public class DSSIMidiChannel implements MidiChannel { int channel = 0; - + /** * Default contructor. */ @@ -484,18 +484,18 @@ public class DSSISynthesizer implements Synthesizer } long sohandle; - long handle; + long handle; private Info info; - + MidiChannel channels[] = new MidiChannel[16]; - + // The list of known soundbanks, and the default one. List soundbanks = new ArrayList(); DSSISoundbank defaultSoundbank; - + /** * Create a DSSI Synthesizer. - * + * * @param info the DSSIInfo for this soft-synth * @param soname the name of the .so file for this DSSI synth * @param index the DSSI index for this soft-synth @@ -507,10 +507,10 @@ public class DSSISynthesizer implements Synthesizer sohandle = DSSIMidiDeviceProvider.dlopen_(soname); handle = DSSIMidiDeviceProvider.getDSSIHandle_(sohandle, index); channels[0] = new DSSIMidiChannel(0); - defaultSoundbank = new DSSISoundbank("name", "description", + defaultSoundbank = new DSSISoundbank("name", "description", "vendor", "version"); soundbanks.add(defaultSoundbank); - + int i = 0; String name; do @@ -519,7 +519,7 @@ public class DSSISynthesizer implements Synthesizer if (name != null) { defaultSoundbank. - add(new DSSIInstrument(defaultSoundbank, + add(new DSSIInstrument(defaultSoundbank, new Patch(getProgramBank_(sohandle, i), getProgramProgram_(sohandle, i)), name)); @@ -581,7 +581,7 @@ public class DSSISynthesizer implements Synthesizer // be in any soundbank. if (instrument.getSoundbank() != defaultSoundbank) throw new IllegalArgumentException ("Synthesizer doesn't support this instrument's soundbank"); - + Patch patch = instrument.getPatch(); selectProgram_(sohandle, patch.getBank(), patch.getProgram()); return true; diff --git a/libjava/classpath/gnu/javax/sound/midi/file/ExtendedMidiFileFormat.java b/libjava/classpath/gnu/javax/sound/midi/file/ExtendedMidiFileFormat.java index cb5a8e8..4b065f3 100644 --- a/libjava/classpath/gnu/javax/sound/midi/file/ExtendedMidiFileFormat.java +++ b/libjava/classpath/gnu/javax/sound/midi/file/ExtendedMidiFileFormat.java @@ -38,7 +38,7 @@ exception statement from your version. */ package gnu.javax.sound.midi.file; /** - * ExtendedMidiFileFormat is a package private class that simply + * ExtendedMidiFileFormat is a package private class that simply * adds the number of MIDI tracks for the MidiFileFormat class. * * @author Anthony Green (green@redhat.com) @@ -47,17 +47,17 @@ class ExtendedMidiFileFormat extends javax.sound.midi.MidiFileFormat { private int ntracks; - + /** * Get the number of tracks for this MIDI file. - * + * * @return the number of tracks for this MIDI file */ public int getNumberTracks() { return ntracks; } - + /** * Create an ExtendedMidiFileFormat object from the given parameters. * @@ -68,7 +68,7 @@ class ExtendedMidiFileFormat * @param microseconds the MIDI file length in microseconds * @param ntracks the number of tracks */ - public ExtendedMidiFileFormat(int type, float divisionType, int resolution, + public ExtendedMidiFileFormat(int type, float divisionType, int resolution, int bytes, long microseconds, int ntracks) { super(type, divisionType, resolution, bytes, microseconds); diff --git a/libjava/classpath/gnu/javax/sound/midi/file/MidiDataInputStream.java b/libjava/classpath/gnu/javax/sound/midi/file/MidiDataInputStream.java index 010d170..d91970b 100644 --- a/libjava/classpath/gnu/javax/sound/midi/file/MidiDataInputStream.java +++ b/libjava/classpath/gnu/javax/sound/midi/file/MidiDataInputStream.java @@ -57,7 +57,7 @@ public class MidiDataInputStream { super(is); } - + /** * Read an int encoded in the MIDI-style variable length * encoding format. @@ -68,7 +68,7 @@ public class MidiDataInputStream throws IOException { int c, value = readByte(); - + if ((value & 0x80) != 0) { value &= 0x7F; @@ -77,7 +77,7 @@ public class MidiDataInputStream value = (value << 7) + ((c = readByte()) & 0x7F); } while ((c & 0x80) != 0); } - - return value; + + return value; } } diff --git a/libjava/classpath/gnu/javax/sound/midi/file/MidiDataOutputStream.java b/libjava/classpath/gnu/javax/sound/midi/file/MidiDataOutputStream.java index f9a3dac..79c66e8 100644 --- a/libjava/classpath/gnu/javax/sound/midi/file/MidiDataOutputStream.java +++ b/libjava/classpath/gnu/javax/sound/midi/file/MidiDataOutputStream.java @@ -71,44 +71,44 @@ public class MidiDataOutputStream while ((value >>= 7) != 0) { - buffer <<= 8; - buffer |= ((value & 0x7F) | 0x80); + buffer <<= 8; + buffer |= ((value & 0x7F) | 0x80); } - + while (true) { - length++; - if ((buffer & 0x80) != 0) - buffer >>>= 8; - else - break; + length++; + if ((buffer & 0x80) != 0) + buffer >>>= 8; + else + break; } return length; } - + /** * Write an int encoded in the MIDI-style variable length * encoding format. */ - public synchronized void writeVariableLengthInt (int value) + public synchronized void writeVariableLengthInt (int value) throws IOException { int buffer = value & 0x7F; while ((value >>= 7) != 0) { - buffer <<= 8; - buffer |= ((value & 0x7F) | 0x80); + buffer <<= 8; + buffer |= ((value & 0x7F) | 0x80); } - + while (true) { - writeByte(buffer & 0xff); - if ((buffer & 0x80) != 0) - buffer >>>= 8; - else - break; + writeByte(buffer & 0xff); + if ((buffer & 0x80) != 0) + buffer >>>= 8; + else + break; } } } diff --git a/libjava/classpath/gnu/javax/sound/midi/file/MidiFileReader.java b/libjava/classpath/gnu/javax/sound/midi/file/MidiFileReader.java index cb640e1..fb2a472 100644 --- a/libjava/classpath/gnu/javax/sound/midi/file/MidiFileReader.java +++ b/libjava/classpath/gnu/javax/sound/midi/file/MidiFileReader.java @@ -56,8 +56,8 @@ import javax.sound.midi.Track; /** * A MIDI file reader. - * - * This code reads MIDI file types 0 and 1. + * + * This code reads MIDI file types 0 and 1. * * There are many decent documents on the web describing the MIDI file * format. I didn't bother looking for the official document. If it @@ -67,7 +67,7 @@ import javax.sound.midi.Track; * @author Anthony Green (green@redhat.com) * */ -public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader +public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader { /* Get the MidiFileFormat for the given input stream. * @see javax.sound.midi.spi.MidiFileReader#getMidiFileFormat(java.io.InputStream) @@ -80,28 +80,28 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader din = (DataInputStream) in; else din = new DataInputStream(in); - + int type, ntracks, division, resolution, bytes; float divisionType; - + if (din.readInt() != 0x4d546864) // "MThd" throw new InvalidMidiDataException("Invalid MIDI chunk header."); bytes = din.readInt(); if (bytes < 6) - throw new - InvalidMidiDataException("Invalid MIDI chunk header length: " + bytes); + throw new + InvalidMidiDataException("Invalid MIDI chunk header length: " + bytes); type = din.readShort(); if (type < 0 || type > 2) - throw new - InvalidMidiDataException("Invalid MIDI file type value: " + type); - + throw new + InvalidMidiDataException("Invalid MIDI file type value: " + type); + ntracks = din.readShort(); if (ntracks <= 0) - throw new - InvalidMidiDataException("Invalid number of MIDI tracks: " + ntracks); - + throw new + InvalidMidiDataException("Invalid number of MIDI tracks: " + ntracks); + division = din.readShort(); if ((division & 0x8000) != 0) { @@ -125,9 +125,9 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader break; default: - throw new - InvalidMidiDataException("Invalid MIDI frame division type: " - + division); + throw new + InvalidMidiDataException("Invalid MIDI frame division type: " + + division); } resolution = division & 0xff; } @@ -136,10 +136,10 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader divisionType = Sequence.PPQ; resolution = division & 0x7fff; } - + // If we haven't read every byte in the header now, just skip the rest. din.skip(bytes - 6); - + return new ExtendedMidiFileFormat(type, divisionType, resolution, MidiFileFormat.UNKNOWN_LENGTH, MidiFileFormat.UNKNOWN_LENGTH, ntracks); @@ -150,7 +150,7 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader */ public MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException - { + { InputStream is = url.openStream(); try { @@ -178,7 +178,7 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader is.close(); } } - + /* Get the MIDI Sequence found in this input stream. * @see javax.sound.midi.spi.MidiFileReader#getSequence(java.io.InputStream) */ @@ -272,7 +272,7 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader case ShortMessage.CHANNEL_PRESSURE: case ShortMessage.SONG_SELECT: case 0xF5: // FIXME: unofficial bus select. Not in - // spec?? + // spec?? sm = new ShortMessage(); sm.setMessage(runningStatus, sbyte, 0); continue; @@ -290,15 +290,15 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader continue; default: - throw new - InvalidMidiDataException("Invalid Short MIDI Event: " - + sbyte); + throw new + InvalidMidiDataException("Invalid Short MIDI Event: " + + sbyte); } } else - throw new - InvalidMidiDataException("Invalid Short MIDI Event: " - + sbyte); + throw new + InvalidMidiDataException("Invalid Short MIDI Event: " + + sbyte); } mm = sm; } @@ -346,16 +346,16 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader * @see javax.sound.midi.spi.MidiFileReader#getSequence(java.net.URL) */ public Sequence getSequence(URL url) throws InvalidMidiDataException, - IOException + IOException { InputStream is = url.openStream(); try { - return getSequence(is); + return getSequence(is); } finally { - is.close(); + is.close(); } } @@ -363,16 +363,16 @@ public class MidiFileReader extends javax.sound.midi.spi.MidiFileReader * @see javax.sound.midi.spi.MidiFileReader#getSequence(java.io.File) */ public Sequence getSequence(File file) throws InvalidMidiDataException, - IOException + IOException { InputStream is = new FileInputStream(file); try { - return getSequence(is); + return getSequence(is); } finally { - is.close(); + is.close(); } } } diff --git a/libjava/classpath/gnu/javax/sound/midi/file/MidiFileWriter.java b/libjava/classpath/gnu/javax/sound/midi/file/MidiFileWriter.java index b9b6fe8..5170fc1 100644 --- a/libjava/classpath/gnu/javax/sound/midi/file/MidiFileWriter.java +++ b/libjava/classpath/gnu/javax/sound/midi/file/MidiFileWriter.java @@ -49,8 +49,8 @@ import javax.sound.midi.Track; /** * A MIDI file writer. - * - * This code writes MIDI file types 0 and 1. + * + * This code writes MIDI file types 0 and 1. * * There are many decent documents on the web describing the MIDI file * format. I didn't bother looking for the official document. If it @@ -92,7 +92,7 @@ public class MidiFileWriter MidiDataOutputStream dos = new MidiDataOutputStream (out); Track[] tracks = in.getTracks(); dos.writeInt(0x4d546864); // MThd - dos.writeInt(6); + dos.writeInt(6); dos.writeShort(fileType); dos.writeShort(tracks.length); float divisionType = in.getDivisionType(); @@ -101,7 +101,7 @@ public class MidiFileWriter int division = 0; if (divisionType == Sequence.PPQ) division = resolution & 0x7fff; - dos.writeShort(division); + dos.writeShort(division); int length = 14; for (int i = 0; i < tracks.length; i++) length += writeTrack(tracks[i], dos); @@ -122,13 +122,13 @@ public class MidiFileWriter long ptick = 0; while (i < eventCount) { - MidiEvent me = track.get(i); - long tick = me.getTick(); - length += dos.variableLengthIntLength((int) (tick - ptick)); - ptick = tick; - length += me.getMessage().getLength(); - i++; - } + MidiEvent me = track.get(i); + long tick = me.getTick(); + length += dos.variableLengthIntLength((int) (tick - ptick)); + ptick = tick; + length += me.getMessage().getLength(); + i++; + } return length; } @@ -149,24 +149,24 @@ public class MidiFileWriter dos.writeInt(trackLength); while (i < elength) { - MidiEvent me = track.get(i); - int dtime = 0; - if (pme != null) - dtime = (int) (me.getTick() - pme.getTick()); - dos.writeVariableLengthInt(dtime); - // FIXME: use running status byte - byte msg[] = me.getMessage().getMessage(); - dos.write(msg); - pme = me; - i++; - } + MidiEvent me = track.get(i); + int dtime = 0; + if (pme != null) + dtime = (int) (me.getTick() - pme.getTick()); + dos.writeVariableLengthInt(dtime); + // FIXME: use running status byte + byte msg[] = me.getMessage().getMessage(); + dos.write(msg); + pme = me; + i++; + } // We're done if the last event was an End of Track meta message. if (pme != null && (pme.getMessage() instanceof MetaMessage)) { - MetaMessage mm = (MetaMessage) pme.getMessage(); - if (mm.getType() == 0x2f) // End of Track message - return trackLength + 8; + MetaMessage mm = (MetaMessage) pme.getMessage(); + if (mm.getType() == 0x2f) // End of Track message + return trackLength + 8; } // Write End of Track meta message @@ -186,12 +186,12 @@ public class MidiFileWriter OutputStream os = new FileOutputStream(out); try { - return write(in, fileType, os); + return write(in, fileType, os); } finally { - os.close(); - } + os.close(); + } } } diff --git a/libjava/classpath/gnu/javax/sound/sampled/AU/AUReader.java b/libjava/classpath/gnu/javax/sound/sampled/AU/AUReader.java index ed5852e..fe0df6e 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/AU/AUReader.java +++ b/libjava/classpath/gnu/javax/sound/sampled/AU/AUReader.java @@ -55,11 +55,11 @@ public class AUReader extends AudioFileReader { private static class AUHeader { - // Magic number identifying the file. '.snd' + // Magic number identifying the file. '.snd' private static final int MAGIC = 0x2e736e64; - + public static final int SIZE = 24; // size of the header - + // Encoding types public static final int ULAW = 1; // 8-bit u-law public static final int PCM8 = 2; // 8-bit PCM @@ -68,10 +68,10 @@ public class AUReader extends AudioFileReader public static final int PCM32 = 5; // 32-bit PCM public static final int IEEE32 = 6; // 32-bit IEEE f.p. public static final int IEEE64 = 7; // 64-bit IEEE f.p. - public static final int G721 = 23; - public static final int G722 = 24; - public static final int G723 = 25; - public static final int G723_5BIT = 26; + public static final int G721 = 23; + public static final int G722 = 24; + public static final int G723 = 25; + public static final int G723_5BIT = 26; public static final int ALAW = 27; // 8-bit a-law // Header data. @@ -90,56 +90,56 @@ public class AUReader extends AudioFileReader ByteBuffer buf = ByteBuffer.wrap(hdr); if( buf.getInt() != MAGIC ) - throw new UnsupportedAudioFileException("Not an AU format audio file."); - headerSize = buf.getInt(); - fileSize = buf.getInt(); - encoding = buf.getInt(); + throw new UnsupportedAudioFileException("Not an AU format audio file."); + headerSize = buf.getInt(); + fileSize = buf.getInt(); + encoding = buf.getInt(); sampleRate = buf.getInt(); - channels = buf.getInt(); + channels = buf.getInt(); switch(encoding) - { - case ULAW: - case PCM8: - case ALAW: - sampleSizeInBits = 8; - break; - case PCM16: - sampleSizeInBits = 16; - break; - case PCM24: - sampleSizeInBits = 24; - break; - case PCM32: - sampleSizeInBits = 32; - break; - default: // other types exist but are not supported. Yet. - throw new UnsupportedAudioFileException("Unsupported encoding."); - } + { + case ULAW: + case PCM8: + case ALAW: + sampleSizeInBits = 8; + break; + case PCM16: + sampleSizeInBits = 16; + break; + case PCM24: + sampleSizeInBits = 24; + break; + case PCM32: + sampleSizeInBits = 32; + break; + default: // other types exist but are not supported. Yet. + throw new UnsupportedAudioFileException("Unsupported encoding."); + } } public AudioFormat getAudioFormat() { AudioFormat.Encoding encType = AudioFormat.Encoding.PCM_SIGNED; if(encoding == 1) - encType = AudioFormat.Encoding.ULAW; + encType = AudioFormat.Encoding.ULAW; if(encoding == 27) - encType = AudioFormat.Encoding.ALAW; - - return new AudioFormat(encType, - (float)sampleRate, - sampleSizeInBits, - channels, - (sampleSizeInBits >> 3) * channels, - (float)sampleRate, - true); + encType = AudioFormat.Encoding.ALAW; + + return new AudioFormat(encType, + (float)sampleRate, + sampleSizeInBits, + channels, + (sampleSizeInBits >> 3) * channels, + (float)sampleRate, + true); } public AudioFileFormat getAudioFileFormat() { - return new AudioFileFormat(new AUFormatType(), - getAudioFormat(), - AudioSystem.NOT_SPECIFIED); + return new AudioFileFormat(new AUFormatType(), + getAudioFormat(), + AudioSystem.NOT_SPECIFIED); } } @@ -160,8 +160,8 @@ public class AUReader extends AudioFileReader public AudioFileFormat getAudioFileFormat(InputStream stream) throws IOException, UnsupportedAudioFileException { - if(!stream.markSupported()) - throw new IOException("Stream must support marking."); + if(!stream.markSupported()) + throw new IOException("Stream must support marking."); stream.mark(25); AUHeader header = new AUHeader(stream); @@ -169,10 +169,10 @@ public class AUReader extends AudioFileReader return header.getAudioFileFormat(); } - + public AudioFileFormat getAudioFileFormat(URL url) throws IOException, UnsupportedAudioFileException - { + { return getAudioFileFormat(new BufferedInputStream(url.openStream())); } @@ -198,8 +198,8 @@ public class AUReader extends AudioFileReader if( header.headerSize > AUHeader.SIZE ) stream.skip(header.headerSize - AUHeader.SIZE); - return new AudioInputStream(stream, header.getAudioFormat(), - AudioSystem.NOT_SPECIFIED); + return new AudioInputStream(stream, header.getAudioFormat(), + AudioSystem.NOT_SPECIFIED); } public AudioInputStream getAudioInputStream(URL url) @@ -208,4 +208,3 @@ public class AUReader extends AudioFileReader return getAudioInputStream(new BufferedInputStream(url.openStream())); } } - diff --git a/libjava/classpath/gnu/javax/sound/sampled/WAV/WAVReader.java b/libjava/classpath/gnu/javax/sound/sampled/WAV/WAVReader.java index 0cf3c13..5cd6efe 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/WAV/WAVReader.java +++ b/libjava/classpath/gnu/javax/sound/sampled/WAV/WAVReader.java @@ -52,7 +52,7 @@ import javax.sound.sampled.spi.AudioFileReader; /** * A WAV file reader. - * + * * This code reads WAV files. * * There are many decent documents on the web describing the WAV file @@ -66,24 +66,24 @@ import javax.sound.sampled.spi.AudioFileReader; */ public class WAVReader extends AudioFileReader { - private static long readUnsignedIntLE (DataInputStream is) + private static long readUnsignedIntLE (DataInputStream is) throws IOException { byte[] buf = new byte[4]; is.readFully(buf); - return (buf[0] & 0xFF - | ((buf[1] & 0xFF) << 8) - | ((buf[2] & 0xFF) << 16) - | ((buf[3] & 0xFF) << 24)); + return (buf[0] & 0xFF + | ((buf[1] & 0xFF) << 8) + | ((buf[2] & 0xFF) << 16) + | ((buf[3] & 0xFF) << 24)); } - private static short readUnsignedShortLE (DataInputStream is) + private static short readUnsignedShortLE (DataInputStream is) throws IOException { byte[] buf = new byte[2]; is.readFully(buf); - return (short) (buf[0] & 0xFF - | ((buf[1] & 0xFF) << 8)); + return (short) (buf[0] & 0xFF + | ((buf[1] & 0xFF) << 8)); } /* Get an AudioFileFormat from the given File. @@ -115,7 +115,7 @@ public class WAVReader extends AudioFileReader din = (DataInputStream) in; else din = new DataInputStream(in); - + if (din.readInt() != 0x52494646) // "RIFF" throw new UnsupportedAudioFileException("Invalid WAV chunk header."); @@ -134,33 +134,33 @@ public class WAVReader extends AudioFileReader while (! foundData) { - int chunkId = din.readInt(); - chunkLength = readUnsignedIntLE(din); - switch (chunkId) - { - case 0x666D7420: // "fmt " - foundFmt = true; - compressionCode = readUnsignedShortLE(din); - numberChannels = readUnsignedShortLE(din); - sampleRate = readUnsignedIntLE(din); - bytesPerSecond = readUnsignedIntLE(din); - blockAlign = readUnsignedShortLE(din); - bitsPerSample = readUnsignedShortLE(din); - din.skip(chunkLength - 16); - break; - case 0x66616374: // "fact" - // FIXME: hold compression format dependent data. - din.skip(chunkLength); - break; - case 0x64617461: // "data" - if (! foundFmt) - throw new UnsupportedAudioFileException("This implementation requires WAV fmt chunks precede data chunks."); - foundData = true; - break; - default: - // Unrecognized chunk. Skip it. - din.skip(chunkLength); - } + int chunkId = din.readInt(); + chunkLength = readUnsignedIntLE(din); + switch (chunkId) + { + case 0x666D7420: // "fmt " + foundFmt = true; + compressionCode = readUnsignedShortLE(din); + numberChannels = readUnsignedShortLE(din); + sampleRate = readUnsignedIntLE(din); + bytesPerSecond = readUnsignedIntLE(din); + blockAlign = readUnsignedShortLE(din); + bitsPerSample = readUnsignedShortLE(din); + din.skip(chunkLength - 16); + break; + case 0x66616374: // "fact" + // FIXME: hold compression format dependent data. + din.skip(chunkLength); + break; + case 0x64617461: // "data" + if (! foundFmt) + throw new UnsupportedAudioFileException("This implementation requires WAV fmt chunks precede data chunks."); + foundData = true; + break; + default: + // Unrecognized chunk. Skip it. + din.skip(chunkLength); + } } AudioFormat.Encoding encoding; @@ -168,25 +168,25 @@ public class WAVReader extends AudioFileReader switch (compressionCode) { case 1: // PCM/uncompressed - if (bitsPerSample <= 8) - encoding = AudioFormat.Encoding.PCM_UNSIGNED; - else - encoding = AudioFormat.Encoding.PCM_SIGNED; - break; + if (bitsPerSample <= 8) + encoding = AudioFormat.Encoding.PCM_UNSIGNED; + else + encoding = AudioFormat.Encoding.PCM_SIGNED; + break; default: - throw new UnsupportedAudioFileException("Unrecognized WAV compression code: 0x" - + Integer.toHexString(compressionCode)); + throw new UnsupportedAudioFileException("Unrecognized WAV compression code: 0x" + + Integer.toHexString(compressionCode)); } return new AudioFileFormat (AudioFileFormat.Type.WAVE, - new AudioFormat(encoding, - (float) sampleRate, - bitsPerSample, - numberChannels, - ((bitsPerSample + 7) / 8) * numberChannels, - (float) bytesPerSecond, false), - (int) chunkLength); + new AudioFormat(encoding, + (float) sampleRate, + bitsPerSample, + numberChannels, + ((bitsPerSample + 7) / 8) * numberChannels, + (float) bytesPerSecond, false), + (int) chunkLength); } /* Get an AudioFileFormat from the given URL. diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java index aa42a4c..1910ea6 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java @@ -58,43 +58,43 @@ public class GStreamerMixer public static class GstInfo extends Info { /* Mixer Properties */ - + /** Name */ private static final String name = "Classpath GStreamer Sound Audio Engine"; - + /** Vendor */ private static final String vendor = "GNU Classpath"; - + /** Description */ private static final String desc = "GStreamer-based software mixer"; - + /** Version */ private static final String vers = "0.0.1"; - + protected GstInfo() { super(name, vendor, desc, vers); } } - + public static final String GST_BACKEND = GstInfo.name; public static final String GST_DECODER = "decoder"; public static final String GST_TYPE_NAME = "type"; public static final String GST_FILE_EXTENSION = "ext"; - + /** Mixer Info */ private static final Mixer.Info INFO = new GStreamerMixer.GstInfo(); - + public Line getLine(Line.Info info) throws LineUnavailableException { // get all the lines formats supported by this mixer and // and see if there is one matching the given line - // if the format comes from the gstreamer backend + // if the format comes from the gstreamer backend // gstreamer will be able to deal with it Class clazz = info.getLineClass(); DataLine.Info _info = (DataLine.Info) info; - + if (clazz == SourceDataLine.class) { for (AudioFormat format : _info.getFormats()) @@ -107,9 +107,9 @@ public class GStreamerMixer } } } - + // TODO: we also support basic PCM - + throw new LineUnavailableException("Cannot open a line"); } @@ -162,7 +162,7 @@ public class GStreamerMixer public boolean isLineSupported(Line.Info info) { - // We support any kind of mixer that comes + // We support any kind of mixer that comes // from our gstreamer backend. // In addition, we support PCM based audio streams for // direct playback. @@ -171,7 +171,7 @@ public class GStreamerMixer DataLine.Info _dinfo = (DataLine.Info) info; _dinfo.getFormats(); } - + return true; } @@ -228,7 +228,7 @@ public class GStreamerMixer // TODO Auto-generated method stub return false; } - + public boolean isOpen() { // TODO Auto-generated method stub diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java index 61a8940..6a0d7fa 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java @@ -43,20 +43,20 @@ import javax.sound.sampled.spi.MixerProvider; /** * Concrete provider class for GStreamerMixer. - * + * * @author Mario Torre */ public class GStreamerMixerProvider extends MixerProvider { - private static final GStreamerMixer mixer = new GStreamerMixer(); - + private static final GStreamerMixer mixer = new GStreamerMixer(); + @Override public Mixer getMixer(Info info) { - if (info.equals(mixer.getMixerInfo())) + if (info.equals(mixer.getMixerInfo())) return mixer; - + throw new IllegalArgumentException("This provider cannot handle a mixer or type: " + info.getName()); diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java index 0514c93..26fb12b 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java @@ -56,20 +56,20 @@ import javax.sound.sampled.spi.AudioFileReader; /** * An implementation of a general AudioFileReader. Uses GStreamer to - * parse and retrieve informations about the file passed as input. - * + * parse and retrieve informations about the file passed as input. + * * @author Mario Torre <neugens@limasoftware.net> */ public class GstAudioFileReader extends AudioFileReader -{ +{ @Override public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { CPStringBuilder name = new CPStringBuilder(file.getName()); String _name = name.substring(name.lastIndexOf(".") + 1); - + return getAudioFileFormat( new BufferedInputStream(new FileInputStream(file)), _name); } @@ -93,30 +93,30 @@ public class GstAudioFileReader { UnsupportedAudioFileException ex = new UnsupportedAudioFileException("Unsupported encoding."); - + ex.initCause(ex.getCause()); throw ex; } - + if (format == null) throw new UnsupportedAudioFileException("Unsupported encoding."); - + String name = format.getProperty(GStreamerMixer.GST_DECODER).toString(); - + if (extension == null) { extension = format.getProperty(GStreamerMixer.GST_FILE_EXTENSION).toString(); } - + AudioFileFormat.Type type = new AudioFileFormat.Type(name, extension); - + // TODO: we should calculate this in some way. We don't need it, but // application may want to use this data. return new AudioFileFormat(type, format, AudioSystem.NOT_SPECIFIED); } - + @Override public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException @@ -127,12 +127,12 @@ public class GstAudioFileReader @Override public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException - { + { InputStream stream = new FileInputStream(file); long length = file.length(); - + AudioFormat format = null; - + try { format = GstAudioFileReaderNativePeer.getAudioFormat(file); @@ -141,11 +141,11 @@ public class GstAudioFileReader { UnsupportedAudioFileException ex = new UnsupportedAudioFileException("Unsupported encoding."); - + ex.initCause(ex.getCause()); throw ex; } - + // get the header size if (format == null) throw new UnsupportedAudioFileException("Unsupported encoding."); @@ -158,7 +158,7 @@ public class GstAudioFileReader throws UnsupportedAudioFileException, IOException { AudioFormat format = null; - + try { format = GstAudioFileReaderNativePeer.getAudioFormat(is); @@ -168,7 +168,7 @@ public class GstAudioFileReader // TODO Auto-generated catch block e.printStackTrace(); } - + // get the header size if (format == null) throw new UnsupportedAudioFileException("Unsupported encoding."); diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java index 761720f..6345d76 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java @@ -54,30 +54,30 @@ import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioFormat.Encoding; /** - * GStreamer native peer for GstAudioFileReader. - * + * GStreamer native peer for GstAudioFileReader. + * * @author Mario Torre <neugens@limasoftware.net> */ final class GstAudioFileReaderNativePeer { private static final String GST_ENCODING = "GStreamer Generic Audio Reader"; - + private static class GstHeader { - /* + /* * NOTE: these properties are accessed by the native code, be careful * if you change them. * Not all the fields are necessarily set. - * + * */ public String file = null; - + public String suffix = null; - + public String name = null; - + public String mimetype = null; - + public String endianness = null; public String channels = null; @@ -87,62 +87,62 @@ final class GstAudioFileReaderNativePeer public String width = null; public String depth = null; - + public String isSigned = null; - + public String layer = null; - + public String bitrate = null; - + public String framed = null; - + public String type = null; } - + public static AudioFormat getAudioFormat(File file) throws Exception { GstHeader header = new GstHeader(); header.file = file.getAbsolutePath(); - + if (!gstreamer_get_audio_format_file(header)) return null; - + return getAudioFormat(header); } - + public static AudioFormat getAudioFormat(InputStream is) throws Exception { return getAudioFormat(is, new GstHeader()); } - + public static AudioFormat getAudioFormat(URL url) throws Exception { GstHeader header = new GstHeader(); header.file = url.toExternalForm(); - + return getAudioFormat(url.openStream(), header); } - + private static AudioFormat getAudioFormat(InputStream is, GstHeader header) throws Exception { BufferedInputStream stream = new BufferedInputStream(is); - if(!stream.markSupported()) - throw new IOException("Stream must support marking."); - + if(!stream.markSupported()) + throw new IOException("Stream must support marking."); + stream.mark(0); - + if (!gstreamer_get_audio_format_stream(header, new GstInputStream(stream). getNativeClass())) return null; - + return getAudioFormat(header); } - + private static Encoding getEncoding(GstHeader header) { StringBuilder buffer = new StringBuilder(); - + if (header.name == null) { buffer.append(GST_ENCODING); @@ -151,7 +151,7 @@ final class GstAudioFileReaderNativePeer buffer.append(" "); buffer.append(header.mimetype); } - + header.name = buffer.toString(); } else @@ -165,47 +165,47 @@ final class GstAudioFileReaderNativePeer { index = lowerCase.indexOf("demuxer"); } - + if (index == -1) index = lowerCase.length(); buffer.append(header.name.substring(0, index)); - + } - + return new Encoding(buffer.toString().trim()); } - + private static AudioFormat getAudioFormat(GstHeader header) throws Exception { int na = AudioSystem.NOT_SPECIFIED; - + /* we use mimetype as an header, but this could have some side effects */ Encoding encoding = getEncoding(header); - + float sampleRate = ((header.rate != null) ? new Float(header.rate).floatValue() : na); - + int sampleSizeInBits = ((header.depth != null) ? new Integer(header.depth).intValue() : na); - + int channels = ((header.channels != null) ? new Integer(header.channels).intValue() : na); - + boolean bigEndian = false; if (header.endianness != null) { if (header.endianness.compareTo("4321") == 0) bigEndian = true; } - + String ext = null; - + int frameSize = na; float frameRate = na; String lowerCase = header.name.toLowerCase(); - + // FIXME: frameRate = sampleRate in these cases under all the tests so far // but I'm not sure if this is always correct... if (lowerCase.contains("law") || lowerCase.contains("au")) @@ -226,7 +226,7 @@ final class GstAudioFileReaderNativePeer frameRate = sampleRate; ext = "aiff"; } - + // write all the additional properties we got to identify // the gstreamer plugin actually used to deal with this stream Map<String, Object> properties = new HashMap<String, Object>(); @@ -235,7 +235,7 @@ final class GstAudioFileReaderNativePeer properties.put(GStreamerMixer.GST_TYPE_NAME, encoding.toString()); if (ext != null) properties.put(GStreamerMixer.GST_FILE_EXTENSION, ext); - + /* now we put in some of the additional properties if we have them */ if (header.type != null) properties.put("type", header.type); if (header.framed != null) properties.put("framed", header.framed); @@ -243,7 +243,7 @@ final class GstAudioFileReaderNativePeer if (header.isSigned != null) properties.put("isSigned", header.isSigned); if (header.depth != null) properties.put("depth", header.depth); if (header.mimetype != null) properties.put("mimetype", header.mimetype); - + AudioFormat format = new AudioFormat(encoding, sampleRate, sampleSizeInBits, @@ -254,28 +254,28 @@ final class GstAudioFileReaderNativePeer properties); return format; } - + /* ***** native methods ***** */ - + /** * Retrieve header information about the stream being played. */ native static final protected boolean gstreamer_get_audio_format_stream(GstHeader info, Pointer pointer); - + /** * Retrieve header information about the file being played. */ native static final protected boolean gstreamer_get_audio_format_file(GstHeader info); - + /** * Initialize the native peer and enables the object cache. * It is meant to be used by the static initializer. */ native private static final void init_id_cache(); - + static { System.loadLibrary("gstreamerpeer"); //$NON-NLS-1$ diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstInputStream.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstInputStream.java index 0702ede..56bddca 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstInputStream.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/io/GstInputStream.java @@ -45,66 +45,66 @@ import java.io.InputStream; /** * Encapsulates the functionality of an InputStream Object. - * + * * This class is only meant to be used by the native code, to allow reading * of the given InputStream as part of a the GStreamer InputStream Source * Plugin. - * + * * <strong>Note:</strong> this class will be not garbage collected as the * native code contains strong references to internal fields. * The native layer provides a method that can be called by the C code to * free the resources and to let the garbage collected to handle this class * when not needed anymore. - * + * * @author Mario Torre <neugens@limasoftware.net> */ public class GstInputStream { /** The real InputStream on which to perform reading operations. */ private InputStream istream; - + /** - * Initialized in the native code, don't change without changes + * Initialized in the native code, don't change without changes * in the native layer. */ private Pointer gstInputStream = null; - + public GstInputStream(InputStream istream) { this.istream = istream; init_instance(); } - + public int read(byte[] buf, int off, int len) throws IOException { return this.istream.read(buf, off, len); } - + public int available() throws IOException { return this.istream.available(); } - + /** * Return a reference to the GstInputStream native class as a Pointer object. * This method is intended as an helper accessor and the returned pointer - * needs to be casted and used in the native code only. - * + * needs to be casted and used in the native code only. + * * @return Pointer to the native GstInputStream class. */ public Pointer getNativeClass() { return this.gstInputStream; } - + /* native methods */ - + /** * Initialize the native peer and enables the object cache. * It is meant to be used by the class constructor. */ native private final void init_instance(); - + /** * Initialize the native peer and enables the object cache. * It is meant to be used by the static initializer. diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java index 33be15c..4e8cb1b 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java @@ -47,19 +47,19 @@ public abstract class GstDataLine implements DataLine { public static final int DEFAULT_BUFFER_SIZE = 1024; - + /** Represents if this Line is opened or not. */ - protected Boolean open = false; - + protected Boolean open = false; + private AudioFormat format = null; private int bufferSize = 0; - + public GstDataLine(AudioFormat format) { this.format = format; this.bufferSize = DEFAULT_BUFFER_SIZE; } - + public GstDataLine(AudioFormat format, int bufferSize) { this.format = format; @@ -81,7 +81,7 @@ public abstract class GstDataLine // TODO Auto-generated method stub return 0; } - + public void addLineListener(LineListener listener) { // TODO Auto-generated method stub @@ -124,7 +124,7 @@ public abstract class GstDataLine } /* protected methods for subclasses */ - + /** * @param open the open to set */ diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java index 84007ac..896f0cb 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java @@ -42,22 +42,22 @@ import gnu.classpath.Pointer; import javax.sound.sampled.LineUnavailableException; public class GstNativeDataLine -{ +{ public static final GstPipeline createSourcePipeline(int bufferSize) throws LineUnavailableException { GstPipeline pipeline = new GstPipeline(bufferSize); - + pipeline.createForWrite(); - + if (!setup_sink_pipeline(pipeline.getNativeClass())) throw new LineUnavailableException("Line unavailable"); - + return pipeline; } - + /* native methods */ - + /** * Initialize the native peer and enables the object cache. * It is meant to be used by the static initializer. diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java index f561f71..9280e9f 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java @@ -48,7 +48,7 @@ import gnu.classpath.Pointer; /** * This class represent a GStreamer pipeline and is resposible to handle the * flow of data to and from the GStreamer native backend. - * + * * @author Mario Torre <neugens@limasoftware.net> */ public class GstPipeline @@ -69,52 +69,52 @@ public class GstPipeline * Opening the pipe to record audio data from the sound card works the same * except that all the operation are inverted. */ - + // These enums are used in the native code also, changes here must reflect // changes in the native code. public static enum State { PLAY, PAUSE, STOP, CLOSE } - + private static final int READ = 0; private static final int WRITE = 1; private static final int QUEUED = 1; - - private static final String CAPACITY_KEY = "Capacity"; - + + private static final String CAPACITY_KEY = "Capacity"; + private static final Object [] lock = new Object[0]; - + /* * Preference subsystem. We use this to store some system specific settings. */ protected Preferences prefs = Preferences.userNodeForPackage(GstPipeline.class).node("GStreamer"); - + // used by the native code, stores the size of the named pipeline // created by the operating system. private long capacity = -1; - + /** Represents the playing state of this Line. */ private State state = State.STOP; - + /** The name of the named pipe. */ // Will be setup and filled in the native code. See the native library // for details. private String name = null; - + /** This is the named pipe that will be read by the gstreamer backend. */ private FileOutputStream output = null; - + /** * Defines if we are getting data from a sink pipe * or writing to a source pipe. */ private boolean source = true; - + /** Indicate that we are ready to process audio data to/from the pipe. */ private boolean ready = false; - + /** * This is the native GStreamer Pipeline. */ @@ -125,20 +125,20 @@ public class GstPipeline /** * Creates a new GstPipeline with a capacity of * {@link GstDataLine#DEFAULT_BUFFER_SIZE}. - * + * * @see GstDataLine#DEFAULT_BUFFER_SIZE */ public GstPipeline() { this(GstDataLine.DEFAULT_BUFFER_SIZE); } - + /** * Creates a new GstPipeline with a capacity of bufferSize. * @see GstDataLine#DEFAULT_BUFFER_SIZE */ public GstPipeline(int bufferSize) - { + { // see if we need to detect the size of the named pipe or we can use // an already computet default for this system. // Note that this is very different from the bufferSize parameter, @@ -150,35 +150,35 @@ public class GstPipeline { capacity = detect_pipe_size(); } - + prefs.putLong(CAPACITY_KEY, capacity); } - + // FIXME: bufferSize actually not used nor needed by the backend. // Applications that expects a buffer of different size will be a // bit disappointed by that.. init_instance(); - + // need to remove the named pipe in case of abnormal termination Runtime.getRuntime().addShutdownHook(new CleanPipeline()); } - + /** * Creates a source pipeline. A source pipeline is a pipe you send data for * processing using the write method. */ public void createForWrite() throws LineUnavailableException - { + { // create the named pipe if (!create_named_pipe(this.pipeline)) throw new LineUnavailableException("Unable to create filesystem pipe"); - + open_native_pipe(this.pipeline, READ); prepareWrite(); - + this.source = true; } - + /** * @return the state */ @@ -195,7 +195,7 @@ public class GstPipeline { setState(State.STOP); } - + /** * @param state the state to set */ @@ -211,7 +211,7 @@ public class GstPipeline case PAUSE: _state = 1; break; - + case STOP: case CLOSE: _state = 2; closePipe(); @@ -221,38 +221,38 @@ public class GstPipeline if (set_state(pipeline, _state)) GstPipeline.this.state = state; } - + /** * Return a reference to the GstPipeline native class as a Pointer object. * This method is intended as an helper accessor and the returned pointer - * needs to be casted and used in the native code only. - * + * needs to be casted and used in the native code only. + * * @return Pointer to the native GstPipeline class. */ public Pointer getNativeClass() { return this.pipeline; } - + /** * Write length bytes from the given buffer into this pipeline, * starting at offset. - * This method block if the pipeline can't accept more data. - * + * This method block if the pipeline can't accept more data. + * * @param buffer * @param offset * @param length * @return */ public int write(byte[] buffer, int offset, int length) - { + { if (this.state == State.STOP) return -1; else if (this.state == State.PAUSE) return 0; else if (!ready) return -1; - + try { if (output != null) @@ -266,15 +266,15 @@ public class GstPipeline { /* nothing to do */ } - + return -1; } - + public int read(byte[] buffer, int offset, int length) { return 0; } - + public int available() { if (this.source) @@ -282,7 +282,7 @@ public class GstPipeline else return available(this.pipeline, WRITE); } - + /** * Wait for remaining data to be enqueued in the pipeline. */ @@ -290,13 +290,13 @@ public class GstPipeline { if (this.state == State.STOP) return; - + try { // wait untill there is anymore data in the pipe while (available(this.pipeline, QUEUED) > 0) Thread.sleep(3000); - + // plus a bit to allow data to be processed Thread.sleep(1000); } @@ -305,7 +305,7 @@ public class GstPipeline /* nothing to do*/ } } - + /** * Flush all the data currently waiting to be processed. */ @@ -321,7 +321,7 @@ public class GstPipeline /* nothing */ } } - + private void closePipe() { try @@ -335,7 +335,7 @@ public class GstPipeline /* nothing to do */ } } - + private void prepareWrite() { try @@ -351,54 +351,54 @@ public class GstPipeline GstPipeline.this.ready = false; } } - + /* ***** native ***** */ - + /** * Initialize the native peer and enables the object cache. * It is meant to be used by the static initializer. */ native private static final void init_id_cache(); - + /** * Set the playing state of this pipeline. */ native private static final boolean set_state(Pointer pipeline, int state); - + /** * Get the number of bytes currently available for reading or writing * from the pipeline. */ native private static final int available(Pointer pipeline, int mode); - + /** * Open the native pipeline with the given mode. */ native private static final void open_native_pipe(Pointer jpipeline, int mode); - + /** * Close the native pipeline. */ native private static final void close_native_pipe(Pointer jpipeline); - + /** * Initialize the native peer and enables the object cache. * It is meant to be used by the class constructor. */ native private final void init_instance(); - + /** * Crates the named pipe used to pass data between the application code * and gstreamer. */ native private final boolean create_named_pipe(Pointer jpipeline); - + /** * Detect and return the size of the filesystem named pipe. */ native private final long detect_pipe_size(); - + private class CleanPipeline extends Thread { public void run() @@ -406,7 +406,7 @@ public class GstPipeline GstPipeline.close_native_pipe(GstPipeline.this.pipeline); } } - + static { System.loadLibrary("gstreamerpeer"); //$NON-NLS-1$ diff --git a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java index f149ab3..2bc2de4 100644 --- a/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java +++ b/libjava/classpath/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java @@ -51,7 +51,7 @@ public class GstSourceDataLine { private GstPipeline pipeline = null; private boolean open = false; - + public GstSourceDataLine(AudioFormat format) { super(format); @@ -60,20 +60,20 @@ public class GstSourceDataLine public void open() throws LineUnavailableException { AudioSecurityManager.checkPermissions(Permission.PLAY); - + if (open) throw new IllegalStateException("Line already opened"); - + // create the pipeline pipeline = GstNativeDataLine.createSourcePipeline(getBufferSize()); - + this.open = true; } - + public void open(AudioFormat fmt) throws LineUnavailableException { AudioSecurityManager.checkPermissions(Permission.PLAY); - + setFormat(fmt); this.open(); } @@ -81,13 +81,13 @@ public class GstSourceDataLine public void open(AudioFormat fmt, int size) throws LineUnavailableException { AudioSecurityManager.checkPermissions(Permission.PLAY); - + setBufferSize(size); this.open(fmt); } public int write(byte[] buf, int offset, int length) - { + { return this.pipeline.write(buf, offset, length); } @@ -145,7 +145,7 @@ public class GstSourceDataLine pipeline.close(); this.open = false; } - + public boolean isRunning() { return (pipeline.getState() == State.PLAY); |