internal static void Swap() { frames.Add(1.0); if (!eglSwapBuffers(display, windowsurface)) { throw new Exception("Unable to swap buffers " + eglGetError()); } }
/// <summary> /// Draw this image to the current OpenVG drawing surface. /// </summary> public void Draw() { if (handle == null) { throw new ObjectDisposedException("Some Image"); } VG.vgDrawImage(handle); VG.DetectError("Draw Image failed"); draws.Add(1.0); }
private static void StartPlayback() { byte[] data = new byte[periodlength * framelength]; byte[] clear = new byte[periodlength * framelength]; int samples = 0; int err; Handle h = device_handle; if (h == null) { return; } if ((err = snd_pcm_prepare(h)) < 0) { throw new Exception("Unable to prepare device " + snd_strerror(err)); } while (true) { lock (h) { if (sfx_buffer == null || sfx_buffer.Count == 0) { sfx_buffer = null; samples = snd_pcm_writei(h, clear, clear.Length / framelength); } else { samples = Math.Min(data.Length / framelength, sfx_buffer.Count / channels); for (int i = 0; i < samples; i++) { short sample = (short)(sfx_buffer[i] * (float)short.MaxValue); data[i << 1] = (byte)(sample & 0xff); data[1 + (i << 1)] = (byte)((sample >> 8) & 0xff); } sfx_buffer.RemoveRange(0, samples); samples = snd_pcm_writei(h, data, samples); } if (samples == -32) //EPIPE { if ((err = snd_pcm_prepare(h)) < 0) { throw new Exception("Unable to prepare device after underrun " + snd_strerror(err)); } } else if (samples == -77) //EBADFD when the sound device is closed { break; } else if (samples < 0) { throw new Exception("Unable to write frame " + snd_strerror(samples)); } else { sample_counter.Add(samples); } } // Without this wait, the sample writer gets starved for lock(h). (Since playback thread is high prio.) And playing a sound can be delayed for 10's of seconds. Thread.Sleep(10); //TODO: This is a cheap, workable solution but not ideal. Revisit this with later resource abstraction refactoring. Mixing could happen in this loop? } }