Prepare to remove this branch

This commit is contained in:
2014-10-13 22:34:27 +01:00
parent d903be9897
commit 0a9ba6d684
15 changed files with 93 additions and 74 deletions

Binary file not shown.

View File

@@ -3,6 +3,7 @@ dependencies {
compile 'commons-io:commons-io:2.+'
compile 'commons-cli:commons-cli:1.+'
compile 'commons-pool:commons-pool:1.+'
compile 'org.slf4j:slf4j-api:1.+'
compile 'org.slf4j:slf4j-log4j12:1.7.5'
compile 'org.ostermiller:utils:1.+'

View File

@@ -1,7 +1,10 @@
package sound;
package old;
import java.io.InputStream;
import sound.Consumer;
import sound.Producer;
public class Transducer implements Consumer, Producer {
public int rate;

View File

@@ -8,8 +8,10 @@ public class Client {
// Connect to the pipe
RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\detest", "rw");
String echoText = "Hello word\n";
// write to pipe
pipe.write(echoText.getBytes());
// read response
String echoResponse = pipe.readLine();
System.out.println(echoResponse);

View File

@@ -1,40 +1,54 @@
package pipe;
/**
*
* @author Vikram S Khatri vikram.khatri@us.ibm.com
*
*/
public class Pipe
{
public class Pipe {
static final int ERROR_PIPE_CONNECTED = 535;
static final int ERROR_BROKEN_PIPE = 109;
static final int PIPE_ACCESS_DUPLEX = 0x00000003;
static final int PIPE_WAIT = 0x00000000;
static
{
static {
System.loadLibrary("pipe");
}
public static final native int CreateNamedPipe(String pipeName,
int ppenMode, int pipeMode, int maxInstances,
int outBufferSize, int inBufferSize, int defaultTimeOut,
public static final native int CreateNamedPipe(
String pipeName,
int ppenMode,
int pipeMode,
int maxInstances,
int outBufferSize,
int inBufferSize,
int defaultTimeOut,
int securityAttributes);
public static final native boolean ConnectNamedPipe(int namedPipeHandle,
int overlapped);
public static final native boolean ConnectNamedPipe(int namedPipeHandle, int overlapped);
public static final native int GetLastError();
public static final native boolean CloseHandle(int bbject);
public static final native byte[] ReadFile(int file, int numberOfBytesToRead);
public static final native int WriteFile(int file, byte[] buffer,
int numberOfBytesToWrite);
public static final native int WriteFile(int file, byte[] buffer, int numberOfBytesToWrite);
public static final native boolean FlushFileBuffers(int file);
public static final native boolean DisconnectNamedPipe(int namedPipeHandle);
public static final native int CreateFile(String fileName,
int desiredAccess, int shareMode, int securityAttributes,
int creationDisposition, int flagsAndAttributes,
public static final native int CreateFile(
String fileName,
int desiredAccess,
int shareMode,
int securityAttributes,
int creationDisposition,
int flagsAndAttributes,
int templateFile);
public static final native boolean WaitNamedPipe(String namedPipeName, int timeOut);
public static final native String FormatMessage(int errorCode);
public static final native void Print(String message);
}

View File

@@ -20,14 +20,19 @@ public class TestPipe {
}
private boolean createPipe() {
namedPipeHandle = Pipe.CreateNamedPipe(pipeName, Pipe.PIPE_ACCESS_DUPLEX,
Pipe.PIPE_WAIT, 5, pipeBuffer, pipeBuffer, 0xffffffff, 0);
namedPipeHandle = Pipe.CreateNamedPipe(
pipeName,
Pipe.PIPE_ACCESS_DUPLEX,
Pipe.PIPE_WAIT,
5,
pipeBuffer,
pipeBuffer,
0xffffffff,
0);
if (namedPipeHandle == -1) {
log("CreateNamedPipe failed for " + pipeName + " for error "
+ " Message " + Pipe.FormatMessage(Pipe.GetLastError()));
log("CreateNamedPipe failed for " + pipeName + " for error Message " + Pipe.FormatMessage(Pipe.GetLastError()));
} else {
log("Named Pipe " + pipeName + " created successfully Handle="
+ namedPipeHandle);
log("Named Pipe " + pipeName + " created successfully Handle=" + namedPipeHandle);
}
return namedPipeHandle != -1;
}
@@ -40,8 +45,7 @@ public class TestPipe {
if (lastError == Pipe.ERROR_PIPE_CONNECTED)
connected = true;
}
log((connected ? "Connected to the pipe "
: "Falied to connect to the pipe ") + pipeName);
log((connected ? "Connected to the pipe " : "Falied to connect to the pipe ") + pipeName);
return connected;
}
@@ -56,12 +60,10 @@ public class TestPipe {
int len, bytesWritten;
while ((len = in.read(buf)) > 0) {
bytesWritten = Pipe.WriteFile(namedPipeHandle, buf, len);
log("Sent " + len + "/" + bytesWritten
+ " bytes to the pipe");
log("Sent " + len + "/" + bytesWritten + " bytes to the pipe");
if (bytesWritten == -1) {
int errorNumber = Pipe.GetLastError();
log("Error Writing to pipe "
+ Pipe.FormatMessage(errorNumber));
log("Error Writing to pipe " + Pipe.FormatMessage(errorNumber));
}
}
in.close();
@@ -77,8 +79,8 @@ public class TestPipe {
public static void main(String[] args) {
String pipeName = "\\\\.\\pipe\\detest";
String fileName = "bla.txt";
fileName = "C:\\Users\\Rik\\Music\\Artists\\+44\\When Your Heart Stops Beating\\+44 - 155.mp3";
String fileName = "txt/bla.txt";
//fileName = "C:\\Users\\Rik\\Music\\Artists\\+44\\When Your Heart Stops Beating\\+44 - 155.mp3";
TestPipe testPipe = new TestPipe(pipeName, fileName);
testPipe.runPipe();
}

View File

@@ -2,7 +2,6 @@ package sound;
public interface Consumer {
public void start(Producer producer);
public void start();
public void stop();
public void exit();
}

View File

@@ -22,7 +22,7 @@ public class Source implements Consumer {
protected Logger logger = LoggerFactory.getLogger(getClass());
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
protected static final int PLAY_FRAMES = 10; // count
protected static final int FRAMES = 10; // count
protected String name;
protected Producer producer;
@@ -147,9 +147,9 @@ public class Source implements Consumer {
try {
if (player == null) {
player = new Player(producerInputStream);
sleep(500);
sleep(SLEEP);
}
player.play(PLAY_FRAMES);
player.play(FRAMES);
} catch (JavaLayerException e) {
logger.error("", e);
}

View File

@@ -36,8 +36,12 @@ public class Port extends Worker implements Consumer {
this.device = device;
}
@SuppressWarnings("static-access")
public void start(Producer producer) {
start(producer, THREAD);
}
@SuppressWarnings("static-access")
public void start(Producer producer, boolean thread) {
this.producer = producer;
producerInputStream = producer.getInputStream();
@@ -57,7 +61,7 @@ public class Port extends Worker implements Consumer {
processBuilder = new ProcessBuilder(command.split(" "));
processBuilder.environment().put("AUDIODEV", device);
start(true);
start(thread);
}
protected void activate() throws ActivateException {
@@ -114,16 +118,4 @@ public class Port extends Worker implements Consumer {
exit();
}
}
@Override
public void start() {
// TODO Auto-generated method stub
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
}

View File

@@ -8,8 +8,8 @@ import java.net.Socket;
import java.net.URL;
import sound.Format;
import sound.GreedyInputStream;
import sound.Producer;
import sound.stream.HoardedInputStream;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.worker.Worker;
@@ -24,7 +24,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
protected Socket socket;
protected InputStream socketInputStream;
protected OutputStreamWriter socketOutputStreamWriter;
protected GreedyInputStream greedyInputStream;
protected HoardedInputStream hoardedInputStream;
protected int meta;
protected int rate;
protected int chunk;
@@ -115,7 +115,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
audioCircularByteBuffer.clear();
metaCircularObjectBuffer.clear();
try {
greedyInputStream.clear();
hoardedInputStream.clear();
} catch (IOException e) {
logger.error("", e);
throw new DeactivateException();
@@ -183,10 +183,10 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
}
public InputStream getInputStream() {
if (greedyInputStream == null) {
greedyInputStream = new GreedyInputStream(audioCircularByteBuffer.getInputStream());
if (hoardedInputStream == null) {
hoardedInputStream = new HoardedInputStream(audioCircularByteBuffer.getInputStream());
}
return greedyInputStream;
return hoardedInputStream;
}
public CircularObjectBuffer<String> getMetaBufferStream() {

View File

@@ -1,4 +1,4 @@
package sound;
package sound.producer;
import java.io.IOException;
import java.io.InputStream;
@@ -10,6 +10,9 @@ import javax.sound.sampled.TargetDataLine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sound.Format;
import sound.Producer;
import sound.stream.HoardedInputStream;
import sound.util.Tool;
public class Target implements Producer, Format.Standard {
@@ -19,6 +22,7 @@ public class Target implements Producer, Format.Standard {
protected TargetDataLine line;
protected InputStream targetInputStream;
protected HoardedInputStream hoardedInputStream;
protected AudioFormat audioFormat;

View File

@@ -1,4 +1,4 @@
package sound;
package sound.stream;
import java.io.BufferedInputStream;
import java.io.IOException;
@@ -7,7 +7,7 @@ import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GreedyInputStream extends BufferedInputStream {
public class HoardedInputStream extends BufferedInputStream {
protected Logger logger = LoggerFactory.getLogger(getClass());
protected static final int SLEEP = 500; // in milliseconds
@@ -18,17 +18,17 @@ public class GreedyInputStream extends BufferedInputStream {
protected int minimumSize;
protected boolean hoard;
public GreedyInputStream(InputStream inputStream) {
public HoardedInputStream(InputStream inputStream) {
this(inputStream, BUFFER_SIZE, MINIMUM_SIZE);
}
public GreedyInputStream(InputStream inputStream, int bufferSize) {
public HoardedInputStream(InputStream inputStream, int bufferSize) {
super(inputStream, bufferSize);
this.bufferSize = bufferSize;
hoard = true;
}
public GreedyInputStream(InputStream inputStream, int bufferSize, int minimumSize) {
public HoardedInputStream(InputStream inputStream, int bufferSize, int minimumSize) {
this(inputStream, bufferSize);
this.minimumSize = minimumSize;
}

View File

@@ -15,12 +15,9 @@ public class Utils {
public static void play(InputStream inputStream) {
try {
Thread.sleep(5000);
new Player(new BufferedInputStream(inputStream)).play();
} catch (JavaLayerException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

View File

@@ -1,14 +1,18 @@
package test;
import java.io.File;
import javax.sound.sampled.AudioFormat;
import sound.Consumer;
import sound.Producer;
import sound.Source;
import sound.Target;
import sound.consumer.Player;
import sound.consumer.Port;
import sound.consumer.Shoutcast;
import sound.consumer.Writer;
import sound.producer.Stream;
import sound.producer.Target;
public class Test {
public static void main(String[] args) {
@@ -16,23 +20,24 @@ public class Test {
try {
//Producer p1 = new Target("Line-In (Creative SB X-Fi)");
Producer p2 = new Target("Line 1 (Virtual Audio Cable)", audioFormat);
p2.start();
Producer p3 = new Stream("http://ics2gss.omroep.nl:80/3fm-bb-mp3");
Producer p4 = new Stream("http://sc7.mystreamserver.com:8004");
Consumer c1 = new Source("Java Sound Audio Engine");
Consumer c2 = new Port("Speakers (Creative SB X-Fi)");
Consumer c3 = new Shoutcast();
Consumer c4 = new Player();
Consumer c5 = new Writer(new File("stream.out"));
//Utils.write(p3.getInputStream(), new File("stream.out"));
//Utils.play(p3.getInputStream());
c3.start(p3);
while (true) {
Thread.sleep(3000);
c2.stop();
Thread.sleep(1000);
c2.start();
}
//while (true) {
//Thread.sleep(300000);
//c1.stop();
//}
} catch (Exception e) {
e.printStackTrace();
}