Exemplo n.º 1
0
        public unsafe void SampleBlockConversions()
        {
            SampleBlock reference16Bit;

            using (MediaFoundationReader reference16BitReader = new MediaFoundationReader(TestConstant.ReferenceFilePath16Bit))
            {
                byte[] buffer16Bit = new byte[reference16BitReader.Length];
                int    bytesRead   = reference16BitReader.Read(buffer16Bit, 0, buffer16Bit.Length);
                reference16Bit = new SampleBlock(buffer16Bit, bytesRead, SampleTypeExtensions.FromBitsPerSample(reference16BitReader.WaveFormat.BitsPerSample));
            }

            SampleBlock reference24Bit;

            using (MediaFoundationReader reference24BitReader = new MediaFoundationReader(TestConstant.ReferenceFilePath24Bit))
            {
                byte[] buffer24Bit = new byte[reference24BitReader.Length];
                int    bytesRead   = reference24BitReader.Read(buffer24Bit, 0, buffer24Bit.Length);
                reference24Bit = new SampleBlock(buffer24Bit, bytesRead, SampleTypeExtensions.FromBitsPerSample(reference24BitReader.WaveFormat.BitsPerSample));
            }

            Assert.IsTrue(reference16Bit.Int16Samples == reference24Bit.SamplesInUse);

            SampleBlock reference16BitAsDouble = reference16Bit.ConvertTo(SampleType.Double);
            SampleBlock reference16BitAsQ31    = reference16Bit.ConvertTo(SampleType.Int32);
            SampleBlock reference24BitAsDouble = reference24Bit.ConvertTo(SampleType.Double);
            SampleBlock reference24BitAsQ31    = reference24Bit.ConvertTo(SampleType.Int32);

            Assert.IsTrue(reference16Bit.Int16Samples == reference16BitAsDouble.DoubleSamples);
            Assert.IsTrue(reference16Bit.Int16Samples == reference16BitAsQ31.Int32Samples);
            Assert.IsTrue(reference16Bit.Int16Samples == reference24BitAsDouble.DoubleSamples);
            Assert.IsTrue(reference16Bit.Int16Samples == reference24BitAsQ31.Int32Samples);

            for (int sample = 0; sample < reference16Bit.Int16Samples; ++sample)
            {
                Assert.IsTrue(((int)reference16Bit.Int16s[sample] << TestConstant.ShiftBetween16BitSamplesAndQ31) == reference16BitAsQ31.Int32s[sample]);
                Assert.IsTrue((int)reference16BitAsDouble.Doubles[sample] == reference16BitAsQ31.Int32s[sample]);

                Assert.IsTrue((reference24Bit.GetInt24AsInt32(sample) << TestConstant.ShiftBetween24BitSamplesAndQ31) == reference24BitAsQ31.Int32s[sample]);
                Assert.IsTrue((int)reference24BitAsDouble.Doubles[sample] == reference24BitAsQ31.Int32s[sample]);
            }
        }