Ejemplo n.º 1
0
        public void ConvertWavToMp3()
        {
            Sox sox = new Sox
            {
                SoxDirectory = Path.Combine(TestHelper.GetSolutionDirectory(), @"libs\sox-14.3.2\")
            };
            ConvertOptions options = new ConvertOptions
            {
                InputFileInfo = new FileInfo
                {
                    FileType = FileType.Mp3,
                },
                OutputFileInfo = new FileInfo
                {
                    FileType         = FileType.RawUnsignedInteger8,
                    Channels         = 1,
                    SampleSizeInBits = 8,
                    SamplingRate     = 8000,
                    EncodingType     = EncodingType.UnsignedInteger
                }
            };

            int preRunTempDirFileCount = Directory.GetFiles(sox.TempDir).Length;

            using (Stream input = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh.mp3"))
                using (Stream expected = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-mp3.u8"))
                    using (Stream output = sox.Convert(input, options))
                    {
                        StreamTestHelper.AssertAreEqual(expected, output, 2);
                    }
            Assert.AreEqual(preRunTempDirFileCount, Directory.GetFiles(sox.TempDir).Length);
        }
Ejemplo n.º 2
0
        public void ConvertWavToRaw()
        {
            Sox            sox     = CreateSoxInstance();
            ConvertOptions options = new ConvertOptions
            {
                InputFileInfo = new FileInfo
                {
                    FileType = FileType.Wav,
                },
                OutputFileInfo = new FileInfo
                {
                    FileType         = FileType.RawUnsignedInteger8,
                    Channels         = 1,
                    SampleSizeInBits = 8,
                    SamplingRate     = 8000,
                    EncodingType     = EncodingType.UnsignedInteger
                }
            };

            int preRunTempDirFileCount = Directory.GetFiles(sox.TempDir).Length;

            using (Stream input = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh.wav"))
                using (Stream expected = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-wav.u8"))
                    using (Stream output = sox.Convert(input, options))
                    {
                        StreamTestHelper.AssertAreEqual(expected, output, 2);
                    }
            Assert.AreEqual(preRunTempDirFileCount, Directory.GetFiles(sox.TempDir).Length);
        }
Ejemplo n.º 3
0
        public async Task When_Open_ReadWrite_AndGetOutputStream()
        {
            var path   = GetRandomFilePath();
            var file   = (await(await GetFile(path)).OpenAsync(FileAccessMode.ReadWrite)).GetOutputStreamAt(0);
            var direct = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

            await StreamTestHelper.Test(writeTo : file, readOn : direct);
        }
Ejemplo n.º 4
0
        public async Task When_CloneStream_Then_PositionAreNotShared()
        {
            var path = GetRandomFilePath();

            await StreamTestHelper.WriteData(File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite));

            var file1 = await(await GetFile(path)).OpenAsync(FileAccessMode.ReadWrite);
            var file2 = file1.CloneStream();

            file1.Seek(5);

            Assert.AreNotEqual(file1.Position, file2.Position);
        }
Ejemplo n.º 5
0
        public async Task When_Open_Read()
        {
            var path   = GetRandomFilePath();
            var file   = await(await GetFile(path)).OpenAsync(FileAccessMode.Read);
            var direct = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

            await StreamTestHelper.Test(writeTo : direct, readOn : file);

            try
            {
                await StreamTestHelper.WriteData(file);

                Assert.Fail("should have failed");
            }
            catch (NotSupportedException)
            {
            }
        }
Ejemplo n.º 6
0
        public void Trim()
        {
            Sox sox = new Sox
            {
                SoxDirectory = Path.Combine(TestHelper.GetSolutionDirectory(), @"libs\sox-14.3.2\")
            };
            TrimOptions options = new TrimOptions
            {
                InputFileInfo = new FileInfo
                {
                    FileType         = FileType.RawUnsignedInteger8,
                    Channels         = 1,
                    SampleSizeInBits = 8,
                    SamplingRate     = 8000,
                    EncodingType     = EncodingType.UnsignedInteger
                },
                OutputFileInfo = new FileInfo
                {
                    FileType         = FileType.RawUnsignedInteger8,
                    Channels         = 1,
                    SampleSizeInBits = 8,
                    SamplingRate     = 8000,
                    EncodingType     = EncodingType.UnsignedInteger
                },
                StartTime = new SoxTimeSamples {
                    Value = 0
                },
                Length = new SoxTimeSamples {
                    Value = 1000
                },
            };

            int preRunTempDirFileCount = Directory.GetFiles(sox.TempDir).Length;

            using (Stream input = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-wav.u8"))
                using (Stream expected = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-wav-trim.u8"))
                    using (Stream output = sox.Trim(input, options))
                    {
                        StreamTestHelper.AssertAreEqual(expected, output, 2);
                    }
            Assert.AreEqual(preRunTempDirFileCount, Directory.GetFiles(sox.TempDir).Length);
        }