/// <summary> /// Initialises a new instance of AsioAudioAvailableEventArgs /// </summary> /// <param name="inputBuffers">Pointers to the ASIO buffers for each channel</param> /// <param name="outputBuffers">Pointers to the ASIO buffers for each channel</param> /// <param name="samplesPerBuffer">Number of samples in each buffer</param> /// <param name="asioSampleType">Audio format within each buffer</param> public AsioAudioAvailableEventArgs(IntPtr[] inputBuffers, IntPtr[] outputBuffers, int samplesPerBuffer, AsioSampleType asioSampleType) { InputBuffers = inputBuffers; OutputBuffers = outputBuffers; SamplesPerBuffer = samplesPerBuffer; AsioSampleType = asioSampleType; }
/// <summary> /// Selects the sample convertor based on the input WaveFormat and the output ASIOSampleTtype. /// </summary> /// <param name="waveFormat">The wave format.</param> /// <param name="asioType">The type.</param> /// <returns></returns> public static SampleConvertor SelectSampleConvertor(WaveFormat waveFormat, AsioSampleType asioType) { SampleConvertor convertor = null; bool is2Channels = waveFormat.Channels == 2; // TODO : IMPLEMENTS OTHER CONVERTOR TYPES switch (asioType) { case AsioSampleType.Int32LSB: switch (waveFormat.BitsPerSample) { case 16: convertor = (is2Channels) ? (SampleConvertor)ConvertorShortToInt2Channels : (SampleConvertor)ConvertorShortToIntGeneric; break; case 32: convertor = (is2Channels) ? (SampleConvertor)ConvertorFloatToInt2Channels : (SampleConvertor)ConvertorFloatToIntGeneric; break; } break; case AsioSampleType.Int16LSB: switch (waveFormat.BitsPerSample) { case 16: convertor = (is2Channels) ? (SampleConvertor)ConvertorShortToShort2Channels : (SampleConvertor)ConvertorShortToShortGeneric; break; case 32: convertor = (is2Channels) ? (SampleConvertor)ConvertorFloatToShort2Channels : (SampleConvertor)ConvertorFloatToShortGeneric; break; } break; case AsioSampleType.Int24LSB: switch (waveFormat.BitsPerSample) { case 16: throw new ArgumentException("Not a supported conversion"); case 32: convertor = ConverterFloatTo24LSBGeneric; break; } break; case AsioSampleType.Float32LSB: switch (waveFormat.BitsPerSample) { case 16: throw new ArgumentException("Not a supported conversion"); case 32: convertor = ConverterFloatToFloatGeneric; break; } break; default: throw new ArgumentException( String.Format("ASIO Buffer Type {0} is not yet supported.", Enum.GetName(typeof(AsioSampleType), asioType))); } return convertor; }
/// <summary> /// Selects the sample convertor based on the input WaveFormat and the output ASIOSampleTtype. /// </summary> /// <param name="waveFormat">The wave format.</param> /// <param name="asioType">The type.</param> /// <returns></returns> public static SampleConvertor SelectSampleConvertor(WaveFormat waveFormat, AsioSampleType asioType) { SampleConvertor convertor = null; bool is2Channels = waveFormat.Channels == 2; // TODO : IMPLEMENTS OTHER CONVERTOR TYPES switch (asioType) { case AsioSampleType.Int32LSB: switch (waveFormat.BitsPerSample) { case 16: convertor = (is2Channels) ? (SampleConvertor)ConvertorShortToInt2Channels : (SampleConvertor)ConvertorShortToIntGeneric; break; case 32: if (waveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { convertor = (is2Channels) ? (SampleConvertor)ConvertorFloatToInt2Channels : (SampleConvertor)ConvertorFloatToIntGeneric; } else { convertor = (is2Channels) ? (SampleConvertor)ConvertorIntToInt2Channels : (SampleConvertor)ConvertorIntToIntGeneric; } break; } break; case AsioSampleType.Int16LSB: switch (waveFormat.BitsPerSample) { case 16: convertor = (is2Channels) ? (SampleConvertor)ConvertorShortToShort2Channels : (SampleConvertor)ConvertorShortToShortGeneric; break; case 32: if (waveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { convertor = (is2Channels) ? (SampleConvertor)ConvertorFloatToShort2Channels : (SampleConvertor)ConvertorFloatToShortGeneric; } else { convertor = (is2Channels) ? (SampleConvertor)ConvertorIntToShort2Channels : (SampleConvertor)ConvertorIntToShortGeneric; } break; } break; case AsioSampleType.Int24LSB: switch (waveFormat.BitsPerSample) { case 16: throw new ArgumentException("Not a supported conversion"); case 32: if (waveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { convertor = ConverterFloatTo24LSBGeneric; } else { throw new ArgumentException("Not a supported conversion"); } break; } break; case AsioSampleType.Float32LSB: switch (waveFormat.BitsPerSample) { case 16: throw new ArgumentException("Not a supported conversion"); case 32: if (waveFormat.Encoding == WaveFormatEncoding.IeeeFloat) { convertor = ConverterFloatToFloatGeneric; } else { convertor = ConvertorIntToFloatGeneric; } break; } break; default: throw new ArgumentException( String.Format("ASIO Buffer Type {0} is not yet supported.", Enum.GetName(typeof(AsioSampleType), asioType))); } return(convertor); }
public static ASIOSampleConvertor.SampleConvertor SelectSampleConvertor(WaveFormat waveFormat, AsioSampleType asioType) { ASIOSampleConvertor.SampleConvertor result = null; bool flag = waveFormat.Channels == 2; switch (asioType) { case AsioSampleType.Int16LSB: { int bitsPerSample = waveFormat.BitsPerSample; if (bitsPerSample != 16) { if (bitsPerSample == 32) { result = (flag ? new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorFloatToShort2Channels) : new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorFloatToShortGeneric)); } } else { result = (flag ? new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorShortToShort2Channels) : new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorShortToShortGeneric)); } break; } case AsioSampleType.Int24LSB: { int bitsPerSample2 = waveFormat.BitsPerSample; if (bitsPerSample2 == 16) { throw new ArgumentException("Not a supported conversion"); } if (bitsPerSample2 == 32) { result = new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConverterFloatTo24LSBGeneric); } break; } case AsioSampleType.Int32LSB: { int bitsPerSample3 = waveFormat.BitsPerSample; if (bitsPerSample3 != 16) { if (bitsPerSample3 == 32) { result = (flag ? new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorFloatToInt2Channels) : new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorFloatToIntGeneric)); } } else { result = (flag ? new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorShortToInt2Channels) : new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConvertorShortToIntGeneric)); } break; } case AsioSampleType.Float32LSB: { int bitsPerSample4 = waveFormat.BitsPerSample; if (bitsPerSample4 == 16) { throw new ArgumentException("Not a supported conversion"); } if (bitsPerSample4 == 32) { result = new ASIOSampleConvertor.SampleConvertor(ASIOSampleConvertor.ConverterFloatToFloatGeneric); } break; } default: throw new ArgumentException(string.Format("ASIO Buffer Type {0} is not yet supported.", Enum.GetName(typeof(AsioSampleType), asioType))); } return(result); }
/// <summary> /// Initialises a new instance of AsioAudioAvailableEventArgs /// </summary> /// <param name="inputBuffers">Pointers to the ASIO buffers for each channel</param> /// <param name="outputBuffers">Pointers to the ASIO buffers for each channel</param> /// <param name="samplesPerBuffer">Number of samples in each buffer</param> /// <param name="asioSampleType">Audio format within each buffer</param> public MyAsioAudioAvailableEventArgs(IntPtr[] inputBuffers, IntPtr[] outputBuffers, int samplesPerBuffer, AsioSampleType inputAsioSampleType, AsioSampleType outputAsioSampleType) : base(inputBuffers, outputBuffers, samplesPerBuffer, inputAsioSampleType) { this.inputAsioSampleType = inputAsioSampleType; this.outputAsioSampleType = outputAsioSampleType; }
/// <summary> /// Initialises a new instance of AsioAudioAvailableEventArgs /// </summary> /// <param name="inputBuffers">Pointers to the ASIO buffers for each channel</param> /// <param name="samplesPerBuffer">Number of samples in each buffer</param> /// <param name="asioSampleType">Audio format within each buffer</param> public AsioAudioAvailableEventArgs(IntPtr[] inputBuffers, int samplesPerBuffer, AsioSampleType asioSampleType) { this.InputBuffers = inputBuffers; this.SamplesPerBuffer = samplesPerBuffer; this.AsioSampleType = asioSampleType; }
// here we get given all the input channels we recorded from public void ProcessBuffer(IntPtr[] inBuffers, IntPtr[] outBuffers, int sampleCount, AsioSampleType sampleType) { Func <IntPtr, int, float> getInputSample; if (sampleType == AsioSampleType.Int32LSB) { getInputSample = GetInputSampleInt32LSB; } else if (sampleType == AsioSampleType.Int16LSB) { getInputSample = GetInputSampleInt16LSB; } else if (sampleType == AsioSampleType.Int24LSB) { getInputSample = GetInputSampleInt24LSB; } else if (sampleType == AsioSampleType.Float32LSB) { getInputSample = GetInputSampleFloat32LSB; } else { throw new ArgumentException($"Unsupported ASIO sample type {sampleType}"); } int offset = 0; mixBuffer = BufferHelpers.Ensure(mixBuffer, sampleCount * outputChannels); for (int n = 0; n < sampleCount; n++) { for (int outputChannel = 0; outputChannel < outputChannels; outputChannel++) { mixBuffer[offset] = 0.0f; for (int inputChannel = 0; inputChannel < inputChannels; inputChannel++) { // mix in the desired amount var amount = routingMatrix[inputChannel, outputChannel]; if (amount > 0) { mixBuffer[offset] += amount * getInputSample(inBuffers[inputChannel], n); } } offset++; } } Action <IntPtr, int, float> setOutputSample; if (sampleType == AsioSampleType.Int32LSB) { setOutputSample = SetOutputSampleInt32LSB; } else if (sampleType == AsioSampleType.Int16LSB) { setOutputSample = SetOutputSampleInt16LSB; } else if (sampleType == AsioSampleType.Int24LSB) { throw new InvalidOperationException("Not supported"); } else if (sampleType == AsioSampleType.Float32LSB) { setOutputSample = SetOutputSampleFloat32LSB; } else { throw new ArgumentException($"Unsupported ASIO sample type {sampleType}"); } // now write to the output buffers offset = 0; for (int n = 0; n < sampleCount; n++) { for (int outputChannel = 0; outputChannel < outputChannels; outputChannel++) { setOutputSample(outBuffers[outputChannel], n, mixBuffer[offset++]); } } }