Skip to content
Browse files

Increased priority of UpdateRunner thread. Added checks for negative/…

…too-large frame lengths.
  • Loading branch information...
1 parent 515d786 commit 0680c3770b4482957fe9352c1a280e2742494309 @finnkuusisto committed Mar 14, 2012
View
4 doc/allclasses-frame.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
All Classes
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/allclasses-noframe.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
All Classes
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/constant-values.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Constant Field Values
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/deprecated-list.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Deprecated List
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/help-doc.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
API Help
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/index-all.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Index
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="./stylesheet.css" TITLE="Style">
View
2 doc/index.html
@@ -2,7 +2,7 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc on Sat Mar 03 23:27:54 CST 2012-->
+<!-- Generated by javadoc on Wed Mar 14 23:33:18 CDT 2012-->
<TITLE>
Generated Documentation (Untitled)
</TITLE>
View
4 doc/kuusisto/tinysound/Music.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Music
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/Sound.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Sound
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/TinySound.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
TinySound
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/Mixer.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Mixer
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/MusicReference.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
MusicReference
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/SoundReference.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
SoundReference
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/UpdateRunner.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
UpdateRunner
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/package-frame.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
kuusisto.tinysound.internal
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/package-summary.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
kuusisto.tinysound.internal
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/internal/package-tree.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
kuusisto.tinysound.internal Class Hierarchy
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/package-frame.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
kuusisto.tinysound
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/package-summary.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
kuusisto.tinysound
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
View
4 doc/kuusisto/tinysound/package-tree.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
kuusisto.tinysound Class Hierarchy
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
View
4 doc/overview-frame.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Overview List
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/overview-summary.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Overview
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
4 doc/overview-tree.html
@@ -2,12 +2,12 @@
<!--NewPage-->
<HTML>
<HEAD>
-<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 23:27:54 CST 2012 -->
+<!-- Generated by javadoc (build 1.6.0_11) on Wed Mar 14 23:33:18 CDT 2012 -->
<TITLE>
Class Hierarchy
</TITLE>
-<META NAME="date" CONTENT="2012-03-03">
+<META NAME="date" CONTENT="2012-03-14">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
View
34 src/kuusisto/tinysound/TinySound.java
@@ -108,7 +108,10 @@ public static void init() {
TinySound.autoUpdater = new UpdateRunner(TinySound.mixer,
TinySound.outLine);
Thread updateThread = new Thread(TinySound.autoUpdater);
- updateThread.setDaemon(true);
+ try {
+ updateThread.setDaemon(true);
+ updateThread.setPriority(Thread.MAX_PRIORITY);
+ } catch (Exception e) {}
TinySound.inited = true;
updateThread.start();
}
@@ -451,6 +454,7 @@ else if (numChannels == 2) {
private static AudioInputStream getValidAudioStream(InputStream stream) {
AudioInputStream audioStream = null;
try {
+ boolean converted = false;
audioStream = AudioSystem.getAudioInputStream(stream);
//1-channel can also be treated as stereo
AudioFormat mono = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
@@ -470,11 +474,13 @@ else if (AudioSystem.isConversionSupported(TinySound.FORMAT,
audioStream.getFormat())) {
audioStream = AudioSystem.getAudioInputStream(TinySound.FORMAT,
audioStream);
+ converted = true;
} //check conversion to mono alternate
else if (AudioSystem.isConversionSupported(mono,
audioStream.getFormat())) {
audioStream = AudioSystem.getAudioInputStream(mono,
audioStream);
+ converted = true;
} //try convert from 8-bit, 2-channel
else if (audioStream.getFormat().equals(stereo8) ||
AudioSystem.isConversionSupported(stereo8,
@@ -483,8 +489,9 @@ else if (audioStream.getFormat().equals(stereo8) ||
if (!audioStream.getFormat().equals(stereo8)) {
audioStream = AudioSystem.getAudioInputStream(stereo8,
audioStream);
+ converted = true;
}
- audioStream = TinySound.getTwoChannel8Bit(audioStream);
+ audioStream = TinySound.convertStereo8Bit(audioStream);
} //try convert from 8-bit, 1-channel
else if (audioStream.getFormat().equals(mono8) ||
AudioSystem.isConversionSupported(mono8,
@@ -493,15 +500,32 @@ else if (audioStream.getFormat().equals(mono8) ||
if (!audioStream.getFormat().equals(mono8)) {
audioStream = AudioSystem.getAudioInputStream(mono8,
audioStream);
+ converted = true;
}
- audioStream = TinySound.getOneChannel8Bit(audioStream);
+ audioStream = TinySound.convertMono8Bit(audioStream);
} //it's time to give up
else {
System.err.println("Unable to convert audio resource!");
System.err.println(audioStream.getFormat());
audioStream.close();
return null;
}
+ //check the frame length
+ long frameLength = audioStream.getFrameLength();
+ //too long
+ if (frameLength > Integer.MAX_VALUE) {
+ System.err.println("Audio resource too long!");
+ return null;
+ } //conversion left frame length unspecified
+ else if (frameLength < 0 && converted) {
+ System.err.println("Converted audio resource has unspecified " +
+ "length!");
+ return null;
+ } //non-converted frame length unspecified
+ else if (frameLength < 0) {
+ System.err.println("Audio resource has unspecified length!");
+ return null;
+ }
}
catch (UnsupportedAudioFileException e) {
System.err.println("Unsupported audio resource!\n" +
@@ -524,7 +548,7 @@ else if (audioStream.getFormat().equals(mono8) ||
* @param stream stream to convert
* @return converted stream
*/
- private static AudioInputStream getOneChannel8Bit(AudioInputStream stream) {
+ private static AudioInputStream convertMono8Bit(AudioInputStream stream) {
//assuming 8-bit, 1-channel to 16-bit, 1-channel
int numFrames = (int)stream.getFrameLength();
int numBytes = numFrames * 2;
@@ -573,7 +597,7 @@ else if (floatVal > 1.0) {
* @param stream stream to convert
* @return converted stream
*/
- private static AudioInputStream getTwoChannel8Bit(AudioInputStream stream) {
+ private static AudioInputStream convertStereo8Bit(AudioInputStream stream) {
//assuming 8-bit, 2-channel to 16-bit, 2-channel
int numFrames = (int)stream.getFrameLength();
int numBytes = numFrames * 2 * 2; //2-bytes, 2-channels
View
6 src/kuusisto/tinysound/internal/UpdateRunner.java
@@ -73,9 +73,13 @@ public void run() {
byte[] audioBuffer = new byte[bufSize];
int numBytesRead = 0;
double framesAccrued = 0;
- long lastUpdate = System.nanoTime();
+ long lastUpdate = 0;
//keep running until told to stop
while (this.running.get()) {
+ //first time
+ if (lastUpdate == 0) {
+ lastUpdate = System.nanoTime();
+ }
//check the time
long currTime = System.nanoTime();
//accrue frames
View
BIN tinysound.jar
Binary file not shown.

0 comments on commit 0680c37

Please sign in to comment.
Something went wrong with that request. Please try again.