From 6b21ca1463d667bbbc4d8918fe0f23ee3d267559 Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 13 Jul 2011 17:59:54 +0000 Subject: [PATCH] changes on mp3 decoder --- .../Tests/ssJava/mp3decoder/AudioDevice.java | 79 +++++++++++++++++++ .../Tests/ssJava/mp3decoder/MP3Player.java | 42 ++++++++++ .../src/Tests/ssJava/mp3decoder/Player.java | 32 ++++---- Robust/src/Tests/ssJava/mp3decoder/makefile | 4 +- 4 files changed, 137 insertions(+), 20 deletions(-) create mode 100644 Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java create mode 100644 Robust/src/Tests/ssJava/mp3decoder/MP3Player.java diff --git a/Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java b/Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java new file mode 100644 index 00000000..17dc9036 --- /dev/null +++ b/Robust/src/Tests/ssJava/mp3decoder/AudioDevice.java @@ -0,0 +1,79 @@ +// dummy audio device +/** + * The JavaSoundAudioDevice 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 true if this audio device is open and playing audio + * samples, or false otherwise. + */ + public boolean isOpen() { + return true; + } + + /** + * Writes a number of samples to this AudioDevice. + * + * @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 write or flush 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 index 00000000..51f7eebf --- /dev/null +++ b/Robust/src/Tests/ssJava/mp3decoder/MP3Player.java @@ -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 diff --git a/Robust/src/Tests/ssJava/mp3decoder/Player.java b/Robust/src/Tests/ssJava/mp3decoder/Player.java index 3bc1cc91..90c4fc2c 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Player.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Player.java @@ -72,27 +72,28 @@ public class Player */ public Player(InputStream stream) throws JavaLayerException { - //this(stream, null); + this(stream, null); } - /* temporarily disabled by eom + public Player(InputStream stream, AudioDevice device) throws JavaLayerException { bitstream = new Bitstream(stream); decoder = new Decoder(); - if (device!=null) - { - audio = device; - } - else - { - FactoryRegistry r = FactoryRegistry.systemRegistry(); - audio = r.createAudioDevice(); - } - audio.open(decoder); +// if (device!=null) +// { +// audio = device; +// } +// else +// { +// FactoryRegistry r = FactoryRegistry.systemRegistry(); +// audio = r.createAudioDevice(); +// } + + device.open(decoder); } - */ + public void play() throws JavaLayerException { @@ -249,9 +250,4 @@ public class Player return true; } - public static void main(String args[]){ - //dummy - } - - } diff --git a/Robust/src/Tests/ssJava/mp3decoder/makefile b/Robust/src/Tests/ssJava/mp3decoder/makefile index 55b823cb..7fb1e383 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/makefile +++ b/Robust/src/Tests/ssJava/mp3decoder/makefile @@ -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 -- 2.34.1