Exemple #1
0
        // Append new file data without header to existing oldfile
        public void Append(string oldFile, string newFile)
        {
            WaveIO wa_IN = new WaveIO();
            WaveIO wa_out = new WaveIO();

            wa_out.DataLength = 0;
            wa_out.length = 0;

            //Gather header data
            string[] files = new[] {oldFile, newFile};

            foreach (string path in files)
            {
                wa_IN.WaveHeaderIN(@path);
                wa_out.DataLength += wa_IN.DataLength;
                wa_out.length += wa_IN.length;

            }

            // change header of existing file
            wa_out.ChangeHeader(@oldFile);

            FileStream fs = new FileStream(@newFile, FileMode.Open, FileAccess.Read);
            byte[] arrfile = new byte[fs.Length - 44];
            fs.Position = 44;
            fs.Read(arrfile, 0, arrfile.Length);
            fs.Close();

            //Read existing file append new file data
            FileStream fo = new FileStream(@oldFile, FileMode.Append, FileAccess.Write);
            BinaryWriter bw = new BinaryWriter(fo);
            bw.Write(arrfile);
            bw.Close();
            fo.Close();
        }
Exemple #2
0
        public void Merge(string[] files, string outfile)
        {
            WaveIO wa_IN = new WaveIO();
            WaveIO wa_out = new WaveIO();

            wa_out.DataLength = 0;
            wa_out.length = 0;

            //Gather header data
            foreach (string path in files)
            {
                wa_IN.WaveHeaderIN(@path);
                wa_out.DataLength += wa_IN.DataLength;
                wa_out.length += wa_IN.length;

            }

            //Recontruct new header
            wa_out.BitsPerSample = wa_IN.BitsPerSample;
            wa_out.channels = wa_IN.channels;
            wa_out.samplerate = wa_IN.samplerate;
            wa_out.WaveHeaderOUT(@outfile);

            foreach (string path in files)
            {
                FileStream fs = new FileStream(@path, FileMode.Open, FileAccess.Read);
                byte[] arrfile = new byte[fs.Length - 44];
                fs.Position = 44;
                fs.Read(arrfile, 0, arrfile.Length);
                fs.Close();

                FileStream fo = new FileStream(@outfile, FileMode.Append, FileAccess.Write);
                BinaryWriter bw = new BinaryWriter(fo);
                bw.Write(arrfile);
                bw.Close();
                fo.Close();
            }
        }