private void Refill(int count) { lock (locker) { if (source.Position >= source.TotalSamples) { if (isLooping) { source.Position = 0; } else { return; } } var state = AL.GetSourceState(IDs[0]); for (int a = 0; a < count; a++) { var sampleRate = source.SampleRate; var bufferCount = Sound.Supports3D ? source.Channels : 1; var channelCount = Sound.Supports3D ? 1 : source.Channels; float[] samples; samples = source.ReadSamples(RINGBUFFER_SAMPLES); if (samples.Length == 0) { return; } short[] samplesChannel = new short[samples.Length / bufferCount]; for (int i = 0; i < bufferCount; i++) { SampleConverter.To16Bit(samples, samplesChannel, i, bufferCount); var buffer = ringbuffers[i, ringBufferIndex]; buffer.SetData(AudioFormat.Short16, channelCount, samplesChannel, sampleRate); AL.SourceQueueBuffer(IDs[i], buffer.ID); } ringBufferIndex = (ringBufferIndex + 1) % RINGBUFFER_COUNT; } var newState = AL.GetSourceState(IDs[0]); if (newState != ALSourceState.Playing && state == ALSourceState.Playing) { Play(); } } }