Index: openjdk.cs =================================================================== RCS file: /cvsroot/ikvm/ikvm/runtime/openjdk.cs,v retrieving revision 1.113 diff -u -r1.113 openjdk.cs --- openjdk.cs 21 Sep 2008 09:45:00 -0000 1.113 +++ openjdk.cs 22 Sep 2008 04:53:21 -0000 @@ -7552,8 +7552,447 @@ #if FIRST_PASS return null; #else - return new global::java.util.ArrayList(); + if (providerClass == (global::java.lang.Class)typeof(javax.sound.sampled.spi.MixerProvider)) + { + global::java.util.ArrayList list = new global::java.util.ArrayList(); + list.add(new MixerProvider()); + return list; + } + else if (providerClass == (global::java.lang.Class)typeof(javax.sound.sampled.spi.AudioFileReader)) + { + global::java.util.ArrayList list = new global::java.util.ArrayList(); + list.add(new AudioFileReader()); + return list; + } + else + { + Console.WriteLine("unsupported provider type: " + providerClass); + return null; + } #endif } } + +#if !FIRST_PASS + class AudioFileReader : javax.sound.sampled.spi.AudioFileReader + { + public override javax.sound.sampled.AudioFileFormat getAudioFileFormat(global::java.io.File f) + { + throw new NotImplementedException(); + } + + public override javax.sound.sampled.AudioFileFormat getAudioFileFormat(global::java.net.URL url) + { + throw new NotImplementedException(); + } + + public override javax.sound.sampled.AudioFileFormat getAudioFileFormat(global::java.io.InputStream @is) + { + throw new NotImplementedException(); + } + + public override javax.sound.sampled.AudioInputStream getAudioInputStream(global::java.io.File f) + { + throw new NotImplementedException(); + } + + public override javax.sound.sampled.AudioInputStream getAudioInputStream(global::java.net.URL url) + { + return new javax.sound.sampled.AudioInputStream(url.openStream(), new javax.sound.sampled.AudioFormat(44000, 16, 1, false, false), -1); + } + + public override javax.sound.sampled.AudioInputStream getAudioInputStream(global::java.io.InputStream @is) + { + throw new NotImplementedException(); + } + } + + class MixerProvider : javax.sound.sampled.spi.MixerProvider + { + public override javax.sound.sampled.Mixer.Info[] getMixerInfo() + { + return new javax.sound.sampled.Mixer.Info[] { new MixerInfo() }; + } + + public override javax.sound.sampled.Mixer getMixer(javax.sound.sampled.Mixer.Info mi) + { + if (mi is MixerInfo) + { + return new Mixer(); + } + throw new global::java.lang.IllegalArgumentException(); + } + } + + class MixerInfo : javax.sound.sampled.Mixer.Info + { + internal MixerInfo() + : base("IKVM Mixer", "Jeroen Frijters", "IKVM Mixer", "1.0") + { + } + } + + class Mixer : javax.sound.sampled.Mixer + { + public javax.sound.sampled.Line getLine(javax.sound.sampled.Line.Info li) + { + return new Line(); + } + + public int getMaxLines(javax.sound.sampled.Line.Info li) + { + // TODO + return 2; + } + + public javax.sound.sampled.Mixer.Info getMixerInfo() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line.Info[] getSourceLineInfo() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line.Info[] getSourceLineInfo(javax.sound.sampled.Line.Info li) + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line[] getSourceLines() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line.Info[] getTargetLineInfo() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line.Info[] getTargetLineInfo(javax.sound.sampled.Line.Info li) + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line[] getTargetLines() + { + throw new NotImplementedException(); + } + + public bool isLineSupported(javax.sound.sampled.Line.Info li) + { + // TODO + return true; + } + + public bool isSynchronizationSupported(javax.sound.sampled.Line[] larr, bool b) + { + throw new NotImplementedException(); + } + + public void synchronize(javax.sound.sampled.Line[] larr, bool b) + { + throw new NotImplementedException(); + } + + public void unsynchronize(javax.sound.sampled.Line[] larr) + { + throw new NotImplementedException(); + } + + public void addLineListener(javax.sound.sampled.LineListener ll) + { + throw new NotImplementedException(); + } + + public void close() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Control getControl(javax.sound.sampled.Control.Type ct) + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Control[] getControls() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line.Info getLineInfo() + { + throw new NotImplementedException(); + } + + public bool isControlSupported(javax.sound.sampled.Control.Type ct) + { + throw new NotImplementedException(); + } + + public bool isOpen() + { + throw new NotImplementedException(); + } + + public void open() + { + throw new NotImplementedException(); + } + + public void removeLineListener(javax.sound.sampled.LineListener ll) + { + throw new NotImplementedException(); + } + } + + class Line : javax.sound.sampled.SourceDataLine, javax.sound.sampled.Clip + { + private Thread thread; + private byte[] buffer = new byte[22000]; + private int bufPos; + private long startTime; + private long endTime; + + private static void WriteWaveHeader(byte[] buf, int length) + { + System.IO.BinaryWriter bw = new System.IO.BinaryWriter(new System.IO.MemoryStream(buf)); + bw.Write(System.Text.Encoding.ASCII.GetBytes("RIFF")); + bw.Write(length + 36); // chunk size + bw.Write(System.Text.Encoding.ASCII.GetBytes("WAVEfmt ")); + bw.Write(16); // sub chunk size + bw.Write((short)1); // format (PCM) + bw.Write((short)1); // channels + bw.Write(44000); // sample rate + bw.Write(88000); // byte rate + bw.Write((short)2); // block align + bw.Write((short)16);// bits per sample + bw.Write(System.Text.Encoding.ASCII.GetBytes("data")); + bw.Write(length); + bw.Close(); + } + + public void addLineListener(javax.sound.sampled.LineListener ll) + { + throw new NotImplementedException(); + } + + public void close() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Control getControl(javax.sound.sampled.Control.Type ct) + { + if (ct == javax.sound.sampled.FloatControl.Type.MASTER_GAIN) + { + return new MasterGain(); + } + throw new NotImplementedException(); + } + + public javax.sound.sampled.Control[] getControls() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.Line.Info getLineInfo() + { + throw new NotImplementedException(); + } + + public bool isControlSupported(javax.sound.sampled.Control.Type ct) + { + throw new NotImplementedException(); + } + + public bool isOpen() + { + throw new NotImplementedException(); + } + + public void open() + { + thread = new Thread(ThreadLoop); + thread.IsBackground = true; + thread.Start(); + } + + public void removeLineListener(javax.sound.sampled.LineListener ll) + { + throw new NotImplementedException(); + } + + public void open(javax.sound.sampled.AudioFormat af) + { + open(); + } + + public void open(javax.sound.sampled.AudioFormat af, int i) + { + open(); + } + + private void ThreadLoop() + { + byte[] buf = new byte[buffer.Length + 44]; + System.Media.SoundPlayer player = new System.Media.SoundPlayer(); + for (; ; ) + { + int len = 0; + lock (this) + { + while (bufPos == 0) + { + Monitor.Wait(this); + } + Array.Copy(buffer, 0, buf, 44, bufPos); + len = bufPos; + bufPos = 0; + } + WriteWaveHeader(buf, len); + player.Stream = new System.IO.MemoryStream(buf); + player.PlaySync(); + } + } + + public int write(byte[] barr, int i1, int i2) + { + lock (this) + { + long time = getMicrosecondPosition(); + if (endTime < time) + { + endTime = time; + } + endTime += (i2 * 1000000L) / (2 * 44000); + i2 = Math.Min(i2, buffer.Length - bufPos); + Array.Copy(barr, i1, buffer, bufPos, i2); + bufPos += i2; + Monitor.PulseAll(this); + return i2; + } + } + + public int available() + { + lock (this) + { + long time = getMicrosecondPosition(); + if (time > endTime) + { + return buffer.Length; + } + return Math.Max(0, buffer.Length - (int)(((endTime - time) * (2 * 44000)) / 1000000L)); + } + } + + public void drain() + { + throw new NotImplementedException(); + } + + public void flush() + { + throw new NotImplementedException(); + } + + public int getBufferSize() + { + throw new NotImplementedException(); + } + + public javax.sound.sampled.AudioFormat getFormat() + { + return new javax.sound.sampled.AudioFormat(44000, 16, 1, false, false); + } + + public int getFramePosition() + { + throw new NotImplementedException(); + } + + public float getLevel() + { + throw new NotImplementedException(); + } + + public long getLongFramePosition() + { + throw new NotImplementedException(); + } + + public long getMicrosecondPosition() + { + return (global::java.lang.System.nanoTime() - startTime) / 1000; + } + + public bool isActive() + { + throw new NotImplementedException(); + } + + public bool isRunning() + { + throw new NotImplementedException(); + } + + public void start() + { + startTime = global::java.lang.System.nanoTime(); + } + + public void stop() + { + } + + public int getFrameLength() + { + throw new NotImplementedException(); + } + + public long getMicrosecondLength() + { + throw new NotImplementedException(); + } + + public void loop(int i) + { + throw new NotImplementedException(); + } + + public void open(javax.sound.sampled.AudioInputStream ais) + { + open(); + } + + public void open(javax.sound.sampled.AudioFormat af, byte[] barr, int i1, int i2) + { + open(); + } + + public void setFramePosition(int i) + { + } + + public void setLoopPoints(int i1, int i2) + { + throw new NotImplementedException(); + } + + public void setMicrosecondPosition(long l) + { + throw new NotImplementedException(); + } + } + + class MasterGain : javax.sound.sampled.FloatControl + { + internal MasterGain() + : base(javax.sound.sampled.FloatControl.Type.MASTER_GAIN, 0, 100, 1, 1, 50, "whatever") + { + } + } +#endif }