Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] files = new string[2] { @textBox1.Text, @textBox2.Text };

            WaveIO wa = new WaveIO();
            wa.Merge(files, @textBox3.Text);

            FileStream fs = new FileStream(textBox3.Text, FileMode.Open, FileAccess.Read);
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer(fs);
            sp.Play();
        }
Ejemplo n.º 3
0
        public JsonResult Upload()
        {
            UploadManager uploadManager = new UploadManager();
            try
            {
                var folder = Server.MapPath("~/" + "Files");
                //string fileSuffix = uploadManager.GetTimestamp(DateTime.Now);
                var fileName = Request.Form["fileName"];
                var file = Request.Files["blob"];
                string filePath = Path.Combine(folder, fileName+".wav");

                string outFilePath = Path.Combine(folder, fileName +"o"+ ".wav");
                //File not exist, write it

                if (!System.IO.File.Exists(filePath))
                {
                    file.SaveAs(filePath);
                }
                else
                {
                    string tempFile = Path.Combine(folder, fileName+"-temp" + ".wav");
                    file.SaveAs(tempFile);
                    string[] filesToMerge = new string[2] {filePath,tempFile};
                    //string[] filesToMerge = new string[1] {tempFile };

                    using (WaveIO wa = new WaveIO())
                    {
                        wa.Merge(filesToMerge, outFilePath);

                        //Append new file with exising file
                        //wa.Append(filePath, tempFile);

                        System.IO.File.Delete(filePath);
                        System.IO.File.Delete(tempFile);
                        System.IO.File.Move(outFilePath, filePath);
                    }
                }

                //var blob = Request.Form["blob"];

                //Request.SaveAs(Server.MapPath("~/" + "Files/" + fileSuffix + ".wav"), false);
                //uploadManager.Upload(Request.Files, folder, fileSuffix);

                return this.Json(new { Success = true, Status = "Uploaded Successfully" });
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return Json(new { Success = true, Status = "Something went wrong, Please try again." });
            }
        }
Ejemplo n.º 4
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();
            }
        }