public void ConversionTest( string inputPath, SampleRate sampleRate, BitRate bitRate, ChannelFormat channelFormat) { var inputFileName = Path.GetFileNameWithoutExtension(inputPath); var actualSampleRate = SampleRateHelper.GetSampleRate(sampleRate); var actualBitRate = BitRateHelper.GetBitRate(bitRate); var actualChannelsCount = ChannelFormatHelper.GetChannelsCount(channelFormat); var fileName = $"{inputFileName}-SR{actualSampleRate}-BR{actualBitRate}-CF{actualChannelsCount}"; var outputPath = string.Format(OutputPathFormat, fileName); WavConverter.Convert(inputPath, outputPath, sampleRate, channelFormat, bitRate); using (var inputReader = new AudioFileReader(inputPath)) using (var outputReader = new WaveFileReader(outputPath)) { Assert.Equal(actualSampleRate, outputReader.WaveFormat.SampleRate); Assert.Equal(actualBitRate, outputReader.WaveFormat.BitsPerSample); Assert.Equal(actualChannelsCount, outputReader.WaveFormat.Channels); Assert.InRange( inputReader.TotalTime, outputReader.TotalTime - _totalTimeDelta, outputReader.TotalTime + _totalTimeDelta); } #if !DEBUG DeleteIfExists(outputPath); #endif }
public static byte GetStride(this ChannelType _this) { ChannelFormat format = _this.GetFormat(); int dimention = _this.GetDimention(); return(ChannelInfo.CalculateStride(format, dimention)); }
public ChannelInfo(byte stream, byte offset, ChannelFormat format, byte dimention) { Stream = stream; Offset = offset; Format = format; Dimension = dimention; }
public static int GetChannelsCount(ChannelFormat channelFormat) { int count; switch (channelFormat) { case ChannelFormat.Mono: count = 1; break; default: count = 2; break; } return count; }
public static int GetSize(this ChannelFormat _this) { switch (_this) { case ChannelFormat.Float: return(4); case ChannelFormat.HalfFloat: return(2); case ChannelFormat.Byte: return(1); case ChannelFormat.Int: return(4); default: throw new Exception(_this.ToString()); } }
public static ChannelFormatV5 ToChannelFormatV5(this ChannelFormat _this) { switch (_this) { case ChannelFormat.Float: return(ChannelFormatV5.Float); case ChannelFormat.Float16: return(ChannelFormatV5.Float16); case ChannelFormat.Byte: return(ChannelFormatV5.Byte); case ChannelFormat.Int: return(ChannelFormatV5.Int); default: throw new Exception(_this.ToString()); } }
public byte GetStride(Version version) { ChannelFormat format = GetFormat(version); return(CalculateStride(format, Dimension)); }
public static byte CalculateStride(ChannelFormat format, int dimention) { return((byte)(format.GetSize() * dimention)); }
/// <summary> /// Initializes a new instance of the <see cref="Xevle.Imaging.Image.Image8i"/> class. /// </summary> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <param name="format">Format.</param> /// <param name="imageData">Image data.</param> public Image8i(uint width, uint height, ChannelFormat format = ChannelFormat.RGB, byte[] imageData = null) { Width = width; Height = height; ChannelFormat = format; this.imageData = imageData; if (width * height > 0) imageData = new byte[width * height * GetBytePerPixelFromChannelFormat(format)]; }
/// <summary> /// Converts to. /// </summary> /// <returns>The to.</returns> /// <param name="channelFormat">Channel format.</param> public Image8i ToChannelFormat(ChannelFormat channelFormat) { switch (channelFormat) { case ChannelFormat.Gray: { return ToChannelFormatGray(); } case ChannelFormat.GrayAlpha: { return ToChannelFormatGrayAlpha(); } case ChannelFormat.RGB: { return ToChannelFormatRGB(); } case ChannelFormat.RGBA: { return ToChannelFormatRGBA(); } case ChannelFormat.BGR: { return ToChannelFormatBGR(); } case ChannelFormat.BGRA: { return ToChannelFormatBGRA(); } } return null; }
/// <summary> /// Gets the byte per pixel from channel format. /// </summary> /// <returns>The byte per pixel from channel format.</returns> /// <param name="format">Format.</param> public uint GetBytePerPixelFromChannelFormat(ChannelFormat format) { switch (format) { case ChannelFormat.Gray: { return 1; } case ChannelFormat.GrayAlpha: { return 2; } case ChannelFormat.RGB: { return 3; } case ChannelFormat.BGR: { return 3; } case ChannelFormat.RGBA: { return 4; } case ChannelFormat.BGRA: { return 4; } default: { return 1; } } }