summaryrefslogtreecommitdiffstats
path: root/www
diff options
context:
space:
mode:
authorkrishna_gadepalli <[email protected]>2007-02-05 22:05:47 +0000
committerkrishna_gadepalli <[email protected]>2007-02-05 22:05:47 +0000
commitc4d389f43b76da36bc40efa31f5fee89ce553bb7 (patch)
tree39eb7dd05e32b21d6cc4a6d21c1440beb1773185 /www
parent4e06d54d50a8d08f7acaa2abce11518252daa6c1 (diff)
- made the number of buffers a variable instead of hardcoding to 2
- made the buffer size and the #buffers specifiable from the command line - added a sleep to the main "playstream" loop so as to not peg the CPU (from Ken Russel) git-svn-id: file:///home/mbien/NetBeansProjects/JOGAMP/joal-sync/svn-server-sync-demos/joal-demos/trunk@59 235fdd13-0e8c-4fed-b5ee-0a390d04b286
Diffstat (limited to 'www')
-rw-r--r--www/devmaster/lesson8.html47
1 files changed, 41 insertions, 6 deletions
diff --git a/www/devmaster/lesson8.html b/www/devmaster/lesson8.html
index 4d68908..a091df1 100644
--- a/www/devmaster/lesson8.html
+++ b/www/devmaster/lesson8.html
@@ -135,7 +135,13 @@ tutorial. <var>OggStreamer</var> which is the main class doing most of the worki
</p>
-<pre class="code"> // The size of a chunk from the stream that we want to read for each update.<br> private static int BUFFER_SIZE = 4096*8;<br></pre>
+<pre class="code">
+ // The size of a chunk from the stream that we want to read for each update.
+ private static int BUFFER_SIZE = 4096*8;
+
+ // The number of buffers used in the audio pipeline
+ private static int NUM_BUFFERS = 2;
+</pre>
@@ -170,8 +176,13 @@ just yet. I believe my comments should give you an idea of what they're for.</p>
-<pre class="code"> // Buffers hold sound data. There are two of them (front/back)<br> private int[] buffers = new int[2];<br> <br> // Sources are points emitting sound.<br> private int[] source = new int[1];<br> <br> private int format; // OpenAL data format<br> private int rate; // sample rate<br></pre>
-
+<pre class="code">
+ // Buffers hold sound data. There are two of them by default (front/back)
+ private int[] buffers = new int[NUM_BUFFERS];
+
+ // Sources are points emitting sound.
+ private int[] source = new int[1];
+</pre>
<p>First thing that I want to point out is that we have 2 buffers dedicated to
@@ -197,7 +208,7 @@ enumerator based on how many channels are in the Ogg and then make a not of the
-<pre class="code"> public boolean open() {<br> ...<br><br> al.alGenBuffers(2, buffers, 0); check();<br> al.alGenSources(1, source, 0); check();<br><br> al.alSourcefv(source[0], AL.AL_POSITION , sourcePos, 0);<br> al.alSourcefv(source[0], AL.AL_VELOCITY , sourceVel, 0);<br> al.alSourcefv(source[0], AL.AL_DIRECTION, sourceDir, 0);<br> <br> al.alSourcef(source[0], AL.AL_ROLLOFF_FACTOR, 0.0f );<br> al.alSourcei(source[0], AL.AL_SOURCE_RELATIVE, AL.AL_TRUE);<br><br> ...<br> }<br></pre>
+<pre class="code"> public boolean open() {<br> ...<br><br> al.alGenBuffers(NUM_BUFFERS, buffers, 0); check();<br> al.alGenSources(1, source, 0); check();<br><br> al.alSourcefv(source[0], AL.AL_POSITION , sourcePos, 0);<br> al.alSourcefv(source[0], AL.AL_VELOCITY , sourceVel, 0);<br> al.alSourcefv(source[0], AL.AL_DIRECTION, sourceDir, 0);<br> <br> al.alSourcef(source[0], AL.AL_ROLLOFF_FACTOR, 0.0f );<br> al.alSourcei(source[0], AL.AL_SOURCE_RELATIVE, AL.AL_TRUE);<br><br> ...<br> }<br></pre>
@@ -211,7 +222,16 @@ will still hear it. The same idea applies to source relativity.</p>
-<pre class="code"> public void release() {<br> al.alSourceStop(source[0]);<br> empty();<br><br> al.alDeleteSources(1, source, 0); check();<br> al.alDeleteBuffers(2, buffers, 0); check();<br> }<br></pre>
+<pre class="code">
+ public void release() {
+ al.alSourceStop(source[0]);
+ empty();
+
+ for (int i = 0; i < NUM_BUFFERS; i++) {
+ al.alDeleteSources(i, source, 0); check();
+ }
+ }
+</pre>
<p>We can clean up after ourselves using this. We stop the source, empty out any
@@ -219,7 +239,22 @@ buffers that are still in the queue, and destroy our objects.
</p>
-<pre class="code"> public boolean playback() {<br> if (playing())<br> return true;<br> <br> if (!stream(buffers[0]))<br> return false;<br> <br> if(!stream(buffers[1]))<br> return false;<br> <br> al.alSourceQueueBuffers(source[0], 2, buffers, 0);<br> al.alSourcePlay(source[0]);<br> <br> return true;<br> }<br></pre>
+<pre class="code">
+ public boolean playback() {
+ if (playing())
+ return true;
+
+ for (int i = 0; i < NUM_BUFFERS; i++) {
+ if (!stream(buffers[i]))
+ return false;
+ }
+
+ al.alSourceQueueBuffers(source[0], NUM_BUFFERS, buffers, 0);
+ al.alSourcePlay(source[0]);
+
+ return true;
+ }
+</pre>