From c4d389f43b76da36bc40efa31f5fee89ce553bb7 Mon Sep 17 00:00:00 2001 From: krishna_gadepalli Date: Mon, 5 Feb 2007 22:05:47 +0000 Subject: - 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 --- www/devmaster/lesson8.html | 47 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'www') 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. OggStreamer which is the main class doing most of the worki

-
    // The size of a chunk from the stream that we want to read for each update.
private static int BUFFER_SIZE = 4096*8;
+
+    // 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;
+
@@ -170,8 +176,13 @@ just yet. I believe my comments should give you an idea of what they're for.

-
    // Buffers hold sound data. There are two of them (front/back)
private int[] buffers = new int[2];

// Sources are points emitting sound.
private int[] source = new int[1];

private int format; // OpenAL data format
private int rate; // sample rate
- +
+    // 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];
+

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 -

    public boolean open() {
...

al.alGenBuffers(2, buffers, 0); check();
al.alGenSources(1, source, 0); check();

al.alSourcefv(source[0], AL.AL_POSITION , sourcePos, 0);
al.alSourcefv(source[0], AL.AL_VELOCITY , sourceVel, 0);
al.alSourcefv(source[0], AL.AL_DIRECTION, sourceDir, 0);

al.alSourcef(source[0], AL.AL_ROLLOFF_FACTOR, 0.0f );
al.alSourcei(source[0], AL.AL_SOURCE_RELATIVE, AL.AL_TRUE);

...
}
+
    public boolean open() {
...

al.alGenBuffers(NUM_BUFFERS, buffers, 0); check();
al.alGenSources(1, source, 0); check();

al.alSourcefv(source[0], AL.AL_POSITION , sourcePos, 0);
al.alSourcefv(source[0], AL.AL_VELOCITY , sourceVel, 0);
al.alSourcefv(source[0], AL.AL_DIRECTION, sourceDir, 0);

al.alSourcef(source[0], AL.AL_ROLLOFF_FACTOR, 0.0f );
al.alSourcei(source[0], AL.AL_SOURCE_RELATIVE, AL.AL_TRUE);

...
}
@@ -211,7 +222,16 @@ will still hear it. The same idea applies to source relativity.

-
    public void release() {
al.alSourceStop(source[0]);
empty();

al.alDeleteSources(1, source, 0); check();
al.alDeleteBuffers(2, buffers, 0); check();
}
+
+    public void release() {
+	al.alSourceStop(source[0]);
+	empty();
+
+	for (int i = 0; i < NUM_BUFFERS; i++) {
+	    al.alDeleteSources(i, source, 0); check();
+	}
+    }
+

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.

-
    public boolean playback() {
if (playing())
return true;

if (!stream(buffers[0]))
return false;

if(!stream(buffers[1]))
return false;

al.alSourceQueueBuffers(source[0], 2, buffers, 0);
al.alSourcePlay(source[0]);

return true;
}
+
+    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;
+    }
+
-- cgit v1.2.3