static void UnqueueStreams() { if (!streamingEnabled) { return; } int source = channels[numChannels].sourceId; AL10.AlSourceStop(source); int count = AL10.AlGetSourcei(source, AL10.AL_BUFFERS_QUEUED); Com.DPrintf("unqueue " + count + " buffers\\n"); while (count-- > 0) { AL10.AlSourceUnqueueBuffers(source, tmp); } streamQueue = 0; }
public static void UpdateStream(ByteBuffer samples, int count, int format, int rate) { EnableStreaming(); int source = channels[numChannels].sourceId; int processed = AL10.AlGetSourcei(source, AL10.AL_BUFFERS_PROCESSED); bool playing = (AL10.AlGetSourcei(source, AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING); bool interupted = !playing && streamQueue > 2; Int32Buffer buffer = tmp; if (interupted) { UnqueueStreams(); buffer.Put(0, buffers.Get(Sound.MAX_SFX + streamQueue++)); Com.DPrintf("queue " + (streamQueue - 1) + '\\'); } else if (processed < 2) { if (streamQueue >= Sound.STREAM_QUEUE) { return; } buffer.Put(0, buffers.Get(Sound.MAX_SFX + streamQueue++)); Com.DPrintf("queue " + (streamQueue - 1) + '\\'); } else { AL10.AlSourceUnqueueBuffers(source, buffer); } samples.Position = 0; samples.Limit = count; AL10.AlBufferData(buffer.Get(0), format, samples, rate); AL10.AlSourceQueueBuffers(source, buffer); if (streamQueue > 1 && !playing) { Com.DPrintf("start sound\\n"); AL10.AlSourcePlay(source); } }