From c4d389f43b76da36bc40efa31f5fee89ce553bb7 Mon Sep 17 00:00:00 2001
From: krishna_gadepalli
// 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() {@@ -211,7 +222,16 @@ will still hear it. The same idea applies to source relativity. -
...
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);
...
}
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