Commits

Anonymous committed 0811e0f

Added the JavaX_Driver by Tobias Braun that allows for a portable playing
through the soundcard.

Comments (0)

Files changed (4)

source/java/source/Makefile

         MikMod/Loaders/XM_Loader.class \
         MikMod/Loaders/STM_Loader.class
 
-DRIVERS = MikMod/Drivers/Raw_Driver.class  \
+DRIVERS = \
+		MikMod/Drivers/JavaX_Driver.class  \
         MikMod/Drivers/NS_Driver.class  \
         MikMod/Drivers/Native_Driver.class \
+		MikMod/Drivers/Raw_Driver.class  \
 		MikMod/Drivers/Wav_Driver.class
 
 OBJS =  MikMod/MMIO/MMIO.class \

source/java/source/MikMod/Drivers/JavaX_Driver.java

+package MikMod.Drivers;
+
+import java.io.*;
+import MikMod.*;
+import javax.sound.sampled.*;
+
+/***************************************************************************
+ * JavaX Driver - implemented in 2002 by Tobias Braun (tb@640k.de)         *
+ * quite an ugly hack at the moment - sound buffer is alway initialized    *
+ * with 44100HZ/16Bit/Stereo. But hey, it works for me ;)                  *
+ ***************************************************************************/
+
+public class JavaX_Driver extends clDRIVER {
+	public final int RAWBUFFERSIZE = 16384;
+  SourceDataLine line;
+
+	byte RAW_DMABUF[]; //[RAWBUFFERSIZE];
+
+	public JavaX_Driver(clMain theMain)
+	//	: clDRIVER(theMain)
+	{
+		super(theMain);
+		int i;
+
+		Name = new String("JavaX-Driver");
+		Version = new String("JavaX output driver v0.01 by Tobias Braun tb@640k.de");
+
+		RAW_DMABUF = new byte[RAWBUFFERSIZE];
+		for (i = 0; i < RAWBUFFERSIZE; i++)
+			RAW_DMABUF[i] = 0;
+	}
+
+	public boolean IsPresent() {
+		return true;
+	}
+
+	public int Init() {
+    // User defined values should be set in the following line
+    AudioFormat format = new AudioFormat(44100f, 16, 2, true, false);
+
+    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
+    if (!AudioSystem.isLineSupported(info)) {
+        System.out.println("Line not supported!");
+        System.exit(-1);
+    }
+
+    // Obtain and open the line.
+    try {
+        line = (SourceDataLine) AudioSystem.getLine(info);
+        line.open(format);
+    } catch (LineUnavailableException ex) {
+        ex.printStackTrace();
+        System.exit(-1);
+    }
+
+		if (!m_.Virtch.VC_Init()) {
+			line.close();
+			line = null;
+			return 0;
+		}
+
+			return 1;
+	}
+
+	public void Exit() {
+			m_.Virtch.VC_Exit();
+			line.close();
+	}
+
+	public void Update() {
+			m_.Virtch.VC_WriteBytes(RAW_DMABUF, RAWBUFFERSIZE);
+			//fwrite(RAW_DMABUF,RAWBUFFERSIZE,1,rawout);
+			line.write(RAW_DMABUF, 0, RAWBUFFERSIZE);
+	}
+
+	public short SampleLoad(
+		RandomAccessFile fp,
+		int length,
+		int reppos,
+		int repend,
+		int flags) {
+		return m_.Virtch.VC_SampleLoad(fp, length, reppos, repend, flags);
+	}
+
+	public void SampleUnLoad(short handle) {
+		m_.Virtch.VC_SampleUnload(handle);
+	}
+
+	public void PlayStart() {
+		m_.Virtch.VC_PlayStart();
+    line.start();
+	}
+
+	public void PlayStop() {
+		m_.Virtch.VC_PlayStop();
+    line.stop();
+	}
+
+	public void VoiceSetVolume(short voice, short vol) {
+		m_.Virtch.VC_VoiceSetVolume(voice, vol);
+	}
+
+	public void VoiceSetFrequency(short voice, int frq) {
+		m_.Virtch.VC_VoiceSetFrequency(voice, frq);
+	}
+
+	public void VoiceSetPanning(short voice, short pan) {
+		m_.Virtch.VC_VoiceSetPanning(voice, pan);
+	}
+
+	public void VoicePlay(
+		short voice,
+		short handle,
+		int start,
+		int size,
+		int reppos,
+		int repend,
+		int flags) {
+		m_.Virtch.VC_VoicePlay(
+			voice,
+			handle,
+			start,
+			size,
+			reppos,
+			repend,
+			flags);
+	}
+
+}

source/java/source/MikMod/clMain.java

     */
     Wav_Driver cl_drv_wav = new Wav_Driver(this);
     MDriver.MD_RegisterDriver(cl_drv_wav);
+    JavaX_Driver cl_drv_javax = new JavaX_Driver(this);
+    MDriver.MD_RegisterDriver(cl_drv_javax);
 
 
 

source/java/source/TODO

+* Make sure the JavaX sound driver can handle other configurations besides
+44.1KHz/Stereo/16-bit.
+
+* Create a base class for all the drivers in which the VC_ functions call
+the Virtch ones.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.