diff --git a/DEPS b/DEPS index b3808f48..a0ae578f 100644 --- a/DEPS +++ b/DEPS @@ -4,7 +4,7 @@ - java 1.6 - lwjgl 2.8.5 , lwjgl.org ( BSD License) -- jorbis 0.0.17 , www.jcraft.com/jorbis ( GNU LGPL) - jChardet 1.1, jchardet.sourceforge.net ( MOZILLA PUBLIC LICENSE) - voile, github.com/chaosfox/voile +- NativeFmodEx, jerome.jouvie.free.fr/nativefmodex (binding LGPL & lib FMOD Non-Commercial License - fmod.com/fmod-sales.html) diff --git a/lib/jlayer-1.0.1-libgdx.jar b/lib/jlayer-1.0.1-libgdx.jar deleted file mode 100644 index 2a58f571..00000000 Binary files a/lib/jlayer-1.0.1-libgdx.jar and /dev/null differ diff --git a/lib/jorbis.jar b/lib/jorbis.jar deleted file mode 100644 index 75122d65..00000000 Binary files a/lib/jorbis.jar and /dev/null differ diff --git a/nbproject/project.properties b/nbproject/project.properties index 8e026f41..c8a2a6c5 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -28,9 +28,7 @@ endorsed.classpath= excludes= file.reference.chardet.jar=lib/chardet.jar file.reference.jinput.jar=lib\\jinput.jar -file.reference.jlayer-1.0.1-libgdx.jar=lib/jlayer-1.0.1-libgdx.jar file.reference.jna-3.4.0.jar=lib/jna-3.4.0.jar -file.reference.jorbis.jar=lib\\jorbis.jar file.reference.lwjgl.jar=lib\\lwjgl.jar file.reference.lwjgl_util.jar=lib\\lwjgl_util.jar file.reference.lzma.jar=lib\\lzma.jar @@ -45,7 +43,6 @@ jar.compress=true jar.index=${jnlp.enabled} javac.classpath=\ ${file.reference.jinput.jar}:\ - ${file.reference.jorbis.jar}:\ ${file.reference.lwjgl.jar}:\ ${file.reference.lwjgl_util.jar}:\ ${file.reference.lzma.jar}:\ @@ -54,7 +51,6 @@ javac.classpath=\ ${file.reference.vlcj-2.0.0.jar}:\ ${file.reference.chardet.jar}:\ ${file.reference.voile.jar}:\ - ${file.reference.jlayer-1.0.1-libgdx.jar}:\ ${reference.open2jam-parsers.jar}:\ ${file.reference.NativeFmodEx.jar}:\ ${file.reference.partytime.jar} diff --git a/parsers/src/org/open2jam/parsers/BMSParser.java b/parsers/src/org/open2jam/parsers/BMSParser.java index 03a7bfc8..e7bdb459 100644 --- a/parsers/src/org/open2jam/parsers/BMSParser.java +++ b/parsers/src/org/open2jam/parsers/BMSParser.java @@ -286,7 +286,7 @@ public static EventList parseChart(BMSChart chart) lines.get(measure).add(line); } } catch (IOException ex) { - Logger.global.log(Level.SEVERE, null, ex); + Logger.global.log(Level.SEVERE, "{0}", ex); } Iterator> it = lines.values().iterator(); @@ -488,7 +488,7 @@ public static HashMap getSamples(BMSChart chart) } } } catch (IOException ex) { - Logger.global.log(Level.SEVERE, null, ex); + Logger.global.log(Level.SEVERE, "{0}", ex); } } return samples; diff --git a/parsers/src/org/open2jam/parsers/SMParser.java b/parsers/src/org/open2jam/parsers/SMParser.java index 06fd5014..b807644c 100644 --- a/parsers/src/org/open2jam/parsers/SMParser.java +++ b/parsers/src/org/open2jam/parsers/SMParser.java @@ -304,7 +304,7 @@ public static EventList parseChart(SMChart chart) } } } catch (IOException ex) { - Logger.global.log(Level.SEVERE, null, ex); + Logger.global.log(Level.SEVERE, "{0}", ex); } catch(NoSuchElementException ignored) {} //add the music @@ -341,7 +341,7 @@ public static HashMap getSamples(SMChart chart) } } } catch (IOException ex) { - Logger.global.log(Level.SEVERE, null, ex); + Logger.global.log(Level.SEVERE, "{0}", ex); } } return samples; diff --git a/parsers/src/org/open2jam/parsers/utils/KrazyRainDB.java b/parsers/src/org/open2jam/parsers/utils/KrazyRainDB.java index c3019ccf..65e002c9 100644 --- a/parsers/src/org/open2jam/parsers/utils/KrazyRainDB.java +++ b/parsers/src/org/open2jam/parsers/utils/KrazyRainDB.java @@ -145,12 +145,12 @@ private void load() { try { SAXParserFactory.newInstance().newSAXParser().parse(resources_xml.openStream(), this); } catch (ParserConfigurationException ex) { - java.util.logging.Logger.getLogger(KrazyRainDB.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(KrazyRainDB.class.getName()).log(Level.SEVERE, "{0}", ex); } } catch (SAXException ex) { - java.util.logging.Logger.getLogger(KrazyRainDB.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(KrazyRainDB.class.getName()).log(Level.SEVERE, "{0}", ex); } catch (IOException ex) { - java.util.logging.Logger.getLogger(KrazyRainDB.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(KrazyRainDB.class.getName()).log(Level.SEVERE, "{0}", ex); } } diff --git a/src/org/open2jam/Config.java b/src/org/open2jam/Config.java index 762451c5..94a86af4 100644 --- a/src/org/open2jam/Config.java +++ b/src/org/open2jam/Config.java @@ -39,8 +39,10 @@ private static GameOptions loadGameOptions() { Object result = decoder.readObject(); decoder.close(); if (result instanceof GameOptions) return (GameOptions)result; + } catch(FileNotFoundException fnf) { + return null; // thats ok a new file will be created } catch (IOException ex) { - Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(Config.class.getName()).log(Level.SEVERE, "{0}", ex); } return null; } @@ -51,7 +53,7 @@ public static void saveGameOptions() { encoder.writeObject(options); encoder.close(); } catch (IOException ex) { - Logger.getLogger(GameOptions.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(GameOptions.class.getName()).log(Level.SEVERE, "{0}", ex); } } diff --git a/src/org/open2jam/gui/Interface.java b/src/org/open2jam/gui/Interface.java index b9da6020..efb75f3b 100644 --- a/src/org/open2jam/gui/Interface.java +++ b/src/org/open2jam/gui/Interface.java @@ -29,6 +29,7 @@ public Interface() { Tabs.addTab("Configuration", new Configuration()); this.addWindowListener(this); + pack(); } diff --git a/src/org/open2jam/gui/parts/MusicSelection.form b/src/org/open2jam/gui/parts/MusicSelection.form index b32498ea..45eea7f0 100644 --- a/src/org/open2jam/gui/parts/MusicSelection.form +++ b/src/org/open2jam/gui/parts/MusicSelection.form @@ -212,6 +212,9 @@ + + + diff --git a/src/org/open2jam/gui/parts/MusicSelection.java b/src/org/open2jam/gui/parts/MusicSelection.java index f9ffa6c1..e1f66a39 100644 --- a/src/org/open2jam/gui/parts/MusicSelection.java +++ b/src/org/open2jam/gui/parts/MusicSelection.java @@ -135,6 +135,7 @@ public String toString() { public MusicSelection() { initLogic(); initComponents(); + load_progress.setVisible(false); List list = Config.getDirsList(); for(File f : list)combo_dirs.addItem(new FileItem(f)); @@ -155,7 +156,6 @@ public MusicSelection() { else loadDir(cwd); - load_progress.setVisible(false); table_sorter = new TableRowSorter(model_songlist); table_songlist.setRowSorter(table_sorter); txt_filter.getDocument().addDocumentListener(new DocumentListener() { @@ -204,7 +204,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { try { BMSWriter.export(selected_header, "converted"); } catch (IOException ex) { - java.util.logging.Logger.getLogger(MusicSelection.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(MusicSelection.class.getName()).log(Level.SEVERE, "{0}", ex); } finally { System.gc(); } @@ -293,7 +293,7 @@ private void initComponents() { bt_choose_dir = new javax.swing.JButton(); load_progress = new javax.swing.JProgressBar(); jLabel2 = new javax.swing.JLabel(); - combo_dirs = new javax.swing.JComboBox(); + combo_dirs = new javax.swing.JComboBox(); btn_reload = new javax.swing.JButton(); btn_delete = new javax.swing.JButton(); panel_setting = new javax.swing.JPanel(); @@ -1177,7 +1177,7 @@ public void autosyncFinished(double audioLatency) { new RenderThread(this.getTopLevelAncestor(), r).start(); } catch (SoundSystemException ex) { - java.util.logging.Logger.getLogger(MusicSelection.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(MusicSelection.class.getName()).log(Level.SEVERE, "{0}", ex); } }//GEN-LAST:event_bt_playActionPerformed @@ -1285,7 +1285,7 @@ private void btnCreateServerActionPerformed(java.awt.event.ActionEvent evt) {//G private javax.swing.JCheckBox cb_autoSyncDisplay; private javax.swing.JCheckBox cb_startPaused; private javax.swing.JComboBox combo_channelModifier; - private javax.swing.JComboBox combo_dirs; + private javax.swing.JComboBox combo_dirs; private javax.swing.JComboBox combo_displays; private javax.swing.JComboBox combo_speedType; private javax.swing.JComboBox combo_visibilityModifier; diff --git a/src/org/open2jam/render/Render.java b/src/org/open2jam/render/Render.java index 7122341e..e43f9164 100644 --- a/src/org/open2jam/render/Render.java +++ b/src/org/open2jam/render/Render.java @@ -514,7 +514,7 @@ public void initialise() Sprite s = ResourceFactory.get().getSprite(img); bga_sprites.put(entry.getKey(), s); } catch (IOException ex) { - java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, "{0}", ex); } } } @@ -539,12 +539,12 @@ public void initialise() Sound sound = soundSystem.load(sampleData); sounds.put(entry.getKey(), sound); } catch (SoundSystemException ex) { - java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, "{0}", ex); } try { entry.getValue().dispose(); } catch (IOException ex) { - java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, "{0}", ex); } } @@ -1088,7 +1088,7 @@ public SoundInstance queueSample(Event.SoundSample soundSample) return sound.play(soundSample.isBGM() ? SoundChannel.BGM : SoundChannel.KEY, 1.0f, soundSample.pan); } catch (SoundSystemException ex) { - java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(Render.class.getName()).log(Level.SEVERE, "{0}", ex); return null; } } diff --git a/src/org/open2jam/render/lwjgl/LWJGLGameWindow.java b/src/org/open2jam/render/lwjgl/LWJGLGameWindow.java index f592040a..f625867a 100644 --- a/src/org/open2jam/render/lwjgl/LWJGLGameWindow.java +++ b/src/org/open2jam/render/lwjgl/LWJGLGameWindow.java @@ -112,7 +112,7 @@ public void startRendering() try { Display.create(); } catch (LWJGLException ex) { - Logger.global.log(Level.SEVERE, null, ex); + Logger.global.log(Level.SEVERE, "{0}", ex); callback.windowClosed(); return; } diff --git a/src/org/open2jam/render/lwjgl/SoundManager.java b/src/org/open2jam/render/lwjgl/SoundManager.java deleted file mode 100644 index cfff4b81..00000000 --- a/src/org/open2jam/render/lwjgl/SoundManager.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.open2jam.render.lwjgl; - -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.util.ArrayList; -import org.lwjgl.BufferUtils; -import org.lwjgl.LWJGLException; -import org.lwjgl.openal.AL; -import org.lwjgl.openal.AL10; -import org.open2jam.util.Logger; -import org.open2jam.sound.Sample; - -/** - this class is the bridge between OpenAL and the app. - http://lwjgl.org/documentation_openal_06.php -*/ -public class SoundManager -{ - - private static final ArrayList sample_buffer = new ArrayList(); - private static final ArrayList source_buffer = new ArrayList(); - - - // we need to initialize the OpenAL context - static { - try { - AL.create(); - - AL10.alGetError(); - FloatBuffer listenerPos = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }); - FloatBuffer listenerVel = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }); - FloatBuffer listenerOri = BufferUtils.createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f }); - - listenerPos.flip(); - listenerVel.flip(); - listenerOri.flip(); - - AL10.alListener(AL10.AL_POSITION, listenerPos); - AL10.alListener(AL10.AL_VELOCITY, listenerVel); - AL10.alListener(AL10.AL_ORIENTATION, listenerOri); - - } catch (LWJGLException ex) { - Logger.global.severe("Could not initialize the OpenAL context !!"); - } - } - - public static void setGain(int source, float g) - { - AL10.alSourcef(source, AL10.AL_GAIN, g); - } - - public static float getGain(int source) - { - return AL10.alGetSourcef(source, AL10.AL_GAIN); - } - - private static final FloatBuffer pan_pos_buffer = BufferUtils.createFloatBuffer(3); - public static void setPan(int source, float x) - { - pan_pos_buffer.put(new float[] { x, 0.0f, 0.0f }).flip(); - AL10.alSource(source, AL10.AL_POSITION, pan_pos_buffer); - } - - public static int newSource() - { - IntBuffer source = BufferUtils.createIntBuffer(1); - - // Generate a source. - AL10.alGenSources(source); - - org.lwjgl.openal.Util.checkALError(); - - FloatBuffer sourcePos = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }); - FloatBuffer sourceVel = BufferUtils.createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f }); - - sourcePos.flip(); - sourceVel.flip(); - - // Setup the source properties. -// AL10.alSourcei(source.get(0), AL10.AL_BUFFER, buffer ); - AL10.alSourcef(source.get(0), AL10.AL_PITCH, 1.0f ); - AL10.alSourcef(source.get(0), AL10.AL_GAIN, 1.0f ); - AL10.alSource (source.get(0), AL10.AL_POSITION, sourcePos ); - AL10.alSource (source.get(0), AL10.AL_VELOCITY, sourceVel ); - AL10.alSourcei(source.get(0), AL10.AL_LOOPING, AL10.AL_FALSE ); - - // Save the source id. - source_buffer.add(source.get(0)); - - // Return the source id. - return source.get(0); - } - - public static boolean isPlaying(int source) - { - return AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING; - } - - public static void play(int source, int buffer) - { - AL10.alSourcei(source, AL10.AL_BUFFER,buffer); - AL10.alSourcePlay(source); - } - public static void stop(int source) - { - AL10.alSourceStop(source); - } - - public static int newBuffer(Sample data) - { - IntBuffer id_buf = BufferUtils.createIntBuffer(1); - AL10.alGenBuffers(id_buf); - - org.lwjgl.openal.Util.checkALError(); - int format = -1; - switch(data.format) - { - case MONO8: format = AL10.AL_FORMAT_MONO8; break; - case MONO16: format = AL10.AL_FORMAT_MONO16; break; - case STEREO8: format = AL10.AL_FORMAT_STEREO8; break; - case STEREO16: format = AL10.AL_FORMAT_STEREO16; break; - } - - AL10.alBufferData(id_buf.get(0), format, data.data, data.samplerate); - - org.lwjgl.openal.Util.checkALError(); - - sample_buffer.add(id_buf.get(0)); - return id_buf.get(0); - } - - public static void killData() - { - IntBuffer scratch = BufferUtils.createIntBuffer(1); - // Release all source data. - for (Integer aSource_buffer : source_buffer) { - scratch.put(0, aSource_buffer); - AL10.alSourceStop(scratch); - AL10.alDeleteSources(scratch); - } - source_buffer.clear(); - - for (Integer aSample_buffer : sample_buffer) { - scratch.put(0, aSample_buffer); - AL10.alDeleteBuffers(scratch); - } - sample_buffer.clear(); - } - - public static void mainVolume(float vol) - { - AL10.alListenerf(AL10.AL_GAIN, vol); - } -} diff --git a/src/org/open2jam/sound/FmodExSoundSystem.java b/src/org/open2jam/sound/FmodExSoundSystem.java index 0c37a34e..5bebb496 100644 --- a/src/org/open2jam/sound/FmodExSoundSystem.java +++ b/src/org/open2jam/sound/FmodExSoundSystem.java @@ -85,7 +85,7 @@ public org.open2jam.sound.Sound load(SampleData data) throws SoundSystemExceptio try { data.copyTo(out); } catch (IOException ex) { - Logger.getLogger(FmodExSoundSystem.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(FmodExSoundSystem.class.getName()).log(Level.SEVERE, "{0}", ex); return null; } diff --git a/src/org/open2jam/sound/Sample.java b/src/org/open2jam/sound/Sample.java deleted file mode 100644 index beec2315..00000000 --- a/src/org/open2jam/sound/Sample.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.open2jam.sound; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.logging.Level; -import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.AudioSystem; -import javazoom.jl.decoder.*; -import org.open2jam.parsers.utils.ByteHelper; -import org.open2jam.parsers.utils.Logger; -import org.open2jam.parsers.utils.SampleData; -import org.open2jam.util.OggInputStream; - -/** - * - * @author CdK - */ -public class Sample { - - public enum Format { MONO8, STEREO8, MONO16, STEREO16, FLOAT32 }; - public enum Method { STREAM_FROM_FILE, COPY_TO_MEMORY }; //TODO do this D: - - public final ByteBuffer data; - public final Format format; - public final int samplerate; - - private Sample(ByteBuffer data, Format format, int samplerate) - { - this.data = data; - this.format = format; - this.samplerate = samplerate; - } - - /** - * Dispose the data - */ - public void dispose() - { - data.clear(); - } - - /* - * Decode a SampleData using his type - */ - public static Sample decode(SampleData data) { - switch(data.getType()) { - case MP3: - return Sample.decodeMP3(data); - case OGG: - return Sample.decodeOGG(data); - case WAV: - case WAV_NO_HEADER: - return Sample.decodeWAV(data); - default: - return null; - } - } - - /** - * Creates a new SampleData from an uncompressed ByteBuffer - * @param buffer The ByteBuffer - * @param bits The numbers of bits per channel - * @param channels The number of channels - * @param samplerate The sample rate - * @param type The type of the sampled data - * @return A new SampleData - */ - public static Sample create(ByteBuffer data, int bits, int channels, int samplerate) - { - Format format; - if(channels == 1){ - format = bits == 8 ? Format.MONO8 : Format.MONO16; - }else{ - format = bits == 8 ? Format.STEREO8 : Format.STEREO16; - } - - - return new Sample(data, format, samplerate); - } - - /** - * Creates a new SampleData from an OggInputStream - * @param ois The OggInputStream - * @return a new SampleData - */ - public static Sample decodeOGG(SampleData ad) - { - try - { - OggInputStream ois = new OggInputStream((ad.getInputStream())); - - Format format = ois.getFormat() == OggInputStream.FORMAT_MONO16 ? - Format.MONO16 : Format.STEREO16; - int samplerate = ois.getRate(); - - ByteArrayOutputStream out = new ByteArrayOutputStream(ByteHelper.tmp_buffer.length); - - ByteHelper.copyTo(ois, out); - - ByteBuffer b = ByteBuffer.allocateDirect(out.size()); - b.put(out.toByteArray()); - b.flip(); - - ois.close(); - - return new Sample(b, format, samplerate); - - } catch(IOException e) { - Logger.global.log(Level.SEVERE, "Exception creating AudioData(OGG) : {0}", e.getMessage()); - return null; - } - } - - public static Sample decodeWAV(SampleData ad) - { - if(ad.getWAVHeader() == null) - return decode_wav(ad); - else - return decode_raw(ad); - } - - /** - * Creates a new SampleData from an InputStream (Only PCM uncompressed WAVE files please) - * @param wav The InputStream - * @return a new SampleData - */ - private static Sample decode_wav(SampleData ad) - { - try { - AudioInputStream ais = AudioSystem.getAudioInputStream(ad.getInputStream()); - AudioFormat audioformat = ais.getFormat(); - - ByteArrayOutputStream out = new ByteArrayOutputStream(ByteHelper.tmp_buffer.length); - - ByteHelper.copyTo(ais, out); - - ByteBuffer b = ByteBuffer.allocateDirect(out.size()); - b.put(out.toByteArray()); - b.flip(); - - ais.close(); - - return create(b, audioformat.getSampleSizeInBits(), audioformat.getChannels(), (int) audioformat.getSampleRate()); - } catch (Exception e) { - Logger.global.log(Level.SEVERE, "Exception creating AudioData(WAVE) : {0}", e.getMessage()); - return null; - } - } - - private static Sample decode_raw(SampleData ad) - { - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(ByteHelper.tmp_buffer.length); - - ByteHelper.copyTo(ad.getInputStream(), out); - - ByteBuffer b = ByteBuffer.allocateDirect(out.size()); - b.put(out.toByteArray()); - b.flip(); - - ad.getInputStream().close(); - - SampleData.WAVHeader h = ad.getWAVHeader(); - - return create(b, h.bits_per_sample, h.num_channels, h.sample_rate); - } catch (IOException ex) { - Logger.global.log(Level.SEVERE, "Exception creating AudioData(RAW) : {0}", ex.getMessage()); - return null; - } - } - - /** - * Creates a new SampleData from a Bitstream (Thanks to the libgdx team for the function & library :D) - * @param stream The Bitstream - * @return a new SampleData - */ - public static Sample decodeMP3(SampleData ad) - { - try { - Bitstream stream = new Bitstream(ad.getInputStream()); - - ByteArrayOutputStream out = new ByteArrayOutputStream(ByteHelper.tmp_buffer.length); - - MP3Decoder decoder = new MP3Decoder(); - - - OutputBuffer outputBuffer = null; - int sampleRate = -1 , channels = -1; - while (true) { - Header header = stream.readFrame(); - if (header == null) break; - if (outputBuffer == null) { - channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2; - outputBuffer = new OutputBuffer(channels, false); - decoder.setOutputBuffer(outputBuffer); - sampleRate = header.getSampleRate(); - } - try { - decoder.decodeFrame(header, stream); - } catch (Exception ignored) { - // JLayer's decoder throws ArrayIndexOutOfBoundsException sometimes!? - } - stream.closeFrame(); - out.write(outputBuffer.getBuffer(), 0, outputBuffer.reset()); - } - - ByteBuffer b = ByteBuffer.allocateDirect(out.size()); - b.put(out.toByteArray()); - b.flip(); - - stream.close(); - - return create(b, 16/*TODO find&fix this*/, channels, sampleRate); - } catch (BitstreamException ex) { - Logger.global.log(Level.SEVERE, "Exception creating AudioData(MP3) : {0}", ex.getMessage()); - return null; - } - } - -} diff --git a/src/org/open2jam/util/OggInputStream.java b/src/org/open2jam/util/OggInputStream.java deleted file mode 100644 index 50d4be54..00000000 --- a/src/org/open2jam/util/OggInputStream.java +++ /dev/null @@ -1,545 +0,0 @@ -package org.open2jam.util; - -import com.jcraft.jogg.Packet; -import com.jcraft.jogg.Page; -import com.jcraft.jogg.StreamState; -import com.jcraft.jogg.SyncState; -import com.jcraft.jorbis.Block; -import com.jcraft.jorbis.Comment; -import com.jcraft.jorbis.DspState; -import com.jcraft.jorbis.Info; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import org.open2jam.parsers.utils.Logger; - - - -/** - * Decompresses an Ogg file. - *

- * How to use:
- * 1. Create OggInputStream passing in the input stream of the packed ogg file
- * 2. Fetch format and sampling rate using getFormat() and getRate(). Use it to - * initialize the sound player.
- * 3. Read the PCM data using one of the read functions, and feed it to your player. - *

- * OggInputStream provides a read(ByteBuffer, int, int) that can be used to read - * data directly into a native buffer. - */ -public class OggInputStream extends FilterInputStream { - - - /** The mono 16 bit format */ - public static final int FORMAT_MONO16 = 1; - - /** The stereo 16 bit format */ - public static final int FORMAT_STEREO16 = 2; - - // temp vars - private float[][][] _pcm = new float[1][][]; - private int[] _index; - - // end of stream - private boolean eos = false; - - // sync and verify incoming physical bitstream - private SyncState syncState = new SyncState(); - - // take physical pages, weld into a logical stream of packets - private StreamState streamState = new StreamState(); - - // one Ogg bitstream page. Vorbis packets are inside - private Page page = new Page(); - - // one raw packet of data for decode - private Packet packet = new Packet(); - - // struct that stores all the static vorbis bitstream settings - private Info info = new Info(); - - // struct that stores all the bitstream user comments - private Comment comment = new Comment(); - - // central working state for the packet->PCM decoder - private DspState dspState = new DspState(); - - // local working space for packet->PCM decode - private Block block = new Block(dspState); - - /// Conversion buffer size - private static int convsize = 4096 * 2; - - // Conversion buffer - private static byte[] convbuffer = new byte[convsize]; - - // where we are in the convbuffer - private int convbufferOff = 0; - - // bytes ready in convbuffer. - private int convbufferSize = 0; - - // a dummy used by read() to read 1 byte. - private byte readDummy[] = new byte[1]; - - - /** - * Creates an OggInputStream that decompressed the specified ogg file. - */ - public OggInputStream(InputStream input) throws IOException { - super(input); - try { - initVorbis(); - _index = new int[info.channels]; - } catch (IOException e) { - eos = true; - throw e; - } - } - - - /** - * Gets the format of the ogg file. Is either FORMAT_MONO16 or FORMAT_STEREO16 - */ - public int getFormat() { - if (info.channels == 1) { - return FORMAT_MONO16; - } else { - return FORMAT_STEREO16; - } - } - - - /** - * Gets the rate of the pcm audio. - */ - public int getRate() { - return info.rate; - } - - - /** - * Reads the next byte of data from this input stream. The value byte is - * returned as an int in the range 0 to 255. If no byte is available because - * the end of the stream has been reached, the value -1 is returned. This - * method blocks until input data is available, the end of the stream is - * detected, or an exception is thrown. - * @return the next byte of data, or -1 if the end of the stream is reached. - */ - @Override - public int read() throws IOException { - int retVal = read(readDummy, 0, 1); - return (retVal == -1 ? -1 : readDummy[0]); - } - - - /** - * Reads up to len bytes of data from the input stream into an array of bytes. - * @param b the buffer into which the data is read. - * @param off the start offset of the data. - * @param len the maximum number of bytes read. - * @return the total number of bytes read into the buffer, or -1 if there is - * no more data because the end of the stream has been reached. - */ - @Override - public int read(byte b[], int off, int len) throws IOException { - if (eos) { - return -1; - } - - int bytesRead = 0; - while (!eos && (len > 0)) { - fillConvbuffer(); - - if (!eos) { - int bytesToCopy = Math.min(len, convbufferSize-convbufferOff); - System.arraycopy(convbuffer, convbufferOff, b, off, bytesToCopy); - convbufferOff += bytesToCopy; - bytesRead += bytesToCopy; - len -= bytesToCopy; - off += bytesToCopy; - } - } - - return bytesRead; - } - - - /** - * Reads up to len bytes of data from the input stream into a ByteBuffer. - * @param b the buffer into which the data is read. - * @param off the start offset of the data. - * @param len the maximum number of bytes read. - * @return the total number of bytes read into the buffer, or -1 if there is - * no more data because the end of the stream has been reached. - */ - public int read(ByteBuffer b, int off, int len) throws IOException { - if (eos) { - return -1; - } - - b.position(off); - int bytesRead = 0; - while (!eos && (len > 0)) { - fillConvbuffer(); - - if (!eos) { - int bytesToCopy = Math.min(len, convbufferSize-convbufferOff); - b.put(convbuffer, convbufferOff, bytesToCopy); - convbufferOff += bytesToCopy; - bytesRead += bytesToCopy; - len -= bytesToCopy; - } - } - - return bytesRead; - } - - - /** - * Helper function. Decodes a packet to the convbuffer if it is empty. - * Updates convbufferSize, convbufferOff, and eos. - */ - private void fillConvbuffer() throws IOException { - if (convbufferOff >= convbufferSize) { - convbufferSize = lazyDecodePacket(); - convbufferOff = 0; - if (convbufferSize == -1) { - eos = true; - } - } - } - - - /** - * Returns 0 after EOF is reached, otherwise always return 1. - *

- * Programs should not count on this method to return the actual number of - * bytes that could be read without blocking. - * @return 1 before EOF and 0 after EOF is reached. - */ - @Override - public int available() throws IOException { - return (eos ? 0 : 1); - } - - - /** - * OggInputStream does not support mark and reset. This function does nothing. - */ - @Override - public void reset() throws IOException { - } - - - /** - * OggInputStream does not support mark and reset. - * @return false. - */ - @Override - public boolean markSupported() { - return false; - } - - - /** - * Skips over and discards n bytes of data from the input stream. The skip - * method may, for a variety of reasons, end up skipping over some smaller - * number of bytes, possibly 0. The actual number of bytes skipped is returned. - * @param n the number of bytes to be skipped. - * @return the actual number of bytes skipped. - */ - @Override - public long skip(long n) throws IOException { - int bytesRead = 0; - while (bytesRead < n) { - int res = read(); - if (res == -1) { - break; - } - - bytesRead++; - } - - return bytesRead; - } - - - /** - * Initalizes the vorbis stream. Reads the stream until info and comment are read. - */ - private void initVorbis() throws IOException { - // Now we can read pages - syncState.init(); - - // grab some data at the head of the stream. We want the first page - // (which is guaranteed to be small and only contain the Vorbis - // stream initial header) We need the first page to get the stream - // serialno. - - // submit a 4k block to libvorbis' Ogg layer - int index = syncState.buffer(4096); - byte buffer[] = syncState.data; - int bytes = in.read(buffer, index, 4096); - syncState.wrote(bytes); - - // Get the first page. - if (syncState.pageout(page) != 1) { - // have we simply run out of data? If so, we're done. - if (bytes < 4096) - return;//break; - - // error case. Must not be Vorbis data - throw new IOException("Input does not appear to be an Ogg bitstream."); - } - - // Get the serial number and set up the rest of decode. - // serialno first; use it to set up a logical stream - streamState.init(page.serialno()); - - // extract the initial header from the first page and verify that the - // Ogg bitstream is in fact Vorbis data - - // I handle the initial header first instead of just having the code - // read all three Vorbis headers at once because reading the initial - // header is an easy way to identify a Vorbis bitstream and it's - // useful to see that functionality seperated out. - - info.init(); - comment.init(); - if (streamState.pagein(page) < 0) { - // error; stream version mismatch perhaps - throw new IOException("Error reading first page of Ogg bitstream data."); - } - - if (streamState.packetout(packet) != 1) { - // no page? must not be vorbis - throw new IOException("Error reading initial header packet."); - } - - if (info.synthesis_headerin(comment, packet) < 0) { - // error case; not a vorbis header - throw new IOException("This Ogg bitstream does not contain Vorbis audio data."); - } - - // At this point, we're sure we're Vorbis. We've set up the logical - // (Ogg) bitstream decoder. Get the comment and codebook headers and - // set up the Vorbis decoder - - // The next two packets in order are the comment and codebook headers. - // They're likely large and may span multiple pages. Thus we read - // and submit data until we get our two packets, watching that no - // pages are missing. If a page is missing, error out; losing a - // header page is the only place where missing data is fatal. - - - int i = 0; - while (i < 2) { - while (i < 2) { - - int result = syncState.pageout(page); - if (result == 0) - break; // Need more data - // Don't complain about missing or corrupt data yet. We'll - // catch it at the packet output phase - - if (result == 1) { - streamState.pagein(page); // we can ignore any errors here - // as they'll also become apparent - // at packetout - while (i < 2) { - result = streamState.packetout(packet); - if (result == 0) { - break; - } - - if (result == -1) { - // Uh oh; data at some point was corrupted or missing! - // We can't tolerate that in a header. Die. - throw new IOException("Corrupt secondary header. Exiting."); - } - - info.synthesis_headerin(comment, packet); - i++; - } - } - } - - // no harm in not checking before adding more - index = syncState.buffer(4096); - buffer = syncState.data; - bytes = in.read(buffer, index, 4096); - - // NOTE: This is a bugfix. read will return -1 which will mess up syncState. - if (bytes < 0 ) { - bytes = 0; - } - - if (bytes == 0 && i < 2) { - throw new IOException("End of file before finding all Vorbis headers!"); - } - - syncState.wrote(bytes); - } - - convsize = 4096 / info.channels; - - // OK, got and parsed all three headers. Initialize the Vorbis - // packet->PCM decoder. - dspState.synthesis_init(info); // central decode state - block.init(dspState); // local state for most of the decode - // so multiple block decodes can - // proceed in parallel. We could init - // multiple vorbis_block structures - // for vd here - } - - - /** - * Decodes a packet. - */ - private int decodePacket(Packet packet) { - // check the endianes of the computer. - final boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN; - - if (block.synthesis(packet) == 0) { - // test for success! - dspState.synthesis_blockin(block); - } - - // **pcm is a multichannel float vector. In stereo, for - // example, pcm[0] is left, and pcm[1] is right. samples is - // the size of each channel. Convert the float values - // (-1.<=range<=1.) to whatever PCM format and write it out - int convOff = 0; - int samples; - while ((samples = dspState.synthesis_pcmout(_pcm, _index)) > 0) { - float[][] pcm = _pcm[0]; - int bout = (samples < convsize ? samples : convsize); - - // convert floats to 16 bit signed ints (host order) and interleave - for (int i = 0; i < info.channels; i++) { - int ptr = (i << 1) + convOff; - - - int mono = _index[i]; - - for (int j = 0; j < bout; j++) { - int val = (int) (pcm[i][mono + j] * 32767.); - - // might as well guard against clipping - val = Math.max(-32768, Math.min(32767, val)); - val |= (val < 0 ? 0x8000 : 0); - - convbuffer[ptr + 0] = (byte) (bigEndian ? val >>> 8 : val); - convbuffer[ptr + 1] = (byte) (bigEndian ? val : val >>> 8); - - ptr += (info.channels) << 1; - } - } - - convOff += 2 * info.channels * bout; - - // Tell orbis how many samples were consumed - dspState.synthesis_read(bout); - } - - return convOff; - } - - - /** - * Decodes the next packet. - * @return bytes read into convbuffer of -1 if end of file - */ - private int lazyDecodePacket() throws IOException { - int result = getNextPacket(packet); - if (result == -1) { - return -1; - } - - // we have a packet. Decode it - return decodePacket(packet); - } - - - /** - * @param packet where to put the packet. - */ - private int getNextPacket(Packet packet) throws IOException { - // get next packet. - boolean fetchedPacket = false; - while (!eos && !fetchedPacket) { - int result1 = streamState.packetout(packet); - if (result1 == 0) { - // no more packets in page. Fetch new page. - int result2 = 0; - while (!eos && result2 == 0) { - result2 = syncState.pageout(page); - if (result2 == 0) { - fetchData(); - } - } - - // return if we have reaced end of file. - if ((result2 == 0) && (page.eos() != 0)) { - return -1; - } - - if (result2 == 0) { - // need more data fetching page.. - fetchData(); - } else if (result2 == -1) { - //throw new Exception("syncState.pageout(page) result == -1"); - Logger.global.severe("OGG decode Error: syncState.pageout(page) result == -1"); - return -1; - } else { - int result3 = streamState.pagein(page); - } - } else if (result1 == -1) { - //throw new Exception("streamState.packetout(packet) result == -1"); - Logger.global.severe("OGG decode Error: streamState.packetout(packet) result == -1"); - return -1; - } else { - fetchedPacket = true; - } - } - - return 0; - } - - - /** - * Copys data from input stream to syncState. - */ - private void fetchData() throws IOException { - if (!eos) { - // copy 4096 bytes from compressed stream to syncState. - int index = syncState.buffer(4096); - if (index < 0) { - eos = true; - return; - } - int bytes = in.read(syncState.data, index, 4096); - syncState.wrote(bytes); - if (bytes == 0) { - eos = true; - } - } - } - - - /** - * Gets information on the ogg. - */ - @Override - public String toString() { - String s = ""; - s = s + "version " + info.version + "\n"; - s = s + "channels " + info.channels + "\n"; - s = s + "rate (hz) " + info.rate ; - return s; - } -}