Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed buffering method. Auto-updating no longer configurable.

  • Loading branch information...
commit 8a1ba027e26c1238aea1cbb00ee55c3681336270 1 parent dd87ccd
Finn Kuusisto authored March 03, 2012

Showing 26 changed files with 157 additions and 213 deletions. Show diff stats Hide diff stats

  1. 4  doc/allclasses-frame.html
  2. 4  doc/allclasses-noframe.html
  3. 4  doc/constant-values.html
  4. 4  doc/deprecated-list.html
  5. 4  doc/help-doc.html
  6. 19  doc/index-all.html
  7. 2  doc/index.html
  8. 4  doc/kuusisto/tinysound/Music.html
  9. 4  doc/kuusisto/tinysound/Sound.html
  10. 85  doc/kuusisto/tinysound/TinySound.html
  11. 4  doc/kuusisto/tinysound/internal/Mixer.html
  12. 4  doc/kuusisto/tinysound/internal/MusicReference.html
  13. 4  doc/kuusisto/tinysound/internal/SoundReference.html
  14. 4  doc/kuusisto/tinysound/internal/UpdateRunner.html
  15. 4  doc/kuusisto/tinysound/internal/package-frame.html
  16. 4  doc/kuusisto/tinysound/internal/package-summary.html
  17. 4  doc/kuusisto/tinysound/internal/package-tree.html
  18. 4  doc/kuusisto/tinysound/package-frame.html
  19. 4  doc/kuusisto/tinysound/package-summary.html
  20. 4  doc/kuusisto/tinysound/package-tree.html
  21. 4  doc/overview-frame.html
  22. 4  doc/overview-summary.html
  23. 4  doc/overview-tree.html
  24. 179  src/kuusisto/tinysound/TinySound.java
  25. 3  src/kuusisto/tinysound/internal/Mixer.java
  26. 2  src/kuusisto/tinysound/internal/UpdateRunner.java
4  doc/allclasses-frame.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 All Classes
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
4  doc/allclasses-noframe.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 All Classes
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
4  doc/constant-values.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Constant Field Values
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
4  doc/deprecated-list.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Deprecated List
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
4  doc/help-doc.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 API Help
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
19  doc/index-all.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Index
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="./stylesheet.css" TITLE="Style">
13 13
 
@@ -148,15 +148,10 @@
148 148
 <DL>
149 149
 <DT><A HREF="./kuusisto/tinysound/TinySound.html#init()"><B>init()</B></A> - 
150 150
 Static method in class kuusisto.tinysound.<A HREF="./kuusisto/tinysound/TinySound.html" title="class in kuusisto.tinysound">TinySound</A>
151  
-<DD>Initialize the AudioSystem with the default update rate of 40Hz and
152  
- auto-updating on.
153  
-<DT><A HREF="./kuusisto/tinysound/TinySound.html#init(int, boolean)"><B>init(int, boolean)</B></A> - 
  151
+<DD>Initialize the AudioSystem with the default update rate of 100Hz.
  152
+<DT><A HREF="./kuusisto/tinysound/TinySound.html#init(int)"><B>init(int)</B></A> - 
154 153
 Static method in class kuusisto.tinysound.<A HREF="./kuusisto/tinysound/TinySound.html" title="class in kuusisto.tinysound">TinySound</A>
155  
-<DD>Initialize the AudioSystem with a desired update rate and desired
156  
- auto-update setting.
157  
-<DT><A HREF="./kuusisto/tinysound/TinySound.html#isAutoUpdating()"><B>isAutoUpdating()</B></A> - 
158  
-Static method in class kuusisto.tinysound.<A HREF="./kuusisto/tinysound/TinySound.html" title="class in kuusisto.tinysound">TinySound</A>
159  
-<DD>Determine whether the TinySound is set to auto-update.
  154
+<DD>Initialize the AudioSystem with a desired update rate.
160 155
 </DL>
161 156
 <HR>
162 157
 <A NAME="_K_"><!-- --></A><H2>
@@ -357,10 +352,6 @@
357 352
 Static method in class kuusisto.tinysound.<A HREF="./kuusisto/tinysound/TinySound.html" title="class in kuusisto.tinysound">TinySound</A>
358 353
 <DD>Write a buffer of audio data to the speakers and fill the audio buffer
359 354
  for the next update.
360  
-<DT><A HREF="./kuusisto/tinysound/TinySound.html#update(boolean)"><B>update(boolean)</B></A> - 
361  
-Static method in class kuusisto.tinysound.<A HREF="./kuusisto/tinysound/TinySound.html" title="class in kuusisto.tinysound">TinySound</A>
362  
-<DD>Write a buffer of audio data to the speakers and fill the audio buffer
363  
- for the next update as specified.
364 355
 <DT><A HREF="./kuusisto/tinysound/internal/UpdateRunner.html" title="class in kuusisto.tinysound.internal"><B>UpdateRunner</B></A> - Class in <A HREF="./kuusisto/tinysound/internal/package-summary.html">kuusisto.tinysound.internal</A><DD>The UpdateRunner class implements Runnable and is what performs automatic
365 356
  updates of the TinySound system.<DT><A HREF="./kuusisto/tinysound/internal/UpdateRunner.html#UpdateRunner(int)"><B>UpdateRunner(int)</B></A> - 
366 357
 Constructor for class kuusisto.tinysound.internal.<A HREF="./kuusisto/tinysound/internal/UpdateRunner.html" title="class in kuusisto.tinysound.internal">UpdateRunner</A>
2  doc/index.html
@@ -2,7 +2,7 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc on Tue Feb 28 21:38:16 CST 2012-->
  5
+<!-- Generated by javadoc on Sat Mar 03 12:10:31 CST 2012-->
6 6
 <TITLE>
7 7
 Generated Documentation (Untitled)
8 8
 </TITLE>
4  doc/kuusisto/tinysound/Music.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:30 CST 2012 -->
6 6
 <TITLE>
7 7
 Music
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/Sound.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Sound
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13 13
 
85  doc/kuusisto/tinysound/TinySound.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 TinySound
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13 13
 
@@ -103,8 +103,7 @@
103 103
 TinySound is the main class of the TinySound system.  In order to use the
104 104
  TinySound system, it must be initialized.  After that, Music and Sound
105 105
  objects can be loaded and used.  When finished with the TinySound system, it
106  
- must be shutdown.  Shutdown is especially important if the system has been
107  
- initialized to update automatically.
  106
+ must be shutdown.
108 107
 <P>
109 108
 
110 109
 <P>
@@ -171,26 +170,15 @@
171 170
 <TD><CODE><B><A HREF="../../kuusisto/tinysound/TinySound.html#init()">init</A></B>()</CODE>
172 171
 
173 172
 <BR>
174  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initialize the AudioSystem with the default update rate of 40Hz and
175  
- auto-updating on.</TD>
  173
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initialize the AudioSystem with the default update rate of 100Hz.</TD>
176 174
 </TR>
177 175
 <TR BGCOLOR="white" CLASS="TableRowColor">
178 176
 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
179 177
 <CODE>static&nbsp;void</CODE></FONT></TD>
180  
-<TD><CODE><B><A HREF="../../kuusisto/tinysound/TinySound.html#init(int, boolean)">init</A></B>(int&nbsp;updateRate,
181  
-     boolean&nbsp;autoUpdate)</CODE>
  178
+<TD><CODE><B><A HREF="../../kuusisto/tinysound/TinySound.html#init(int)">init</A></B>(int&nbsp;updateRate)</CODE>
182 179
 
183 180
 <BR>
184  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initialize the AudioSystem with a desired update rate and desired
185  
- auto-update setting.</TD>
186  
-</TR>
187  
-<TR BGCOLOR="white" CLASS="TableRowColor">
188  
-<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
189  
-<CODE>static&nbsp;boolean</CODE></FONT></TD>
190  
-<TD><CODE><B><A HREF="../../kuusisto/tinysound/TinySound.html#isAutoUpdating()">isAutoUpdating</A></B>()</CODE>
191  
-
192  
-<BR>
193  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Determine whether the TinySound is set to auto-update.</TD>
  181
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initialize the AudioSystem with a desired update rate.</TD>
194 182
 </TR>
195 183
 <TR BGCOLOR="white" CLASS="TableRowColor">
196 184
 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
@@ -273,15 +261,6 @@
273 261
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Write a buffer of audio data to the speakers and fill the audio buffer
274 262
  for the next update.</TD>
275 263
 </TR>
276  
-<TR BGCOLOR="white" CLASS="TableRowColor">
277  
-<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
278  
-<CODE>static&nbsp;void</CODE></FONT></TD>
279  
-<TD><CODE><B><A HREF="../../kuusisto/tinysound/TinySound.html#update(boolean)">update</A></B>(boolean&nbsp;fillNextBuffer)</CODE>
280  
-
281  
-<BR>
282  
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Write a buffer of audio data to the speakers and fill the audio buffer
283  
- for the next update as specified.</TD>
284  
-</TR>
285 264
 </TABLE>
286 265
 &nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
287 266
 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
@@ -348,8 +327,8 @@
348 327
 <PRE>
349 328
 public static void <B>init</B>()</PRE>
350 329
 <DL>
351  
-<DD>Initialize the AudioSystem with the default update rate of 40Hz and
352  
- auto-updating on.  This is probably sufficient for most users.
  330
+<DD>Initialize the AudioSystem with the default update rate of 100Hz.  This
  331
+ is probably sufficient for most users.
353 332
 <P>
354 333
 <DD><DL>
355 334
 </DL>
@@ -357,21 +336,18 @@
357 336
 </DL>
358 337
 <HR>
359 338
 
360  
-<A NAME="init(int, boolean)"><!-- --></A><H3>
  339
+<A NAME="init(int)"><!-- --></A><H3>
361 340
 init</H3>
362 341
 <PRE>
363  
-public static void <B>init</B>(int&nbsp;updateRate,
364  
-                        boolean&nbsp;autoUpdate)</PRE>
  342
+public static void <B>init</B>(int&nbsp;updateRate)</PRE>
365 343
 <DL>
366  
-<DD>Initialize the AudioSystem with a desired update rate and desired
367  
- auto-update setting.  The AudioSystem will attempt to allocate an audio
368  
- buffer that is most appropriate for the specified update rate.  If the
369  
- AudioSystem is not set to auto-update, the user must update the
370  
- AudioSystem at the specified update rate.
  344
+<DD>Initialize the AudioSystem with a desired update rate.  The AudioSystem
  345
+ will attempt to allocate an audio buffer that is appropriate for the
  346
+ specified update rate.
371 347
 <P>
372 348
 <DD><DL>
373 349
 <DT><B>Parameters:</B><DD><CODE>updateRate</CODE> - the desired update rate of the AudioSystem, in updates
374  
- per second<DD><CODE>autoUpdate</CODE> - true if auto-updating is desired</DL>
  350
+ per second</DL>
375 351
 </DD>
376 352
 </DL>
377 353
 <HR>
@@ -403,28 +379,14 @@
403 379
 </DL>
404 380
 <HR>
405 381
 
406  
-<A NAME="isAutoUpdating()"><!-- --></A><H3>
407  
-isAutoUpdating</H3>
408  
-<PRE>
409  
-public static boolean <B>isAutoUpdating</B>()</PRE>
410  
-<DL>
411  
-<DD>Determine whether the TinySound is set to auto-update.
412  
-<P>
413  
-<DD><DL>
414  
-
415  
-<DT><B>Returns:</B><DD>true if the TinySound is set to auto-update</DL>
416  
-</DD>
417  
-</DL>
418  
-<HR>
419  
-
420 382
 <A NAME="update()"><!-- --></A><H3>
421 383
 update</H3>
422 384
 <PRE>
423 385
 public static void <B>update</B>()</PRE>
424 386
 <DL>
425 387
 <DD>Write a buffer of audio data to the speakers and fill the audio buffer
426  
- for the next update.  This or the other update method must be called
427  
- regularly if not auto-updating.
  388
+ for the next update.  TinySound users shouldn't concern themselves with
  389
+ this method.
428 390
 <P>
429 391
 <DD><DL>
430 392
 </DL>
@@ -432,21 +394,6 @@
432 394
 </DL>
433 395
 <HR>
434 396
 
435  
-<A NAME="update(boolean)"><!-- --></A><H3>
436  
-update</H3>
437  
-<PRE>
438  
-public static void <B>update</B>(boolean&nbsp;fillNextBuffer)</PRE>
439  
-<DL>
440  
-<DD>Write a buffer of audio data to the speakers and fill the audio buffer
441  
- for the next update as specified.  This or the other update method must
442  
- be called regularly if not auto-updating.
443  
-<P>
444  
-<DD><DL>
445  
-<DT><B>Parameters:</B><DD><CODE>fillNextBuffer</CODE> - true if the next audio buffer should be filled</DL>
446  
-</DD>
447  
-</DL>
448  
-<HR>
449  
-
450 397
 <A NAME="loadMusic(java.lang.String)"><!-- --></A><H3>
451 398
 loadMusic</H3>
452 399
 <PRE>
4  doc/kuusisto/tinysound/internal/Mixer.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Mixer
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/internal/MusicReference.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 MusicReference
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/internal/SoundReference.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 SoundReference
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/internal/UpdateRunner.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 UpdateRunner
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/internal/package-frame.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 kuusisto.tinysound.internal
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/internal/package-summary.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 kuusisto.tinysound.internal
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/internal/package-tree.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 kuusisto.tinysound.internal Class Hierarchy
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/package-frame.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 kuusisto.tinysound
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/package-summary.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 kuusisto.tinysound
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/kuusisto/tinysound/package-tree.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 kuusisto.tinysound Class Hierarchy
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
13 13
 
4  doc/overview-frame.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Overview List
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
4  doc/overview-summary.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Overview
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
4  doc/overview-tree.html
@@ -2,12 +2,12 @@
2 2
 <!--NewPage-->
3 3
 <HTML>
4 4
 <HEAD>
5  
-<!-- Generated by javadoc (build 1.6.0_11) on Tue Feb 28 21:38:16 CST 2012 -->
  5
+<!-- Generated by javadoc (build 1.6.0_11) on Sat Mar 03 12:10:31 CST 2012 -->
6 6
 <TITLE>
7 7
 Class Hierarchy
8 8
 </TITLE>
9 9
 
10  
-<META NAME="date" CONTENT="2012-02-28">
  10
+<META NAME="date" CONTENT="2012-03-03">
11 11
 
12 12
 <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
13 13
 
179  src/kuusisto/tinysound/TinySound.java
@@ -50,8 +50,7 @@
50 50
  * TinySound is the main class of the TinySound system.  In order to use the
51 51
  * TinySound system, it must be initialized.  After that, Music and Sound
52 52
  * objects can be loaded and used.  When finished with the TinySound system, it
53  
- * must be shutdown.  Shutdown is especially important if the system has been
54  
- * initialized to update automatically.
  53
+ * must be shutdown.
55 54
  * 
56 55
  * @author Finn Kuusisto
57 56
  */
@@ -76,36 +75,33 @@
76 75
 	private static int updateRate;
77 76
 	private static byte[] audioBuffer;
78 77
 	private static int numBytesRead;
79  
-	private static double driftFramesPerUpdate;
80  
-	private static double driftFramesAccrued;
  78
+	private static long lastUpdate;
  79
+	private static boolean isFirstUpdate;
81 80
 	//need a line to the speakers
82 81
 	private static SourceDataLine outLine;
83 82
 	//see if the system has been initialized
84 83
 	private static boolean inited = false;
85  
-	//see if the system is auto-updating
86  
-	private static boolean autoUpdate;
  84
+	//auto-updater for the system
87 85
 	private static UpdateRunner autoUpdater;
  86
+	private static double driftFramesAccrued;
88 87
 	
89 88
 	/**
90  
-	 * Initialize the AudioSystem with the default update rate of 40Hz and
91  
-	 * auto-updating on.  This is probably sufficient for most users.
  89
+	 * Initialize the AudioSystem with the default update rate of 100Hz.  This
  90
+	 * is probably sufficient for most users.
92 91
 	 */
93 92
 	public static void init() {
94  
-		//default to 40Hz, auto-update
95  
-		TinySound.init(40, true);
  93
+		//default to 100Hz, auto-update
  94
+		TinySound.init(100);
96 95
 	}
97 96
 	
98 97
 	/**
99  
-	 * Initialize the AudioSystem with a desired update rate and desired
100  
-	 * auto-update setting.  The AudioSystem will attempt to allocate an audio
101  
-	 * buffer that is most appropriate for the specified update rate.  If the
102  
-	 * AudioSystem is not set to auto-update, the user must update the
103  
-	 * AudioSystem at the specified update rate.
  98
+	 * Initialize the AudioSystem with a desired update rate.  The AudioSystem
  99
+	 * will attempt to allocate an audio buffer that is appropriate for the
  100
+	 * specified update rate.
104 101
 	 * @param updateRate the desired update rate of the AudioSystem, in updates
105 102
 	 * per second
106  
-	 * @param autoUpdate true if auto-updating is desired
107 103
 	 */
108  
-	public static void init(int updateRate, boolean autoUpdate) {
  104
+	public static void init(int updateRate) {
109 105
 		if (TinySound.inited) {
110 106
 			return;
111 107
 		}
@@ -129,32 +125,23 @@ public static void init(int updateRate, boolean autoUpdate) {
129 125
 		//now initialize the other stuff
130 126
 		TinySound.mixer = new Mixer();
131 127
 		TinySound.updateRate = updateRate;
132  
-		//compute the buffer size needed for update rate
133  
-		double framesPerUpdate = TinySound.FORMAT.getSampleRate() / updateRate;
134  
-		double bytesPerUpdate =
135  
-			framesPerUpdate * TinySound.FORMAT.getFrameSize();
136  
-		int bufSize = //make sure it's a multiple of frame size
137  
-			((int)framesPerUpdate + 1) * TinySound.FORMAT.getFrameSize();
  128
+		//1/2 second + 1 update
  129
+		int halfSecFrames = (int)(TinySound.FORMAT.getFrameRate() / 2);
  130
+		int updateFrames = (int)(TinySound.FORMAT.getFrameRate() / updateRate);
  131
+		int bufSize = (halfSecFrames * TinySound.FORMAT.getFrameSize()) +
  132
+				(updateFrames * TinySound.FORMAT.getFrameSize());
138 133
 		TinySound.audioBuffer = new byte[bufSize];
139 134
 		TinySound.numBytesRead = 0;
140  
-		//now calculate frame drift per update
141  
-		double byteDriftPerUpdate = (double)bufSize - bytesPerUpdate;
142  
-		TinySound.driftFramesPerUpdate = byteDriftPerUpdate /
143  
-			TinySound.FORMAT.getFrameSize();
144  
-		if (TinySound.driftFramesPerUpdate < 0.0) { //just in case
145  
-			TinySound.driftFramesPerUpdate = 0.0;
146  
-		}
147  
-		TinySound.driftFramesAccrued = 0.0;
148  
-		//start the updater if set to autoUpdate
149  
-		TinySound.autoUpdate = autoUpdate;
150  
-		if (autoUpdate) {
151  
-			TinySound.autoUpdater = new UpdateRunner(updateRate);
152  
-			Thread updateThread = new Thread(TinySound.autoUpdater);
153  
-			updateThread.setDaemon(true);
154  
-			TinySound.inited = true;
155  
-			updateThread.start();
156  
-		}
  135
+		TinySound.isFirstUpdate = true;
  136
+		//buffer 10ms of audio
  137
+		int tenMSFrames = (int)TinySound.FORMAT.getFrameRate() / 100;
  138
+		TinySound.preFillAudioBuffer(tenMSFrames);
  139
+		//initialize and start the updater
  140
+		TinySound.autoUpdater = new UpdateRunner(updateRate);
  141
+		Thread updateThread = new Thread(TinySound.autoUpdater);
  142
+		updateThread.setDaemon(true);
157 143
 		TinySound.inited = true;
  144
+		updateThread.start();
158 145
 	}
159 146
 	
160 147
 	/**
@@ -166,20 +153,18 @@ public static void shutdown() {
166 153
 		}
167 154
 		TinySound.inited = false;
168 155
 		//stop the auto-updater if running
169  
-		if (TinySound.autoUpdate) {
170  
-			TinySound.autoUpdater.stop();
171  
-			TinySound.autoUpdater = null;
172  
-			TinySound.autoUpdate = false;
173  
-		}
  156
+		TinySound.autoUpdater.stop();
  157
+		TinySound.autoUpdater = null;
174 158
 		TinySound.outLine.stop();
175 159
 		TinySound.outLine.flush();
176 160
 		TinySound.mixer.clearMusic();
177 161
 		TinySound.mixer.clearSounds();
178 162
 		TinySound.mixer = null;
179 163
 		TinySound.updateRate = 0;
  164
+		TinySound.lastUpdate = 0;
  165
+		TinySound.isFirstUpdate = true;
180 166
 		TinySound.audioBuffer = null;
181 167
 		TinySound.numBytesRead = 0;
182  
-		TinySound.driftFramesPerUpdate = 0.0;
183 168
 		TinySound.driftFramesAccrued = 0.0;
184 169
 	}
185 170
 	
@@ -192,17 +177,9 @@ public static int getUpdateRate() {
192 177
 	}
193 178
 	
194 179
 	/**
195  
-	 * Determine whether the TinySound is set to auto-update.
196  
-	 * @return true if the TinySound is set to auto-update
197  
-	 */
198  
-	public static boolean isAutoUpdating() {
199  
-		return TinySound.autoUpdate;
200  
-	}
201  
-	
202  
-	/**
203 180
 	 * Write a buffer of audio data to the speakers and fill the audio buffer
204  
-	 * for the next update.  This or the other update method must be called
205  
-	 * regularly if not auto-updating.
  181
+	 * for the next update.  TinySound users shouldn't concern themselves with
  182
+	 * this method.
206 183
 	 */
207 184
 	public static void update() {
208 185
 		if (!TinySound.inited) {
@@ -214,23 +191,29 @@ public static void update() {
214 191
 	
215 192
 	/**
216 193
 	 * Write a buffer of audio data to the speakers and fill the audio buffer
217  
-	 * for the next update as specified.  This or the other update method must
218  
-	 * be called regularly if not auto-updating.
  194
+	 * for the next update as specified.
219 195
 	 * @param fillNextBuffer true if the next audio buffer should be filled
220 196
 	 */
221  
-	public static void update(boolean fillNextBuffer) {
  197
+	private static void update(boolean fillNextBuffer) {
222 198
 		if (!TinySound.inited) {
223 199
 			System.err.println("TinySound not initialized!");
224 200
 			return;
225 201
 		}
226  
-		//read from the mixer if not filling for the next update
  202
+		//check for first update
  203
+		if (TinySound.isFirstUpdate) {
  204
+			TinySound.lastUpdate = System.nanoTime();
  205
+			TinySound.isFirstUpdate = false;
  206
+		}
  207
+		//drain the buffer if there is any
227 208
 		if (TinySound.numBytesRead <= 0) {
228 209
 			TinySound.fillAudioBuffer();
229 210
 		}
230  
-		//and write to the speakers
231  
-		TinySound.outLine.write(TinySound.audioBuffer, 0,
232  
-				TinySound.numBytesRead);
233  
-		TinySound.numBytesRead = 0;
  211
+		if (TinySound.numBytesRead > 0) {
  212
+			//and write to the speakers
  213
+			TinySound.outLine.write(TinySound.audioBuffer, 0,
  214
+					TinySound.numBytesRead);
  215
+			TinySound.numBytesRead = 0;
  216
+		}
234 217
 		//now fill the buffer for the next update if desired
235 218
 		if (fillNextBuffer) {
236 219
 			TinySound.fillAudioBuffer();
@@ -244,27 +227,53 @@ private static void fillAudioBuffer() {
244 227
 		if (!TinySound.inited) {
245 228
 			return;
246 229
 		}
247  
-		//default to full buffer
248  
-		int length = TinySound.audioBuffer.length;
249  
-		//check for full frames of drift
250  
-		int fullDriftFrames = (int)TinySound.driftFramesAccrued;
251  
-		if (fullDriftFrames > 0) {
252  
-			//reduce the buffer length to compensate
253  
-			length -= (fullDriftFrames * TinySound.FORMAT.getFrameSize());
254  
-			//and update accrued
255  
-			TinySound.driftFramesAccrued -= fullDriftFrames;
256  
-		}
257  
-		//now read the bytes
258  
-		TinySound.numBytesRead = TinySound.mixer.read(TinySound.audioBuffer, 0,
259  
-				length);
260  
-		//fill remainder with zeroes
261  
-		for (int i = TinySound.numBytesRead; i < length; i++) {
262  
-			TinySound.audioBuffer[i] = 0;
263  
-		}
264  
-		TinySound.numBytesRead = length;
265  
-		//accrue drift
266  
-		if (length == TinySound.audioBuffer.length) {
267  
-			TinySound.driftFramesAccrued += TinySound.driftFramesPerUpdate;
  230
+		long currTime = System.nanoTime();
  231
+		double secDelta = (currTime - TinySound.lastUpdate) / 1000000000.0;
  232
+		double framesToRead = secDelta * TinySound.FORMAT.getFrameRate();
  233
+		if (framesToRead > 0.0) {
  234
+			//update accrued drift
  235
+			TinySound.driftFramesAccrued += (framesToRead - (int)framesToRead);
  236
+			//check drift and update accrued drift
  237
+			int driftFramesToAdd = (int)TinySound.driftFramesAccrued;
  238
+			TinySound.driftFramesAccrued -= driftFramesToAdd;
  239
+			//calculate bytes to read
  240
+			int bytesToRead = ((int)framesToRead + driftFramesToAdd) *
  241
+				TinySound.FORMAT.getFrameSize();
  242
+			//now read the bytes
  243
+			int tmpBytesRead = TinySound.mixer.read(TinySound.audioBuffer,
  244
+					TinySound.numBytesRead, bytesToRead);
  245
+			TinySound.numBytesRead += tmpBytesRead;
  246
+			//fill remainder with zeroes
  247
+			int remainder = bytesToRead - tmpBytesRead;
  248
+			for (int i = 0; i < remainder; i++) {
  249
+				TinySound.audioBuffer[TinySound.numBytesRead + i] = 0;
  250
+			}
  251
+			TinySound.numBytesRead += remainder;
  252
+			//mark last update
  253
+			TinySound.lastUpdate = currTime;
  254
+		}
  255
+	}
  256
+	
  257
+	/**
  258
+	 * Fills the audio buffer with a specified number of frames of audio data
  259
+	 * without recording the last update time.
  260
+	 */
  261
+	private static void preFillAudioBuffer(int numFrames) {
  262
+		if (!TinySound.inited) {
  263
+			return;
  264
+		}
  265
+		if (numFrames > 0) {
  266
+			int bytesToRead = numFrames * TinySound.FORMAT.getFrameSize();
  267
+			//now read the bytes
  268
+			int tmpBytesRead = TinySound.mixer.read(TinySound.audioBuffer,
  269
+					TinySound.numBytesRead, bytesToRead);
  270
+			TinySound.numBytesRead += tmpBytesRead;
  271
+			//fill remainder with zeroes
  272
+			int remainder = bytesToRead - tmpBytesRead;
  273
+			for (int i = 0; i < remainder; i++) {
  274
+				TinySound.audioBuffer[TinySound.numBytesRead + i] = 0;
  275
+			}
  276
+			TinySound.numBytesRead += remainder;
268 277
 		}
269 278
 	}
270 279
 	
3  src/kuusisto/tinysound/internal/Mixer.java
@@ -112,9 +112,6 @@ public synchronized int read(byte[] data, int offset, int length) {
112 112
 		//*********************************************//
113 113
 		//assume big-endian, stereo, 16-bit, signed PCM//
114 114
 		//*********************************************//
115  
-		if (length < data.length) {
116  
-			length = data.length;
117  
-		}
118 115
 		int numRead = 0;
119 116
 		boolean bytesRead = true; //terminate early if out of bytes
120 117
 		for (int i = offset; i < (length + offset) && bytesRead; i += 4) {
2  src/kuusisto/tinysound/internal/UpdateRunner.java
@@ -75,7 +75,7 @@ public void run() {
75 75
 				}
76 76
 				//give the CPU back to the OS for a bit
77 77
 				try {
78  
-					Thread.sleep(0, 500000);
  78
+					Thread.sleep(0, 100000);
79 79
 				} catch (InterruptedException e) {}
80 80
 			}
81 81
 		}

0 notes on commit 8a1ba02

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