static int GetBufferSize(XtStream stream, int frames) { XtFormat format = stream.GetFormat(); int sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size; return(frames * format.inputs * sampleSize); }
void FormatOrDeviceChanged() { if (_suspendDeviceChanged) { return; } _bufferSize.Minimum = 1; _bufferSize.Maximum = 5000; _bufferSize.Value = 1000; _output.FormatOrDeviceChanged(true, GetFormat(true)); _input.FormatOrDeviceChanged(false, GetFormat(false)); if (_sample.SelectedItem != null) { var attrs = XtAudio.GetSampleAttributes((XtSample)_sample.SelectedItem); _attributes.Text = $"Size: {attrs.size}, Count: {attrs.count}, Float: {attrs.isFloat}, Signed: {attrs.isSigned}"; } var format = GetFormat(true); bool supported = format == null ? false : (_output._device.SelectedItem as DeviceInfo)?.Device?.SupportsFormat(format.Value) == true; var buffer = format == null || !supported ? null : (_output._device.SelectedItem as DeviceInfo)?.Device?.GetBufferSize(format.Value); if (buffer != null) { _bufferSize.Minimum = (int)Math.Floor(buffer.Value.min); _bufferSize.Maximum = (int)Math.Ceiling(buffer.Value.max); _bufferSize.Value = (int)Math.Ceiling(buffer.Value.current); _bufferSize.TickFrequency = (_bufferSize.Maximum - _bufferSize.Minimum) / 10; } }
static void OnAggregate(XtStream stream, object input, object output, int frames, double time, ulong position, bool timeValid, ulong error, object user) { XtFormat format = stream.GetFormat(); XtAttributes attrs = XtAudio.GetSampleAttributes(format.mix.sample); if (frames > 0) { Buffer.BlockCopy((Array)input, 0, (Array)output, 0, frames * format.inputs * attrs.size); } }
internal XtSafeBuffer(XtStream stream, bool interleaved) { _stream = stream; _interleaved = interleaved; _format = stream.GetFormat(); _inputs = _format.channels.inputs; _outputs = _format.channels.outputs; _attrs = XtAudio.GetSampleAttributes(_format.mix.sample); _input = CreateBuffer(_inputs); _output = CreateBuffer(_outputs); }
static void CaptureNonInterleaved(XtStream stream, object input, object output, int frames, double time, ulong position, bool timeValid, ulong error, object user) { if (frames > 0) { Context ctx = (Context)user; XtFormat format = stream.GetFormat(); int channels = format.inputs; int sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size; for (int f = 0; f < frames; f++) { for (int c = 0; c < channels; c++) { // Don't do this. ctx.recording.Write(((byte[][])input)[c], f * sampleSize, sampleSize); } } } }
static unsafe void CaptureNonInterleavedRaw(XtStream stream, object input, object output, int frames, double time, ulong position, bool timeValid, ulong error, object user) { if (frames > 0) { Context ctx = (Context)user; XtFormat format = stream.GetFormat(); int channels = format.inputs; int sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size; for (int f = 0; f < frames; f++) { for (int c = 0; c < channels; c++) { IntPtr source = new IntPtr(&(((byte **)(IntPtr)input)[c][f * sampleSize])); Marshal.Copy(source, ctx.intermediate, 0, sampleSize); // Don't do this. ctx.recording.Write(ctx.intermediate, 0, sampleSize); } } } }
internal override unsafe void OnCallback(XtFormat format, bool interleaved, bool raw, object input, object output, int frames) { int sampleSize = XtAudio.GetSampleAttributes(format.mix.sample).size; if (!raw) { if (interleaved) { Buffer.BlockCopy((Array)input, 0, (Array)output, 0, frames * format.inputs * sampleSize); } else { for (int i = 0; i < format.inputs; i++) { Buffer.BlockCopy((Array)(((Array)input).GetValue(i)), 0, (Array)(((Array)output).GetValue(i)), 0, frames * sampleSize); } } } else { if (interleaved) { Utility.MemCpy((IntPtr)output, (IntPtr)input, new IntPtr(frames * format.inputs * sampleSize)); } else { for (int i = 0; i < format.inputs; i++) { Utility.MemCpy( new IntPtr(((void **)(((IntPtr)output).ToPointer()))[i]), new IntPtr(((void **)(((IntPtr)input).ToPointer()))[i]), new IntPtr(frames * sampleSize)); } } } }
internal void Init(XtFormat format, int maxFrames) { frameSize = format.inputs * XtAudio.GetSampleAttributes(format.mix.sample).size; block = new byte[maxFrames * frameSize]; interleavedBuffer = Utility.CreateInterleavedBuffer(format.mix.sample, format.inputs, maxFrames); }
static int GetBufferSize(int channels, int frames) { int size = XtAudio.GetSampleAttributes(Mix.sample).size; return(channels * frames * size); }
private void FormatOrDeviceChanged() { if (sample.SelectedItem != null) { var attrs = XtAudio.GetSampleAttributes((XtSample)sample.SelectedItem); attributes.Text = XtPrint.AttributesToString(attrs); } XtFormat inputFormat = GetFormat(false); XtDevice inputDevice = this.inputDevice.SelectedItem == null ? null : ((DeviceView)(this.inputDevice.SelectedItem)).device; bool inputSupported = inputDevice == null ? false : inputDevice.SupportsFormat(inputFormat); inputFormatSupported.Text = inputSupported.ToString(); XtBuffer inputBuffer = !inputSupported ? null : inputDevice.GetBuffer(inputFormat); inputBufferSizes.Text = !inputSupported ? "N/A" : string.Format("{0} / {1} / {2}", inputBuffer.min.ToString("N1"), inputBuffer.current.ToString("N1"), inputBuffer.max.ToString("N1")); inputMix.Text = inputDevice == null || inputDevice.GetMix() == null ? "N/A" : inputDevice.GetMix().ToString(); inputInterleaved.Text = inputDevice == null ? "N/A" : inputDevice.SupportsAccess(true) && inputDevice.SupportsAccess(false) ? "Both" : inputDevice.SupportsAccess(false) ? "False" : "True"; List <ChannelView> inputViews = new List <ChannelView>(); if (inputDevice != null) { inputViews = (from i in Enumerable.Range(0, inputDevice.GetChannelCount(false)) select new ChannelView { index = i, name = (1 + i) + ": " + inputDevice.GetChannelName(false, i) }) .ToList(); } inputChannels.DataSource = null; inputChannels.DataSource = inputViews; inputChannels.SelectedItems.Clear(); XtFormat outputFormat = GetFormat(true); XtDevice outputDevice = this.outputDevice.SelectedItem == null ? null : ((DeviceView)(this.outputDevice.SelectedItem)).device; bool outputSupported = outputDevice == null ? false : outputDevice.SupportsFormat(outputFormat); outputFormatSupported.Text = outputSupported.ToString(); XtBuffer outputBuffer = !outputSupported ? null : outputDevice.GetBuffer(outputFormat); outputBufferSizes.Text = !outputSupported ? "N/A" : string.Format("{0} / {1} / {2}", outputBuffer.min.ToString("N1"), outputBuffer.current.ToString("N1"), outputBuffer.max.ToString("N1")); outputMix.Text = outputDevice == null || outputDevice.GetMix() == null ? "N/A" : outputDevice.GetMix().ToString(); outputInterleaved.Text = outputDevice == null ? "N/A" : outputDevice.SupportsAccess(true) && outputDevice.SupportsAccess(false) ? "Both" : outputDevice.SupportsAccess(false) ? "False" : "True"; List <ChannelView> outputViews = new List <ChannelView>(); if (outputDevice != null) { outputViews = (from i in Enumerable.Range(0, outputDevice.GetChannelCount(true)) select new ChannelView { index = i, name = (1 + i) + ": " + outputDevice.GetChannelName(true, i) }) .ToList(); } outputChannels.DataSource = null; outputChannels.DataSource = outputViews; outputChannels.SelectedItems.Clear(); bufferSize.Minimum = 1; bufferSize.Maximum = 5000; bufferSize.Value = 1000; if (outputBuffer != null) { bufferSize.Minimum = (int)Math.Floor(outputBuffer.min); bufferSize.Maximum = (int)Math.Ceiling(outputBuffer.max); bufferSize.Value = (int)Math.Ceiling(outputBuffer.current); bufferSize.TickFrequency = (bufferSize.Maximum - bufferSize.Minimum) / 10; } }