cleaned up old imported/decompiled files, basic shoutcast functionality

restored, disabled meta for streaming because of inconsistency issues.
This commit is contained in:
2013-12-15 21:31:11 +00:00
parent 74b42dec10
commit d903be9897
12 changed files with 68 additions and 38 deletions

View File

@@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import sound.util.Utils;
import javazoom.jl.decoder.Bitstream;
import javazoom.jl.decoder.BitstreamException;
import base.exception.worker.ActivateException;

View File

@@ -8,6 +8,7 @@ import java.io.IOException;
import org.farng.mp3.MP3File;
import org.farng.mp3.TagException;
import sound.util.Utils;
import base.exception.worker.ActivateException;
public class Mp3 extends Converter {

View File

@@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
public class GreedyInputStream extends BufferedInputStream {
protected Logger logger = LoggerFactory.getLogger(getClass());
protected static final int SLEEP = 500;
protected static final int SLEEP = 500; // in milliseconds
protected static final int BUFFER_SIZE = 30000; // in bytes
protected static final int MINIMUM_SIZE = 1000; // in bytes

View File

@@ -13,6 +13,7 @@ import javazoom.jl.player.Player;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sound.util.Tool;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.worker.Worker;

View File

@@ -10,6 +10,8 @@ import javax.sound.sampled.TargetDataLine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sound.util.Tool;
public class Target implements Producer, Format.Standard {
protected Logger logger = LoggerFactory.getLogger(getClass());

View File

@@ -1,4 +1,4 @@
package sound;
package sound.consumer;
import java.io.IOException;
import java.io.InputStream;
@@ -6,13 +6,17 @@ import java.io.OutputStream;
import javax.sound.sampled.AudioFormat;
import sound.Consumer;
import sound.Format;
import sound.Format.Standard;
import sound.Producer;
import sound.util.SoxBuilder;
import sound.util.SoxBuilder.File;
import sound.util.SoxBuilder.File.Type;
import sound.util.SoxBuilder.Option;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.worker.Worker;
import sound.Format.Standard;
import sound.SoxBuilder.File;
import sound.SoxBuilder.File.Type;
import sound.SoxBuilder.Option;
public class Port extends Worker implements Consumer {
protected static final int BUFFER_SIZE = 1024 * 4; // in bytes
@@ -48,7 +52,7 @@ public class Port extends Worker implements Consumer {
.setOption(Option.QUIET)
.addFile(File.setType(Type.DEVICE))
.build();
logger.debug(String.format("Build process (\"%s\")", command));
processBuilder = new ProcessBuilder(command.split(" "));
processBuilder.environment().put("AUDIODEV", device);

View File

@@ -1,4 +1,4 @@
package sound;
package sound.producer;
import java.io.IOException;
import java.io.InputStream;
@@ -7,6 +7,9 @@ import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.URL;
import sound.Format;
import sound.GreedyInputStream;
import sound.Producer;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.worker.Worker;
@@ -15,7 +18,6 @@ import com.Ostermiller.util.CircularByteBuffer;
import com.Ostermiller.util.CircularObjectBuffer;
public class Stream extends Worker implements Producer, Format.Mp3 {
public static final String HTTP = "http://shoutcast.omroep.nl:8104/";
public static final int STEP = 80; // in milliseconds
protected String http;
@@ -31,12 +33,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
protected CircularObjectBuffer<String> metaCircularObjectBuffer;
protected String metaData;
public Stream() {
this(HTTP);
}
public Stream(String http) {
super(true);
this.http = http;
meta = -1;
rate = -1;
@@ -52,9 +49,13 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
socketOutputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
/* Write stream request */
socketOutputStreamWriter.write("GET " + url.getFile() + " HTTP/1.1\r\n");
if (url.getFile().equals("")) {
socketOutputStreamWriter.write("GET / HTTP/1.1\r\n");
} else {
socketOutputStreamWriter.write("GET " + url.getFile() + " HTTP/1.1\r\n");
}
socketOutputStreamWriter.write("Host: " + url.getHost() + "\r\n");
socketOutputStreamWriter.write("Icy-MetaData: 1\r\n");
//socketOutputStreamWriter.write("Icy-MetaData: 1\r\n");
socketOutputStreamWriter.write("Connection: close\r\n");
socketOutputStreamWriter.write("\r\n");
socketOutputStreamWriter.flush();
@@ -104,7 +105,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
}
/* Calculate streaming parameters */
untilMeta = meta;
//untilMeta = meta;
chunk = STEP * rate / 8;
super.activate();
}
@@ -124,19 +125,18 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
protected void work() {
int left = chunk;
/* Handle media at appropriate times */
/* Handle media at appropriate times *
while (meta > 0 && left >= untilMeta) {
stream(untilMeta);
meta();
left -= untilMeta;
meta();
untilMeta = meta;
}
}*/
/* Stream at fixed rate */
stream(left);
untilMeta -= left;
//untilMeta -= left;
sleep(STEP);
}
protected void stream(int length) {
@@ -146,9 +146,9 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
while (length > 0 && (read = socketInputStream.read(bytes)) > 0) {
length -= read;
audioCircularByteBuffer.getOutputStream().write(bytes);
}
}
} catch (IOException e) {
logger.error("", e);
logger.error(e.getMessage());
stop();
}
}
@@ -158,6 +158,7 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
/* Retrieve data length */
byte[] data = new byte[1];
socketInputStream.read(data);
int length = 16 * data[0];
data = new byte[length];
socketInputStream.read(data);
@@ -178,10 +179,13 @@ public class Stream extends Worker implements Producer, Format.Mp3 {
logger.error("", e);
}
stop();
return;
}
public InputStream getInputStream() {
greedyInputStream = new GreedyInputStream(audioCircularByteBuffer.getInputStream());
if (greedyInputStream == null) {
greedyInputStream = new GreedyInputStream(audioCircularByteBuffer.getInputStream());
}
return greedyInputStream;
}

View File

@@ -1,13 +1,12 @@
package sound;
package sound.util;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.sound.sampled.AudioFormat;
import sound.SoxBuilder.Option.Combine;
import sound.SoxBuilder.Option.Replay;
import sound.util.SoxBuilder.Option.Combine;
import sound.util.SoxBuilder.Option.Replay;
public final class SoxBuilder {
protected static SoxBuilder instance;

View File

@@ -1,4 +1,4 @@
package sound;
package sound.util;
import java.util.ArrayList;
import java.util.HashMap;

View File

@@ -1,4 +1,4 @@
package old;
package sound.util;
import java.io.BufferedInputStream;
import java.io.File;

View File

@@ -1,25 +1,38 @@
package sound;
package test;
import javax.sound.sampled.AudioFormat;
import sound.Consumer;
import sound.Producer;
import sound.Source;
import sound.Target;
import sound.consumer.Port;
import sound.consumer.Shoutcast;
import sound.producer.Stream;
public class Test {
public static void main(String[] args) {
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 48000f, 16, 2, 4, 48000f, true);
try {
Producer p1 = new Target("Line-In (Creative SB X-Fi)");
//Producer p1 = new Target("Line-In (Creative SB X-Fi)");
Producer p2 = new Target("Line 1 (Virtual Audio Cable)", audioFormat);
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();
c2.start(p3);
//Utils.write(p3.getInputStream(), new File("stream.out"));
//Utils.play(p3.getInputStream());
c3.start(p3);
/*while (true) {
while (true) {
Thread.sleep(3000);
c2.stop();
Thread.sleep(1000);
c2.start();
}*/
}
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -5,6 +5,7 @@ import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
public class Main {
@@ -18,8 +19,12 @@ public class Main {
for (Line.Info lineInfo : mixer.getTargetLineInfo()) {
try {
Line line = mixer.getLine(lineInfo);
if (mixer.isLineSupported(lineInfo) && line instanceof TargetDataLine) {
new TargetLine(mixer, (TargetDataLine) line);
if (mixer.isLineSupported(lineInfo)) {
if (line instanceof TargetDataLine) {
new TargetLine(mixer, (TargetDataLine) line);
}/* else if (line instanceof SourceDataLine) {
new SourceLine(mixer, (SourceDataLine) line);
}*/
}
} catch (LineUnavailableException e) {}
}