Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string source = @"C:\____",
                   dest   = @"C:\____";
            WavOptions d  = WavHandler.Read(source);

            WavHandler.Write(d, d.Data, dest);
            Console.WriteLine(File.ReadAllText(source) == File.ReadAllText(dest));
        }
Exemplo n.º 2
0
        public static void Write(WavOptions options, byte[] data, string path)
        {
            List <byte> bytes = new List <byte>();

            bytes.AddRange(options.ChunkID);
            bytes.AddRange(b4(options.ChunkSize));
            bytes.AddRange(options.Format);
            bytes.AddRange(options.SubChunk1Id);
            bytes.AddRange(b4(options.SubShunk1Size));
            bytes.AddRange(b2(options.AudioFormat));
            bytes.AddRange(b2(options.NumChannels));
            bytes.AddRange(b4(options.SampleRate));
            bytes.AddRange(b4(options.ByteRate));
            bytes.AddRange(b2(options.BlockAlign));
            bytes.AddRange(b2(options.BitsPerSample));
            bytes.AddRange(options.ExtraData);
            bytes.AddRange(options.SubChunk2ID);
            bytes.AddRange(b4(options.SubChunk2Size));
            bytes.AddRange(data);
            File.WriteAllBytes(path, bytes.ToArray());
        }
Exemplo n.º 3
0
        public static WavOptions Read(string path)
        {
            WavOptions options = new WavOptions();

            byte[]      bytes = File.ReadAllBytes(path).ToArray();
            List <byte> b     = new List <byte>(bytes);

            options.ChunkSize     = ChunkReader(b.GetRange(4, 4).ToArray());
            options.SubShunk1Size = ChunkReader(b.GetRange(16, 4).ToArray());
            options.AudioFormat   = (short)ChunkReader(b.GetRange(20, 2).ToArray());
            options.NumChannels   = (short)ChunkReader(b.GetRange(22, 2).ToArray());
            options.SampleRate    = ChunkReader(b.GetRange(24, 4).ToArray());
            options.BitsPerSample = (short)ChunkReader(b.GetRange(34, 2).ToArray());
            int offset = 0;

            if (options.AudioFormat != 1 || options.SubShunk1Size != 16)
            {
                offset            = ChunkReader(b.GetRange(36, 2).ToArray()) + 2;
                options.ExtraData = b.GetRange(36, offset).ToArray();
            }
            options.SubChunk2Size = ChunkReader(b.GetRange(offset + 40, 4).ToArray());
            options.Data          = b.GetRange(44 + offset, b.Count - offset - 44).ToArray();
            return(options);
        }
Exemplo n.º 4
0
 public WavHandler(WavOptions opts)
 {
     this.options = opts;
 }
Exemplo n.º 5
0
 public WavHandler()
 {
     this.options = new WavOptions();
 }