private void OnBufferSwitch(int Index, ASIOBool Direct) { Audio.SampleBuffer[] a = new Audio.SampleBuffer[input.Length]; for (int i = 0; i < input.Length; ++i) { a[i] = input[i].Samples; using (Audio.RawLock l = new Audio.RawLock(a[i], false, true)) ConvertSamples( input[i].Info.buffers[Index], input[i].Type, l, l.Count); } Audio.SampleBuffer[] b = new Audio.SampleBuffer[output.Length]; for (int i = 0; i < output.Length; ++i) { b[i] = output[i].Samples; } callback(buffer, a, b, sampleRate); for (int i = 0; i < output.Length; ++i) { using (Audio.RawLock l = new Audio.RawLock(b[i], true, false)) ConvertSamples( l, output[i].Info.buffers[Index], output[i].Type, l.Count); } }
private void Proc() { Thread.CurrentThread.Name = "WaveAudio Stream"; try { Log.Global.WriteLine(MessageType.Info, "Entering streaming thread"); EventWaitHandle[] events = waveIn.Select(i => i.Callback).Concat(waveOut.Select(i => i.Callback)).ToArray(); Audio.SampleBuffer[] input = new Audio.SampleBuffer[waveIn.Length]; Audio.SampleBuffer[] output = new Audio.SampleBuffer[waveOut.Length]; while (!stop) { // TODO: Why can't we use this? //if (!WaitHandle.WaitAll(events, 100)) // continue; // Read from the inputs. for (int i = 0; i < waveIn.Length; ++i) { InBuffer b = waveIn[i].GetBuffer(); if (b == null) { return; } using (Audio.RawLock l = new Audio.RawLock(b.Samples, false, true)) ConvertSamples(b.Data, format, l, l.Count); b.Record(); input[i] = b.Samples; } // Get an available buffer from the outputs. for (int i = 0; i < waveOut.Length; ++i) { OutBuffer b = waveOut[i].GetBuffer(); if (b == null) { return; } output[i] = b.Samples; } // Call the callback. callback(buffer, input, output, format.nSamplesPerSec); // Play the results. for (int i = 0; i < output.Length; ++i) { OutBuffer b = (OutBuffer)output[i].Tag; using (Audio.RawLock l = new Audio.RawLock(b.Samples, true, false)) ConvertSamples(l, b.Data, format, l.Count); b.Play(); } } } catch (Exception Ex) { Log.Global.WriteLine(MessageType.Error, "Unhandled exception on streaming thread '{0}': {1}", Ex.GetType().FullName, Ex.ToString()); } Log.Global.WriteLine(MessageType.Info, "Exiting streaming thread"); }
private void OnBufferSwitch(int Index, ASIOBool Direct) { Audio.SampleBuffer[] a = new Audio.SampleBuffer[input.Length]; for (int i = 0; i < input.Length; ++i) { a[i] = input[i].Samples; using (Audio.RawLock l = new Audio.RawLock(a[i], false, true)) ConvertSamples( input[i].Info.buffers[Index], input[i].Type, l, l.Count); } Audio.SampleBuffer[] b = new Audio.SampleBuffer[output.Length]; for (int i = 0; i < output.Length; ++i) b[i] = output[i].Samples; callback(buffer, a, b, sampleRate); for (int i = 0; i < output.Length; ++i) { using (Audio.RawLock l = new Audio.RawLock(b[i], true, false)) ConvertSamples( l, output[i].Info.buffers[Index], output[i].Type, l.Count); } }