Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        public static byte GetStride(this ChannelType _this)
        {
            ChannelFormat format    = _this.GetFormat();
            int           dimention = _this.GetDimention();

            return(ChannelInfo.CalculateStride(format, dimention));
        }
Exemplo n.º 3
0
 public ChannelInfo(byte stream, byte offset, ChannelFormat format, byte dimention)
 {
     Stream    = stream;
     Offset    = offset;
     Format    = format;
     Dimension = dimention;
 }
Exemplo n.º 4
0
        public static int GetChannelsCount(ChannelFormat channelFormat)
        {
            int count;

            switch (channelFormat)
            {
                case ChannelFormat.Mono:
                    count = 1;
                    break;
                default:
                    count = 2;
                    break;
            }

            return count;
        }
Exemplo n.º 5
0
        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());
            }
        }
Exemplo n.º 6
0
        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());
            }
        }
Exemplo n.º 7
0
        public byte GetStride(Version version)
        {
            ChannelFormat format = GetFormat(version);

            return(CalculateStride(format, Dimension));
        }
Exemplo n.º 8
0
 public static byte CalculateStride(ChannelFormat format, int dimention)
 {
     return((byte)(format.GetSize() * dimention));
 }
Exemplo n.º 9
0
		/// <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)];
		}
Exemplo n.º 10
0
		/// <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;
		}
Exemplo n.º 11
0
		/// <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;
					}
			}
		}