Exemplo n.º 1
0
        public async Task Copy()
        {
            var input = GetType().Assembly.GetManifestResourceStream("WavSplitterTest.Resources.source.wav");

            var path   = Path.Combine(TestContext.CurrentContext.TestDirectory, "copy.wav");
            var output = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);

            var reader = new WavReader(input);
            var writer = new WavWriter(output, reader.Header);

            var fllr = reader.ReadChunkHeader(skipFllr: false);

            writer.SetCurrentChunkId(fllr.ChunkId);

            var bytes = new byte[fllr.ChunkLength];
            await reader.ReadDataChunk(bytes);

            await writer.Write(bytes, 0, bytes.Length);

            writer.Flush();

            Assert.AreEqual(input.Position, output.Position, "First chunk test");
            Assert.AreEqual(fllr.ChunkLength, writer.LastDataChunkLength);

            var data = reader.ReadChunkHeader(skipFllr: false);

            bytes = new byte[data.ChunkLength];
            await reader.ReadDataChunk(bytes);

            writer.StartNewDataChunk(data.ChunkId);
            await writer.Write(bytes, 0, bytes.Length);

            writer.Flush();

            Assert.IsFalse(reader.HasMore);
            Assert.AreEqual(input.Position, output.Position, "Second chunk test");
            Assert.AreEqual(data.ChunkLength, writer.LastDataChunkLength);
        }
Exemplo n.º 2
0
        public async Task ReadToEnd()
        {
            using (var input = Helper.GetAudioStream())
            {
                var reader      = new WavReader(input);
                var chunkHeader = reader.ReadChunkHeader();

                var buffer = new byte[chunkHeader.ChunkLength];
                var count  = await reader.ReadDataChunk(buffer);

                Assert.AreEqual(count, buffer.Length, "buffer.Length");
                Assert.AreEqual(false, reader.HasMore, "reader.HasMore");
            }
        }