2013-10-14 20:08:15 +02:00
|
|
|
package mekanism.client.voice;
|
|
|
|
|
|
|
|
import javax.sound.sampled.AudioSystem;
|
|
|
|
import javax.sound.sampled.DataLine;
|
|
|
|
import javax.sound.sampled.SourceDataLine;
|
|
|
|
|
2013-10-14 20:25:04 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-10-14 20:08:15 +02:00
|
|
|
public class VoiceOutput extends Thread
|
|
|
|
{
|
|
|
|
public VoiceClient voiceClient;
|
|
|
|
|
2013-10-14 20:25:04 +02:00
|
|
|
public DataLine.Info speaker;
|
2013-10-14 20:08:15 +02:00
|
|
|
|
|
|
|
public SourceDataLine sourceLine;
|
|
|
|
|
|
|
|
public VoiceOutput(VoiceClient client)
|
|
|
|
{
|
|
|
|
voiceClient = client;
|
2013-10-14 20:25:04 +02:00
|
|
|
speaker = new DataLine.Info(SourceDataLine.class, voiceClient.format, 2200);
|
2013-10-14 20:08:15 +02:00
|
|
|
|
|
|
|
setDaemon(true);
|
|
|
|
setName("VoiceServer Client Output Thread");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
sourceLine = ((SourceDataLine)AudioSystem.getLine(speaker));
|
|
|
|
sourceLine.open(voiceClient.format, 2200);
|
|
|
|
sourceLine.start();
|
|
|
|
|
|
|
|
while(voiceClient.running)
|
|
|
|
{
|
2013-10-19 02:05:47 +02:00
|
|
|
try {
|
|
|
|
short byteCount = voiceClient.input.readShort();
|
|
|
|
byte[] audioData = new byte[byteCount];
|
|
|
|
voiceClient.input.readFully(audioData);
|
|
|
|
|
|
|
|
sourceLine.write(audioData, 0, audioData.length);
|
|
|
|
} catch(Exception e) {}
|
2013-10-14 20:08:15 +02:00
|
|
|
}
|
|
|
|
} catch(Exception e) {
|
2013-10-14 20:25:04 +02:00
|
|
|
System.err.println("[Mekanism] VoiceServer: Error while running client output thread.");
|
2013-10-14 20:08:15 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void close()
|
|
|
|
{
|
|
|
|
sourceLine.flush();
|
|
|
|
sourceLine.close();
|
|
|
|
}
|
|
|
|
}
|