From fbedc1915fccdd800554f2e30dd4e29167d9928a Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Sun, 13 Oct 2013 23:27:49 -0400 Subject: [PATCH] More core work --- .../mekanism/client/VoiceClientManager.java | 75 +++++++++++++++++++ common/mekanism/common/VoiceConnection.java | 26 +++++++ 2 files changed, 101 insertions(+) diff --git a/common/mekanism/client/VoiceClientManager.java b/common/mekanism/client/VoiceClientManager.java index 18869048d..446111c95 100644 --- a/common/mekanism/client/VoiceClientManager.java +++ b/common/mekanism/client/VoiceClientManager.java @@ -1,8 +1,18 @@ package mekanism.client; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.net.InetAddress; import java.net.Socket; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; +import javax.sound.sampled.SourceDataLine; +import javax.sound.sampled.TargetDataLine; + import net.minecraft.network.INetworkManager; import net.minecraft.network.NetLoginHandler; import net.minecraft.network.packet.NetHandler; @@ -14,6 +24,19 @@ import cpw.mods.fml.common.network.Player; public class VoiceClientManager implements IConnectionHandler { public Socket socket; + + public AudioFormat format = new AudioFormat(11025.0F, 8, 1, true, true); + + public DataLine.Info microphone = new DataLine.Info(TargetDataLine.class, this.format, 2200); + public DataLine.Info speaker = new DataLine.Info(SourceDataLine.class, this.format, 2200); + + public TargetDataLine targetLine; + public SourceDataLine sourceLine; + + public DataInputStream input; + public DataOutputStream output; + + public boolean running; @Override public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) @@ -35,6 +58,7 @@ public class VoiceClientManager implements IConnectionHandler //connecting to foreign server try { socket = new Socket(server, 36123); + running = true; } catch(Exception e) {} } @@ -44,6 +68,7 @@ public class VoiceClientManager implements IConnectionHandler //connecting to LAN server on same instance try { socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 36123); + running = true; } catch(Exception e) {} } @@ -51,8 +76,22 @@ public class VoiceClientManager implements IConnectionHandler public void connectionClosed(INetworkManager manager) { try { + sourceLine.flush(); + sourceLine.close(); + + targetLine.flush(); + targetLine.close(); + + output.flush(); + output.close(); + output = null; + + input.close(); + input = null; + socket.close(); socket = null; + running = false; } catch(Exception e) {} } @@ -61,4 +100,40 @@ public class VoiceClientManager implements IConnectionHandler { } + + public void init() + { + try { + input = new DataInputStream(new BufferedInputStream(socket.getInputStream())); + output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); + + //Speaker (Out) + new Thread(new Runnable() + { + @Override + public void run() + { + try { + VoiceClientManager.this.sourceLine = ((SourceDataLine)AudioSystem.getLine(VoiceClientManager.this.speaker)); + VoiceClientManager.this.sourceLine.open(VoiceClientManager.this.format, 2200); + VoiceClientManager.this.sourceLine.start(); + } catch(Exception e) {} + } + }).start(); + + //Microphone (In) + new Thread(new Runnable() + { + @Override + public void run() + { + try { + VoiceClientManager.this.targetLine = ((TargetDataLine)AudioSystem.getLine(microphone)); + VoiceClientManager.this.targetLine.open(VoiceClientManager.this.format, 2200); + VoiceClientManager.this.targetLine.start(); + } catch(Exception e) {} + } + }).start(); + } catch(Exception e) {} + } } diff --git a/common/mekanism/common/VoiceConnection.java b/common/mekanism/common/VoiceConnection.java index 9f14da394..5db90b002 100644 --- a/common/mekanism/common/VoiceConnection.java +++ b/common/mekanism/common/VoiceConnection.java @@ -1,13 +1,39 @@ package mekanism.common; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.net.Socket; public class VoiceConnection { public Socket socket; + public DataInputStream input; + public DataOutputStream output; + public VoiceConnection(Socket s) { socket = s; } + + public void start() + { + try { + input = new DataInputStream(new BufferedInputStream(socket.getInputStream())); + output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); + + new Thread(new Runnable() + { + @Override + public void run() + { + try { + + } catch(Exception e) {} + } + }).start(); + } catch(Exception e) {} + } }