Ejemplo n.º 1
0
        public void DataChunkHeader()
        {
            using (var input = Helper.GetAudioStream())
            {
                var reader      = new WavReader(input);
                var chunkHeader = reader.ReadChunkHeader();

                Assert.AreEqual(WavConst.Data, chunkHeader.ChunkId, "ChunkID");
                Assert.AreEqual(65938, chunkHeader.ChunkLength, "ChunkLength");
            }
        }
Ejemplo n.º 2
0
        public void FllrChunkHeader()
        {
            using (var input = Helper.GetAudioStream())
            {
                var reader      = new WavReader(input);
                var chunkHeader = reader.ReadChunkHeader(skipFllr: false);

                Assert.AreEqual(WavConst.Fllr, chunkHeader.ChunkId, "ChunkID");
                Assert.AreEqual(4044, chunkHeader.ChunkLength, "ChunkLength");
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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");
            }
        }
Ejemplo n.º 5
0
        public async Task FlushUpdatesSizes()
        {
            WavHeader header = GetHeader();

            using (var memory = new MemoryStream())
            {
                var writer = new WavWriter(memory, header);

                var data = new byte[12];
                await writer.Write(data, 0, data.Length);

                writer.Flush();

                // read data, that has been written above
                memory.Position = 0;
                var reader = new WavReader(memory);
                var h      = reader.ReadChunkHeader();

                Assert.AreEqual(WavHeader.Size + WavChunkHeader.Size - 8 + data.Length, reader.Header.FileSize);
                Assert.AreEqual(data.Length, h.ChunkLength);
            }
        }