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); } }
public static void PlayAllSounds(SingleBuffer listenerOrigin) { SingleBuffer sourceOrigin = sourceOriginBuffer; Channel ch; int sourceId; int state; for (int i = 0; i < numChannels; i++) { ch = channels[i]; if (ch.active) { sourceId = ch.sourceId; switch (ch.type) { case Channel.LISTENER: sourceOrigin.Put(0, listenerOrigin.Get(0)); sourceOrigin.Put(1, listenerOrigin.Get(1)); sourceOrigin.Put(2, listenerOrigin.Get(2)); break; case Channel.DYNAMIC: CL_ents.GetEntitySoundOrigin(ch.entnum, entityOrigin); ConvertVector(entityOrigin, sourceOrigin); break; case Channel.FIXED: ConvertVector(ch.origin, sourceOrigin); break; } if (ch.modified) { if (ch.bufferChanged) { try { AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); } catch (OpenALException e) { AL10.AlSourceStop(sourceId); AL10.AlSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); } } if (ch.volumeChanged) { AL10.AlSourcef(sourceId, AL10.AL_GAIN, ch.volume); } AL10.AlSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, ch.rolloff); AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin); AL10.AlSourcePlay(sourceId); ch.modified = false; } else { state = AL10.AlGetSourcei(sourceId, AL10.AL_SOURCE_STATE); if (state == AL10.AL_PLAYING) { AL10.AlSource(sourceId, AL10.AL_POSITION, sourceOrigin); } else { ch.Clear(); } } ch.autosound = false; } } }