changes on mp3 decoder
authoryeom <yeom>
Wed, 13 Jul 2011 17:59:54 +0000 (17:59 +0000)
committeryeom <yeom>
Wed, 13 Jul 2011 17:59:54 +0000 (17:59 +0000)
Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java [new file with mode: 0644]
Robust/src/Tests/ssJava/mp3decoder/MP3Player.java [new file with mode: 0644]
Robust/src/Tests/ssJava/mp3decoder/Player.java
Robust/src/Tests/ssJava/mp3decoder/makefile

diff --git a/Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java b/Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java
new file mode 100644 (file)
index 0000000..17dc903
--- /dev/null
@@ -0,0 +1,79 @@
+// dummy audio device
+/**
+ * The <code>JavaSoundAudioDevice</code> implements an audio device by using the
+ * JavaSound API.
+ * 
+ * @since 0.0.8
+ * @author Mat McGowan
+ */
+public class AudioDevice {
+
+  /**
+   * Prepares the AudioDevice for playback of audio samples.
+   * 
+   * @param decoder
+   *          The decoder that will be providing the audio samples.
+   * 
+   *          If the audio device is already open, this method returns silently.
+   * 
+   */
+  public void open(Decoder decoder) throws JavaLayerException {
+
+  }
+
+  /**
+   * Retrieves the open state of this audio device.
+   * 
+   * @return <code>true</code> if this audio device is open and playing audio
+   *         samples, or <code>false</code> otherwise.
+   */
+  public boolean isOpen() {
+    return true;
+  }
+
+  /**
+   * Writes a number of samples to this <code>AudioDevice</code>.
+   * 
+   * @param samples
+   *          The array of signed 16-bit samples to write to the audio device.
+   * @param offs
+   *          The offset of the first sample.
+   * @param len
+   *          The number of samples to write.
+   * 
+   *          This method may return prior to the samples actually being played
+   *          by the audio device.
+   */
+  public void write(short[] samples, int offs, int len) throws JavaLayerException {
+
+  }
+
+  /**
+   * Closes this audio device. Any currently playing audio is stopped as soon as
+   * possible. Any previously written audio data that has not been heard is
+   * discarded.
+   * 
+   * The implementation should ensure that any threads currently blocking on the
+   * device (e.g. during a <code>write</code> or <code>flush</code> operation
+   * should be unblocked by this method.
+   */
+  public void close() {
+
+  }
+
+  /**
+   * Blocks until all audio samples previously written to this audio device have
+   * been heard.
+   */
+  public void flush() {
+
+  }
+
+  /**
+   * Retrieves the current playback position in milliseconds.
+   */
+  public int getPosition() {
+    return 0;
+  }
+
+}
\ No newline at end of file
diff --git a/Robust/src/Tests/ssJava/mp3decoder/MP3Player.java b/Robust/src/Tests/ssJava/mp3decoder/MP3Player.java
new file mode 100644 (file)
index 0000000..51f7eeb
--- /dev/null
@@ -0,0 +1,42 @@
+// command line player for MPEG audio file
+public class MP3Player {
+
+  private String filename = null;
+
+  public static void main(String args[]) {
+
+    MP3Player player = new MP3Player();
+    player.init(args);
+
+  }
+
+  private void init(String[] args) {
+    if (args.length == 1) {
+      filename = args[0];
+    }
+  }
+
+  /**
+   * Playing file from FileInputStream.
+   */
+  protected InputStream getInputStream() throws IOException {
+    FileInputStream fin = new FileInputStream(filename);
+    BufferedInputStream bin = new BufferedInputStream(fin);
+    return bin;
+  }
+
+  public void play() throws JavaLayerException {
+    try {
+      System.out.println("playing " + filename + "...");
+      InputStream in = getInputStream();
+      AudioDevice dev = new AudioDevice();
+      Player player = new Player(in, dev);
+      player.play();
+    } catch (IOException ex) {
+      throw new JavaLayerException("Problem playing file " + filename, ex);
+    } catch (Exception ex) {
+      throw new JavaLayerException("Problem playing file " + filename, ex);
+    }
+  }
+
+}
\ No newline at end of file
index 3bc1cc9..90c4fc2 100644 (file)
@@ -72,27 +72,28 @@ public class Player
         */\r
        public Player(InputStream stream) throws JavaLayerException\r
        {\r
-               //this(stream, null);   \r
+               this(stream, null);     \r
        }\r
 \r
-       /* temporarily disabled by eom\r
+\r
        public Player(InputStream stream, AudioDevice device) throws JavaLayerException\r
        {\r
                bitstream = new Bitstream(stream);              \r
                decoder = new Decoder();\r
                                \r
-               if (device!=null)\r
-               {               \r
-                       audio = device;\r
-               }\r
-               else\r
-               {                       \r
-                       FactoryRegistry r = FactoryRegistry.systemRegistry();\r
-                       audio = r.createAudioDevice();\r
-               }\r
-               audio.open(decoder);\r
+//             if (device!=null)\r
+//             {               \r
+//                     audio = device;\r
+//             }\r
+//             else\r
+//             {                       \r
+//                     FactoryRegistry r = FactoryRegistry.systemRegistry();\r
+//                     audio = r.createAudioDevice();\r
+//             }\r
+               \r
+               device.open(decoder);\r
        }\r
-       */\r
+       \r
        \r
        public void play() throws JavaLayerException\r
        {\r
@@ -249,9 +250,4 @@ public class Player
                return true;\r
        }\r
        \r
-       public static void main(String args[]){\r
-         //dummy         \r
-       }\r
-\r
-       \r
 }\r
index 55b823c..7fb1e38 100644 (file)
@@ -1,7 +1,7 @@
 BUILDSCRIPT=../../../buildscript
 
-PROGRAM=Player
-SOURCE_FILES=Player.java
+PROGRAM=MP3Player
+SOURCE_FILES=MP3Player.java
 
 BSFLAGS= -32bit -ssjava -ssjavadebug -printlinenum -mainclass $(PROGRAM)  -heapsize-mb 1000 -garbagestats -joptimize -noloop -optimize -debug