/// <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; if (waveFormat.BitsPerSample != 16 && waveFormat.BitsPerSample != 32) { throw new ArgumentException(String.Format("WaveFormat BitsPerSample {0} is not yet supported", waveFormat.BitsPerSample)); } // TODO : IMPLEMENTS OTHER CONVERTOR TYPES switch (asioType) { case ASIOSampleType.ASIOSTInt32LSB: switch (waveFormat.BitsPerSample) { case 16: convertor = (is2Channels) ? ConvertorShortToInt2Channels : (SampleConvertor)ConvertorShortToIntGeneric; break; case 32: convertor = (is2Channels) ? ConvertorFloatToInt2Channels : (SampleConvertor)ConvertorFloatToIntGeneric; break; } break; case ASIOSampleType.ASIOSTInt16LSB: switch (waveFormat.BitsPerSample) { case 16: convertor = (is2Channels) ? ConvertorShortToShort2Channels : (SampleConvertor)ConvertorShortToShortGeneric; break; case 32: convertor = (is2Channels) ? ConvertorFloatToShort2Channels : (SampleConvertor)ConvertorFloatToShortGeneric; break; } break; default: throw new ArgumentException( String.Format("ASIO Buffer Type {0} is not yet supported. ASIO Int32 buffer is only 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); }